diff --git a/RIGS/forms.py b/RIGS/forms.py index 8a840166..b4de22f4 100644 --- a/RIGS/forms.py +++ b/RIGS/forms.py @@ -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 @@ -97,6 +98,9 @@ class EventForm(forms.ModelForm): 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. "), code='access_sanity') return super().clean() def save(self, commit=True): diff --git a/RIGS/tests/test_interaction.py b/RIGS/tests/test_interaction.py index 6239b307..b035098e 100644 --- a/RIGS/tests/test_interaction.py +++ b/RIGS/tests/test_interaction.py @@ -127,7 +127,7 @@ class TestEventCreate(BaseRigboardTest): # 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"