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 @@
</div>
</div>
<div class="row">
<div class="col s12">
<div class="card">
<div class="card-content">
<span class="card-title">
{% blocktrans %}Personal notes{% endblocktrans %}
</span>
{% form form=personal_note_formset.management_form %}{% endform %}
<table class="striped responsive-table alsijil-table">
<thead>
<tr>
<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 %}
{% if not lesson_period.get_substitution.cancelled %}
<div class="row">
<div class="col s12">
<div class="card">
<div class="card-content">
<span class="card-title">
{% blocktrans %}Personal notes{% endblocktrans %}
</span>
{% form form=personal_note_formset.management_form %}{% endform %}
<table class="striped responsive-table alsijil-table">
<thead>
<tr>
{{ form.id }}
<td>{{ form.person_name }}{{ form.person_name.value }}</td>
<td class="center-align">
<label>
{{ form.absent }}
<span></span>
</label>
</td>
<td>
<div class="input-field">
{{ form.late }}
<label for="{{ form.absent.id_for_label }}">
{% trans "Tardiness (in m)" %}
<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>
{{ form.id }}
<td>{{ form.person_name }}{{ form.person_name.value }}</td>
<td class="center-align">
<label>
{{ form.absent }}
<span></span>
</label>
</div>
</td>
<td class="center-align">
<label>
{{ form.excused }}
<span></span>
</label>
</td>
<td>
<div class="input-field">
{{ form.remarks }}
<label for="{{ form.absent.id_for_label }}">
{% trans "Remarks" %}
</td>
<td>
<div class="input-field">
{{ form.late }}
<label for="{{ form.absent.id_for_label }}">
{% trans "Tardiness (in m)" %}
</label>
</div>
</td>
<td class="center-align">
<label>
{{ form.excused }}
<span></span>
</label>
</div>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</td>
<td>
<div class="input-field">
{{ form.remarks }}
<label for="{{ form.absent.id_for_label }}">
{% trans "Remarks" %}
</label>
</div>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
{% endif %}
<div class="row">
<div class="col s12">
......
......@@ -12,7 +12,7 @@ from calendarweek import CalendarWeek
from django_tables2 import RequestConfig
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.core.models import Group, Person, SchoolTerm
from aleksis.core.util import messages
......@@ -98,17 +98,19 @@ def lesson(
if lesson_documentation_form.is_valid():
lesson_documentation_form.save()
if personal_note_formset.is_valid():
instances = personal_note_formset.save()
# Iterate over personal notes and carry changed absences to following lessons
for instance in instances:
instance.person.mark_absent(
wanted_week[lesson_period.period.weekday],
lesson_period.period.period + 1,
instance.absent,
instance.excused,
)
substitution = lesson_period.get_substitution()
if not getattr(substitution, "cancelled", False):
if personal_note_formset.is_valid():
instances = personal_note_formset.save()
# Iterate over personal notes and carry changed absences to following lessons
for instance in instances:
instance.person.mark_absent(
wanted_week[lesson_period.period.weekday],
lesson_period.period.period + 1,
instance.absent,
instance.excused,
)
context["lesson_documentation"] = lesson_documentation
context["lesson_documentation_form"] = lesson_documentation_form
......@@ -297,7 +299,13 @@ def full_register_group(request: HttpRequest, id_: int) -> HttpResponse:
persons = group.members.annotate(
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(
"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