diff --git a/biscuit/apps/alsijil/models.py b/biscuit/apps/alsijil/models.py index 04732c311867c41eca0daedcd52ad37edba541b7..79f6f5df13f4cd055301dce98be2c5a01cdf653d 100644 --- a/biscuit/apps/alsijil/models.py +++ b/biscuit/apps/alsijil/models.py @@ -8,7 +8,7 @@ class PersonalNote(SchoolRelated): person = models.ForeignKey('core.Person', models.CASCADE, related_name='personal_notes') week = models.IntegerField() - lesson_period = models.ForeignKey('chronos.LessonPeriod', models.CASCADE) + lesson_period = models.ForeignKey('chronos.LessonPeriod', models.CASCADE, related_name='personal_notes') absent = models.BooleanField(default=False) late = models.IntegerField(default=0) diff --git a/biscuit/apps/alsijil/static/css/alsijil/full_register.css b/biscuit/apps/alsijil/static/css/alsijil/full_register.css index fc5ed9915371976113f6fab1658cf6f1905b874e..0d771fd94dc3265b764c838e38ef3c5b5bea0256 100644 --- a/biscuit/apps/alsijil/static/css/alsijil/full_register.css +++ b/biscuit/apps/alsijil/static/css/alsijil/full_register.css @@ -135,3 +135,19 @@ tr.lesson-cancelled td { tr.lesson-substituted td.lesson-subj { text-decoration: line-through; } + +td.lesson-notes { + font-size: 80%; +} + +td.lesson-notes span.lesson-note-absent { + color: #cc0000; +} + +td.lesson-notes span.lesson-note-late { + color: #ff9933; +} + +td.lesson-notes span.lesson-note-excused { + color: #009933; +} diff --git a/biscuit/apps/alsijil/templates/alsijil/print/full_register.html b/biscuit/apps/alsijil/templates/alsijil/print/full_register.html index 8ad0fa08209e1fb68d8a72f11f5ffdfcaeb0b3d1..a95cc646ae465039ee396ac9857fbc3e9a95d97c 100644 --- a/biscuit/apps/alsijil/templates/alsijil/print/full_register.html +++ b/biscuit/apps/alsijil/templates/alsijil/print/full_register.html @@ -130,11 +130,12 @@ <th>{% trans 'Subs.' %}</th> <th>{% trans 'Lesson topic' %}</th> <th>{% trans 'Homework' %}</th> + <th>{% trans 'Notes' %}</th> <th>{% trans 'Te.' %}</th> </tr> </thead> <tbody> - {% for period, documentations, substitution in periods_by_day|get_dict:day %} + {% for period, documentations, notes, substitution in periods_by_day|get_dict:day %} <tr class=" {% if substitution %} {% if substitution.cancelled %} @@ -155,6 +156,29 @@ {% endif %} </td> <td class="lesson-homework">{{ documentations.0.homework }}</td> + <td class="lesson-notes"> + {% for note in notes %} + {% if note.absent %} + <span class="lesson-note-absent"> + {{ note.person.last_name }}, {{ note.person.first_name|slice:"0:1" }}. + {% if note.excused %} + <span class="lesson-note-excused"> + ({% trans 'e' %}) + </span> + {% endif %} + {% endif %} + {% if note.late %} + <span class="lesson-note-late"> + {{ note.person.last_name }}, {{ note.person.first_name|slice:"0:1" }}. + ({{ note.late }}′) + {% if note.excused %} + <span class="lesson-note-excused"> + ({% trans 'e' %}) + </span> + {% endif %} + {% endif %} + {% endfor %} + </td> <td class="lesson-te"> {% if documentations.0.topic %} {{ substitution.teachers.first.short_name|default:period.lesson.teachers.first.short_name }} diff --git a/biscuit/apps/alsijil/views.py b/biscuit/apps/alsijil/views.py index 2c980af962d98936fd6ca26bf42f81a3512f0cc5..619f6b4bfe4e52e03fccc20ddef0d8c1161c90c2 100644 --- a/biscuit/apps/alsijil/views.py +++ b/biscuit/apps/alsijil/views.py @@ -198,28 +198,6 @@ def full_register_group(request: HttpRequest, id_: int) -> HttpResponse: Q(lesson__groups=group) | Q(lesson__groups__parent_groups=group) ).distinct() - # Aggregate all personal notes for this group and week - persons = Person.objects.filter( - is_active=True - ).filter( - Q(member_of=group) | Q(member_of__parent_groups=group) - ).distinct().prefetch_related( - 'personal_notes' - ).annotate( - absences=Count('personal_notes__absent', filter=Q( - personal_notes__lesson_period__in=lesson_periods, - personal_notes__absent=True - )), - unexcused=Count('personal_notes__absent', filter=Q( - personal_notes__lesson_period__in=lesson_periods, - personal_notes__absent=True, - personal_notes__excused=False - )), - tardiness=Sum('personal_notes__late', filter=Q( - personal_notes__lesson_period__in=lesson_periods, - )) - ) - weeks = CalendarWeek.weeks_within(group.school.current_term.date_start, group.school.current_term.date_end) periods_by_day = {} for lesson_period in lesson_periods: @@ -228,15 +206,14 @@ def full_register_group(request: HttpRequest, id_: int) -> HttpResponse: if lesson_period.lesson.date_start <= day and lesson_period.lesson.date_end >= day: documentations = list(filter(lambda d: d.week == week.week, lesson_period.documentations.all())) + notes = list(filter(lambda d: d.week == week.week, lesson_period.personal_notes.all())) substitution = lesson_period.get_substitution(week.week) - periods_by_day.setdefault(day, []).append((lesson_period, documentations, substitution)) + periods_by_day.setdefault(day, []).append((lesson_period, documentations, notes, substitution)) context['group'] = group context['weeks'] = weeks - context['lesson_periods'] = lesson_periods context['periods_by_day'] = periods_by_day - context['persons'] = persons context['today'] = date.today() return render(request, 'alsijil/print/full_register.html', context)