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

[Full register] Filter data by school term

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