Skip to content
Snippets Groups Projects
Commit 98dcfc5d authored by Konrad Mohrfeldt's avatar Konrad Mohrfeldt :koala:
Browse files

fix: raise ValidationError on invalid data

This gives the calling code better control over the handling of such
errors and makes it easy to differentiate between errors and valid
return types.
parent ab4c64d2
No related branches found
No related tags found
1 merge request!21Add API documentation
......@@ -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 = []
......
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