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

Merge branch 'issue25' into 'master'

Add function to cancel lessons. Closes #25.

Closes #25

See merge request Teckids/BiscuIT/BiscuIT-App-Chronos!13
parents da6fc856 c32a5791
No related branches found
No related tags found
1 merge request!13Add function to cancel lessons. Closes #25.
...@@ -24,4 +24,4 @@ class SelectForm(forms.Form): ...@@ -24,4 +24,4 @@ class SelectForm(forms.Form):
class LessonSubstitutionForm(forms.ModelForm): class LessonSubstitutionForm(forms.ModelForm):
class Meta: class Meta:
model = LessonSubstitution model = LessonSubstitution
fields = ['week', 'lesson_period', 'subject', 'teachers', 'room'] fields = ['week', 'lesson_period', 'subject', 'teachers', 'room', 'cancelled']
# Generated by Django 2.2.5 on 2019-09-07 14:19
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('chronos', '0002_db_indexes'),
]
operations = [
migrations.AddField(
model_name='lessonsubstitution',
name='cancelled',
field=models.BooleanField(default=False),
),
migrations.AddConstraint(
model_name='lessonsubstitution',
constraint=models.CheckConstraint(check=models.Q(('cancelled', True), ('subject__isnull', False), _negated=True), name='either_substituted_or_cancelled'),
),
]
...@@ -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
...@@ -119,10 +121,22 @@ class LessonSubstitution(SchoolRelated): ...@@ -119,10 +121,22 @@ class LessonSubstitution(SchoolRelated):
related_name='lesson_substitutions') related_name='lesson_substitutions')
room = models.ForeignKey('Room', models.CASCADE, null=True) room = models.ForeignKey('Room', models.CASCADE, null=True)
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=True, subject__isnull=False),
name='either_substituted_or_cancelled'
)
]
class LessonPeriod(SchoolRelated): class LessonPeriod(SchoolRelated):
......
...@@ -5,4 +5,9 @@ ...@@ -5,4 +5,9 @@
ul#timetable_select_form li { ul#timetable_select_form li {
dispaly: inline; dispaly: inline;
} }
\ No newline at end of file
.chronos-lesson-cancelled {
background-color: inherit !important;
text-decoration: line-through;
}
{# -*- engine:django -*- #} {# -*- engine:django -*- #}
<div class="card chronos-lesson <div class="card chronos-lesson
{% if lesson_period.get_substitution %} {% if lesson_period.get_substitution.cancelled %}
border border-warning border border-danger chronos-lesson-cancelled
{% elif lesson_period.get_substitution %}
border border-warning
{% endif %} {% endif %}
" "
style=" style="
......
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