Add warning when creating event with access time more than a week before start.

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

Closes #593
This commit is contained in:
2024-10-20 19:51:01 +01:00
parent 6d53df0c8b
commit be7b595edb
2 changed files with 6 additions and 2 deletions

View File

@@ -1,10 +1,11 @@
from datetime import datetime from datetime import datetime, timedelta
import simplejson import simplejson
from django import forms from django import forms
from django.conf import settings from django.conf import settings
from django.core import serializers from django.core import serializers
from django.utils import timezone from django.utils import timezone
from django.utils.html import format_html
from reversion import revisions as reversion from reversion import revisions as reversion
from RIGS import models from RIGS import models
@@ -97,6 +98,9 @@ class EventForm(forms.ModelForm):
raise forms.ValidationError( raise forms.ValidationError(
'You haven\'t provided any client contact details. Please add a person or organisation.', 'You haven\'t provided any client contact details. Please add a person or organisation.',
code='contact') 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() return super().clean()
def save(self, commit=True): def save(self, commit=True):

View File

@@ -127,7 +127,7 @@ class TestEventCreate(BaseRigboardTest):
# Fix it # Fix it
self.page.end_date = datetime.date(2020, 1, 11) 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.dry_hire = True
self.page.status = "Booked" self.page.status = "Booked"
self.page.collected_by = "Fred" self.page.collected_by = "Fred"