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

Merge branch...

Merge branch '88-ensure-that-full_register-only-counts-personal-notes-in-the-selected-school-term' into 'master'

Resolve "[Full register] Filter personal notes by school term"

Closes #88

See merge request !71
parents b016ec19 b7605ee6
No related branches found
No related tags found
1 merge request!71Resolve "[Full register] Filter personal notes by school term"
Pipeline #3188 passed
......@@ -310,32 +310,34 @@
<tbody>
{% for note in person.personal_notes.all %}
{% if note.absent or note.late or note.remarks %}
{% period_to_date note.week note.lesson_period.period as note_date %}
<tr>
<td>{{ note_date }}</td>
<td>{{ note.lesson_period.period.period }}</td>
<td>{{ note.lesson_period.get_subject.short_name }} </td>
<td>{{ note.lesson_period.get_teachers.first.short_name }}</td>
<td>
{% if note.absent %}
{% trans 'Yes' %}
{% if note.excused %}
{% if note.excuse_type %}
({{ note.excuse_type.short_name }})
{% else %}
({% trans 'e' %})
{% if note.lesson_period in lesson_periods or note.lesson_period in lesson_periods %}
{% if note.absent or note.late or note.remarks %}
{% period_to_date note.week note.lesson_period.period as note_date %}
<tr>
<td>{{ note_date }}</td>
<td>{{ note.lesson_period.period.period }}</td>
<td>{{ note.lesson_period.get_subject.short_name }} </td>
<td>{{ note.lesson_period.get_teachers.first.short_name }}</td>
<td>
{% if note.absent %}
{% trans 'Yes' %}
{% if note.excused %}
{% if note.excuse_type %}
({{ note.excuse_type.short_name }})
{% else %}
({% trans 'e' %})
{% endif %}
{% endif %}
{% endif %}
{% endif %}
</td>
<td>
{% if note.late %}
{{ note.late }}'
{% endif %}
</td>
<td>{{ note.remarks }}</td>
</tr>
</td>
<td>
{% if note.late %}
{{ note.late }}'
{% endif %}
</td>
<td>{{ note.remarks }}</td>
</tr>
{% endif %}
{% endif %}
{% endfor %}
</tbody>
......
......@@ -16,6 +16,7 @@ from rules.contrib.views import PermissionRequiredMixin
from aleksis.apps.chronos.managers import TimetableType
from aleksis.apps.chronos.models import LessonPeriod
from aleksis.apps.chronos.util.chronos_helpers import get_el_by_pk
from aleksis.apps.chronos.util.date import week_weekday_to_date
from aleksis.core.mixins import AdvancedCreateView, AdvancedDeleteView, AdvancedEditView
from aleksis.core.models import Group, Person, SchoolTerm
from aleksis.core.util import messages
......@@ -46,6 +47,14 @@ def lesson(
lesson_period = LessonPeriod.objects.annotate_week(wanted_week).get(
pk=period_id
)
date_of_lesson = week_weekday_to_date(wanted_week, lesson_period.period.weekday)
if (
date_of_lesson < lesson_period.lesson.validity.date_start
or date_of_lesson > lesson_period.lesson.validity.date_end
):
return HttpResponseNotFound()
else:
# Determine current lesson by current date and time
lesson_period = (
......@@ -290,18 +299,19 @@ def full_register_group(request: HttpRequest, id_: int) -> HttpResponse:
group = get_object_or_404(Group, pk=id_)
current_school_term = SchoolTerm.current
if not current_school_term:
return HttpResponseNotFound(_("There is no current school term."))
# Get all lesson periods for the selected group
lesson_periods = (
LessonPeriod.objects.filter_group(group)
.filter(lesson__validity__school_term=current_school_term)
.distinct()
.prefetch_related("documentations", "personal_notes")
)
current_school_term = SchoolTerm.current
if not current_school_term:
return HttpResponseNotFound(_("There is no current school term."))
weeks = CalendarWeek.weeks_within(
current_school_term.date_start, current_school_term.date_end,
)
......@@ -336,7 +346,11 @@ 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,
personal_notes__lesson_period__lesson__validity__school_term=current_school_term,
),
),
excused=Count(
"personal_notes__absent",
......@@ -344,11 +358,16 @@ def full_register_group(request: HttpRequest, id_: int) -> HttpResponse:
personal_notes__absent=True,
personal_notes__excused=True,
personal_notes__excuse_type__isnull=True,
personal_notes__lesson_period__lesson__validity__school_term=current_school_term,
),
),
unexcused=Count(
"personal_notes__absent",
filter=Q(personal_notes__absent=True, personal_notes__excused=False),
filter=Q(
personal_notes__absent=True,
personal_notes__excused=False,
personal_notes__lesson_period__lesson__validity__school_term=current_school_term,
),
),
tardiness=Sum("personal_notes__late"),
)
......@@ -361,6 +380,7 @@ def full_register_group(request: HttpRequest, id_: int) -> HttpResponse:
filter=Q(
personal_notes__absent=True,
personal_notes__excuse_type=excuse_type,
personal_notes__lesson_period__lesson__validity__school_term=current_school_term,
),
)
}
......@@ -375,7 +395,8 @@ def full_register_group(request: HttpRequest, id_: int) -> HttpResponse:
% personal_note_filter.identifier: Count(
"personal_notes__remarks",
filter=Q(
personal_notes__remarks__iregex=personal_note_filter.regex
personal_notes__remarks__iregex=personal_note_filter.regex,
personal_notes__lesson_period__lesson__validity__school_term=current_school_term,
),
)
}
......@@ -388,6 +409,7 @@ def full_register_group(request: HttpRequest, id_: int) -> HttpResponse:
context["group"] = group
context["weeks"] = weeks
context["periods_by_day"] = periods_by_day
context["lesson_periods"] = lesson_periods
context["today"] = date.today()
return render(request, "alsijil/print/full_register.html", context)
......
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