mirror of
https://gitlab.crans.org/bde/nk20
synced 2025-06-21 09:58:23 +02:00
Ensure that date_end ≥ date_start in activities
This commit is contained in:
@ -15,6 +15,19 @@ from .models import Activity, Guest
|
||||
|
||||
|
||||
class ActivityForm(forms.ModelForm):
|
||||
def clean_date_start(self):
|
||||
date_start = self.cleaned_data["date_start"]
|
||||
if not self.instance.pk and date_start < timezone.now():
|
||||
self.add_error("date_start", _("You can't create a past activity."))
|
||||
return date_start
|
||||
|
||||
def clean_date_end(self):
|
||||
date_end = self.cleaned_data["date_end"]
|
||||
date_start = self.cleaned_data["date_start"]
|
||||
if date_end < date_start:
|
||||
self.add_error("date_end", _("The end date must be after the start date."))
|
||||
return date_end
|
||||
|
||||
class Meta:
|
||||
model = Activity
|
||||
exclude = ('creater', 'valid', 'open', )
|
||||
|
@ -123,6 +123,9 @@ class Activity(models.Model):
|
||||
"""
|
||||
Update the activity wiki page each time the activity is updated (validation, change description, ...)
|
||||
"""
|
||||
if self.date_end < self.date_start:
|
||||
raise ValidationError(_("The end date must be after the start date."))
|
||||
|
||||
ret = super().save(*args, **kwargs)
|
||||
if settings.DEBUG and self.pk and "scripts" in settings.INSTALLED_APPS:
|
||||
def refresh_activities():
|
||||
|
Reference in New Issue
Block a user