Skip to content

Commit

Permalink
Add warning when creating event with access time more than a week bef…
Browse files Browse the repository at this point in the history
…ore start.

Yes. I know it's a dirty solution. >:D

Closes #593
  • Loading branch information
FreneticScribbler committed Oct 20, 2024
1 parent 6d53df0 commit be7b595
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 5 additions & 1 deletion RIGS/forms.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from datetime import datetime
from datetime import datetime, timedelta

import simplejson
from django import forms
from django.conf import settings
from django.core import serializers
from django.utils import timezone
from django.utils.html import format_html
from reversion import revisions as reversion

from RIGS import models
Expand Down Expand Up @@ -97,6 +98,9 @@ def clean(self):
raise forms.ValidationError(
'You haven\'t provided any client contact details. Please add a person or organisation.',
code='contact')
access = self.cleaned_data.get("access_at")
if 'warn-access' not in self.data and access is not None and access.date() < (self.cleaned_data.get("start_date") - timedelta(days=7)):
raise forms.ValidationError(format_html("Are you sure about that? Your access time seems a bit optimistic. If you're sure, save again. <input type='hidden' id='warn-access' name='warn-access' value='0'/>"), code='access_sanity')
return super().clean()

def save(self, commit=True):
Expand Down
2 changes: 1 addition & 1 deletion RIGS/tests/test_interaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def test_rig_creation(self):

# Fix it
self.page.end_date = datetime.date(2020, 1, 11)
self.page.access_at = datetime.datetime(2020, 1, 1, 9)
self.page.access_at = datetime.datetime(2020, 1, 8, 9)
self.page.dry_hire = True
self.page.status = "Booked"
self.page.collected_by = "Fred"
Expand Down

0 comments on commit be7b595

Please sign in to comment.