Skip to content
Snippets Groups Projects
Verified Commit b0bc6e8b authored by Nik | Klampfradler's avatar Nik | Klampfradler
Browse files

Enforce that lessons are either cancelled or substituted.

parent 9fd0444c
No related branches found
No related tags found
1 merge request!13Add function to cancel lessons. Closes #25.
...@@ -2,7 +2,9 @@ from datetime import datetime ...@@ -2,7 +2,9 @@ from datetime import datetime
from typing import Dict, Optional, Tuple from typing import Dict, Optional, Tuple
from django.core import validators from django.core import validators
from django.core.exceptions import ValidationError
from django.db import models from django.db import models
from django.db.models import Q
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from biscuit.core.mixins import SchoolRelated from biscuit.core.mixins import SchoolRelated
...@@ -121,10 +123,20 @@ class LessonSubstitution(SchoolRelated): ...@@ -121,10 +123,20 @@ class LessonSubstitution(SchoolRelated):
cancelled = models.BooleanField(default=False) cancelled = models.BooleanField(default=False)
def clean(self) -> None:
if self.subject and self.cancelled:
raise ValidationError(_('Lessons can only be either substituted or cancelled.'))
class Meta: class Meta:
unique_together = [['school', 'lesson_period', 'week']] unique_together = [['school', 'lesson_period', 'week']]
ordering = ['lesson_period__lesson__date_start', 'week', ordering = ['lesson_period__lesson__date_start', 'week',
'lesson_period__period__weekday', 'lesson_period__period__period'] 'lesson_period__period__weekday', 'lesson_period__period__period']
constraints = [
models.CheckConstraint(
check=Q(cancelled=False, subject__isnull=False) | Q(cancelled=True, subject__isnull=True, room__isnull=True),
name='either_substituted_or_cancelled'
)
]
class LessonPeriod(SchoolRelated): class LessonPeriod(SchoolRelated):
......
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