Skip to content
Snippets Groups Projects
Verified Commit 81c3a538 authored by Jonathan Weth's avatar Jonathan Weth :keyboard:
Browse files

Allow setting personal notes only if lesson isn't cancelled

parent 3cb069cd
No related branches found
No related tags found
1 merge request!61Resolve "Do not allow to add personal notes for cancelled lessons"
...@@ -128,66 +128,68 @@ ...@@ -128,66 +128,68 @@
</div> </div>
</div> </div>
<div class="row"> {% if not lesson_period.get_substitution.cancelled %}
<div class="col s12"> <div class="row">
<div class="card"> <div class="col s12">
<div class="card-content"> <div class="card">
<span class="card-title"> <div class="card-content">
{% blocktrans %}Personal notes{% endblocktrans %} <span class="card-title">
</span> {% blocktrans %}Personal notes{% endblocktrans %}
{% form form=personal_note_formset.management_form %}{% endform %} </span>
{% form form=personal_note_formset.management_form %}{% endform %}
<table class="striped responsive-table alsijil-table">
<thead> <table class="striped responsive-table alsijil-table">
<tr> <thead>
<th>{% blocktrans %}Person{% endblocktrans %}</th>
<th>{% blocktrans %}Absent{% endblocktrans %}</th>
<th>{% blocktrans %}Tardiness{% endblocktrans %}</th>
<th>{% blocktrans %}Excused{% endblocktrans %}</th>
<th>{% blocktrans %}Remarks{% endblocktrans %}</th>
</tr>
</thead>
<tbody>
{% for form in personal_note_formset %}
<tr> <tr>
{{ form.id }} <th>{% blocktrans %}Person{% endblocktrans %}</th>
<td>{{ form.person_name }}{{ form.person_name.value }}</td> <th>{% blocktrans %}Absent{% endblocktrans %}</th>
<td class="center-align"> <th>{% blocktrans %}Tardiness{% endblocktrans %}</th>
<label> <th>{% blocktrans %}Excused{% endblocktrans %}</th>
{{ form.absent }} <th>{% blocktrans %}Remarks{% endblocktrans %}</th>
<span></span> </tr>
</label> </thead>
</td> <tbody>
<td> {% for form in personal_note_formset %}
<div class="input-field"> <tr>
{{ form.late }} {{ form.id }}
<label for="{{ form.absent.id_for_label }}"> <td>{{ form.person_name }}{{ form.person_name.value }}</td>
{% trans "Tardiness (in m)" %} <td class="center-align">
<label>
{{ form.absent }}
<span></span>
</label> </label>
</div> </td>
</td> <td>
<td class="center-align"> <div class="input-field">
<label> {{ form.late }}
{{ form.excused }} <label for="{{ form.absent.id_for_label }}">
<span></span> {% trans "Tardiness (in m)" %}
</label> </label>
</td> </div>
<td> </td>
<div class="input-field"> <td class="center-align">
{{ form.remarks }} <label>
<label for="{{ form.absent.id_for_label }}"> {{ form.excused }}
{% trans "Remarks" %} <span></span>
</label> </label>
</div> </td>
</td> <td>
</tr> <div class="input-field">
{% endfor %} {{ form.remarks }}
</tbody> <label for="{{ form.absent.id_for_label }}">
</table> {% trans "Remarks" %}
</label>
</div>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div> </div>
</div> </div>
</div> </div>
</div> {% endif %}
<div class="row"> <div class="row">
<div class="col s12"> <div class="col s12">
......
...@@ -12,7 +12,7 @@ from calendarweek import CalendarWeek ...@@ -12,7 +12,7 @@ from calendarweek import CalendarWeek
from django_tables2 import RequestConfig from django_tables2 import RequestConfig
from aleksis.apps.chronos.managers import TimetableType from aleksis.apps.chronos.managers import TimetableType
from aleksis.apps.chronos.models import LessonPeriod from aleksis.apps.chronos.models import LessonPeriod, LessonSubstitution
from aleksis.apps.chronos.util.chronos_helpers import get_el_by_pk from aleksis.apps.chronos.util.chronos_helpers import get_el_by_pk
from aleksis.core.models import Group, Person, SchoolTerm from aleksis.core.models import Group, Person, SchoolTerm
from aleksis.core.util import messages from aleksis.core.util import messages
...@@ -98,17 +98,19 @@ def lesson( ...@@ -98,17 +98,19 @@ def lesson(
if lesson_documentation_form.is_valid(): if lesson_documentation_form.is_valid():
lesson_documentation_form.save() lesson_documentation_form.save()
if personal_note_formset.is_valid(): substitution = lesson_period.get_substitution()
instances = personal_note_formset.save() if not getattr(substitution, "cancelled", False):
if personal_note_formset.is_valid():
# Iterate over personal notes and carry changed absences to following lessons instances = personal_note_formset.save()
for instance in instances:
instance.person.mark_absent( # Iterate over personal notes and carry changed absences to following lessons
wanted_week[lesson_period.period.weekday], for instance in instances:
lesson_period.period.period + 1, instance.person.mark_absent(
instance.absent, wanted_week[lesson_period.period.weekday],
instance.excused, lesson_period.period.period + 1,
) instance.absent,
instance.excused,
)
context["lesson_documentation"] = lesson_documentation context["lesson_documentation"] = lesson_documentation
context["lesson_documentation_form"] = lesson_documentation_form context["lesson_documentation_form"] = lesson_documentation_form
...@@ -297,7 +299,13 @@ def full_register_group(request: HttpRequest, id_: int) -> HttpResponse: ...@@ -297,7 +299,13 @@ def full_register_group(request: HttpRequest, id_: int) -> HttpResponse:
persons = group.members.annotate( persons = group.members.annotate(
absences_count=Count( absences_count=Count(
"personal_notes__absent", filter=Q(personal_notes__absent=True) "personal_notes__absent", filter=Q(personal_notes__absent=True) & ~Q(personal_notes__lesson_period__substitutions=Subquery(
LessonSubstitution.objects.filter(
lesson_period__pk=OuterRef("personal_notes__lesson_period__pk"),
cancelled=True,
week=OuterRef("personal_notes__week"),
).values("pk")
))
), ),
unexcused=Count( unexcused=Count(
"personal_notes__absent", "personal_notes__absent",
......
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