diff --git a/program/models.py b/program/models.py index 6a4762df388c594a6d4534e0e6e966b12234588f..2d8fc1f9eac9a4a071003a3835cca3873623952a 100644 --- a/program/models.py +++ b/program/models.py @@ -22,6 +22,7 @@ from datetime import datetime, time, timedelta from dateutil.relativedelta import relativedelta from dateutil.rrule import rrule +from rest_framework.exceptions import ValidationError from versatileimagefield.fields import PPOIField, VersatileImageField from django.contrib.auth.models import User @@ -673,17 +674,26 @@ class Schedule(models.Model): conflicts = Schedule.make_conflicts(sdl, schedule_pk, show_pk) if schedule.rrule.freq > 0 and schedule.first_date == schedule.last_date: - return {"detail": _("Start and until dates mustn't be the same")} + raise ValidationError( + _("Start and until dates mustn't be the same"), + code="no-same-day-start-and-end", + ) if schedule.last_date < schedule.first_date: - return {"detail": _("Until date mustn't be before start")} + raise ValidationError( + _("Until date mustn't be before start"), + code="no-start-after-end", + ) num_conflicts = len( [pr for pr in conflicts["projected"] if len(pr["collisions"]) > 0] ) if len(solutions) != num_conflicts: - return {"detail": _("Numbers of conflicts and solutions don't match.")} + raise ValidationError( + _("Numbers of conflicts and solutions don't match."), + code="one-solution-per-conflict", + ) # Projected timeslots to create create = []