Skip to content
Snippets Groups Projects

Add API documentation

Merged Konrad Mohrfeldt requested to merge feature/api-docs into master
1 file
+ 4
3
Compare changes
  • Side-by-side
  • Inline
+ 88
17
@@ -19,9 +19,11 @@
#
from datetime import datetime, time, timedelta
from textwrap import dedent
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
@@ -224,17 +226,76 @@ class RRule(models.Model):
class Schedule(models.Model):
rrule = models.ForeignKey(RRule, on_delete=models.CASCADE, related_name="schedules")
show = models.ForeignKey(Show, on_delete=models.CASCADE, related_name="schedules")
by_weekday = models.IntegerField()
first_date = models.DateField()
start_time = models.TimeField()
end_time = models.TimeField()
last_date = models.DateField()
is_repetition = models.BooleanField(default=False)
add_days_no = models.IntegerField(blank=True, null=True)
add_business_days_only = models.BooleanField(default=False)
default_playlist_id = models.IntegerField(blank=True, null=True)
rrule = models.ForeignKey(
RRule,
on_delete=models.CASCADE,
related_name="schedules",
help_text=dedent(
"""
A recurrence rule.
* 1 = once,
* 2 = daily,
* 3 = business days,
* 4 = weekly,
* 5 = biweekly,
* 6 = every four weeks,
* 7 = every even calendar week (ISO 8601),
* 8 = every odd calendar week (ISO 8601),
* 9 = every 1st week of month,
* 10 = every 2nd week of month,
* 11 = every 3rd week of month,
* 12 = every 4th week of month,
* 13 = every 5th week of month
"""
),
)
show = models.ForeignKey(
Show,
on_delete=models.CASCADE,
related_name="schedules",
help_text="Show the schedule belongs to.",
)
by_weekday = models.IntegerField(
help_text="Number of the Weekday.",
choices=[
(0, "Monday"),
(1, "Tuesday"),
(2, "Wednesday"),
(3, "Thursday"),
(4, "Friday"),
(5, "Saturday"),
(6, "Sunday"),
],
)
first_date = models.DateField(help_text="Start date of schedule.")
start_time = models.TimeField(help_text="Start time of schedule.")
end_time = models.TimeField(help_text="End time of schedule.")
last_date = models.DateField(help_text="End date of schedule.")
is_repetition = models.BooleanField(
default=False,
help_text="Whether the schedule is a repetition.",
)
add_days_no = models.IntegerField(
blank=True,
null=True,
help_text=(
"Add a number of days to the generated dates. "
"This can be useful for repetitions, like 'On the following day'."
),
)
add_business_days_only = models.BooleanField(
default=False,
help_text=(
"Whether to add add_days_no but skipping the weekends. "
"E.g. if weekday is Friday, the date returned will be the next Monday."
),
)
default_playlist_id = models.IntegerField(
blank=True,
null=True,
help_text="A tank ID in case the timeslot's playlist_id is empty.",
)
class Meta:
ordering = ("first_date", "start_time")
@@ -525,10 +586,10 @@ class Schedule(models.Model):
# Get note
try:
note = Note.objects.get(timeslot=c.id).values_list("id", flat=True)
collision["note_id"] = note
note = Note.objects.get(timeslot=c.id)
collision["note_id"] = note.pk
except ObjectDoesNotExist:
pass
collision["note_id"] = None
collisions.append(collision)
@@ -606,6 +667,7 @@ class Schedule(models.Model):
projected_entry["collisions"] = collisions
projected_entry["solution_choices"] = solution_choices
projected_entry["error"] = None
projected.append(projected_entry)
conflicts["projected"] = projected
@@ -673,17 +735,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 = []
Loading