Skip to content
Snippets Groups Projects
Commit d35051c0 authored by Benjamin Hättasch's avatar Benjamin Hättasch
Browse files

Restrict AKSlot duration to length of the event

This implements #212.
parent dcafb769
No related branches found
No related tags found
No related merge requests found
...@@ -600,6 +600,14 @@ class AKSlot(models.Model): ...@@ -600,6 +600,14 @@ class AKSlot(models.Model):
""" """
return self.start < other.end <= self.end or self.start <= other.start < self.end return self.start < other.end <= self.end or self.start <= other.start < self.end
def save(self, force_insert=False, force_update=False, using=None, update_fields=None):
# Make sure duration is not longer than the event
if update_fields is None or 'duration' in update_fields:
event_duration = self.event.end - self.event.start
event_duration_hours = event_duration.days * 24 + event_duration.seconds // 3600
self.duration = min(self.duration, event_duration_hours)
super().save(force_insert, force_update, using, update_fields)
class AKOrgaMessage(models.Model): class AKOrgaMessage(models.Model):
""" """
......
...@@ -86,7 +86,7 @@ class AKForm(AvailabilitiesFormMixin, forms.ModelForm): ...@@ -86,7 +86,7 @@ class AKForm(AvailabilitiesFormMixin, forms.ModelForm):
duration = float(duration.replace(",", ".")) duration = float(duration.replace(",", "."))
try: try:
float(duration) duration = float(duration)
except ValueError as exc: except ValueError as exc:
raise ValidationError( raise ValidationError(
_('"%(duration)s" is not a valid duration'), _('"%(duration)s" is not a valid duration'),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment