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

[Lesson view] Show summary of previous lesson (topic, homework, absences and tardinesses)

- Add extra templates for absences and tardinesses
- Add model extensions for lesson documentation and personal notes to LessonPeriod
parent cd55e32d
No related branches found
No related tags found
1 merge request!57Resolve "[Lesson view] Show summary (homework, etc.) of previous lessons"
Pipeline #2812 passed
...@@ -19,6 +19,11 @@ class LessonDocumentationForm(forms.ModelForm): ...@@ -19,6 +19,11 @@ class LessonDocumentationForm(forms.ModelForm):
model = LessonDocumentation model = LessonDocumentation
fields = ["topic", "homework"] fields = ["topic", "homework"]
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.fields["homework"].label = _("Homework for the next lesson")
class PersonalNoteForm(forms.ModelForm): class PersonalNoteForm(forms.ModelForm):
class Meta: class Meta:
......
from datetime import date from datetime import date
from typing import Optional, Union
from django.db.models import Exists, OuterRef from django.db.models import Exists, OuterRef, QuerySet
from calendarweek import CalendarWeek from calendarweek import CalendarWeek
from aleksis.apps.chronos.models import LessonPeriod from aleksis.apps.chronos.models import LessonPeriod
from aleksis.core.models import Group, Person from aleksis.core.models import Group, Person
from .models import PersonalNote from .models import LessonDocumentation, PersonalNote
@Person.method @Person.method
...@@ -91,3 +92,61 @@ def get_personal_notes(self, wanted_week: CalendarWeek): ...@@ -91,3 +92,61 @@ def get_personal_notes(self, wanted_week: CalendarWeek):
return PersonalNote.objects.select_related("person").filter( return PersonalNote.objects.select_related("person").filter(
lesson_period=self, week=wanted_week.week lesson_period=self, week=wanted_week.week
) )
@LessonPeriod.method
def get_lesson_documentation(
self, week: Optional[CalendarWeek] = None
) -> Union[LessonDocumentation, None]:
"""Get lesson documentation object for this lesson."""
if not week:
week = self.week
try:
return LessonDocumentation.objects.get(lesson_period=self, week=week.week)
except LessonDocumentation.DoesNotExist:
return None
@LessonPeriod.method
def get_or_create_lesson_documentation(
self, week: Optional[CalendarWeek] = None
) -> LessonDocumentation:
"""Get or create lesson documentation object for this lesson."""
if not week:
week = self.week
lesson_documentation, created = LessonDocumentation.objects.get_or_create(
lesson_period=self, week=week.week
)
return lesson_documentation
@LessonPeriod.method
def get_absences(self, week: Optional[CalendarWeek] = None) -> QuerySet:
"""Get all personal notes of absent persons for this lesson."""
if not week:
week = self.week
return self.personal_notes.filter(week=week.week, absent=True)
@LessonPeriod.method
def get_excused_absences(self, week: Optional[CalendarWeek] = None) -> QuerySet:
"""Get all personal notes of excused absent persons for this lesson."""
if not week:
week = self.week
return self.personal_notes.filter(week=week.week, absent=True, excused=True)
@LessonPeriod.method
def get_unexcused_absences(self, week: Optional[CalendarWeek] = None) -> QuerySet:
"""Get all personal notes of unexcused absent persons for this lesson."""
if not week:
week = self.week
return self.personal_notes.filter(week=week.week, absent=True, excused=False)
@LessonPeriod.method
def get_tardinesses(self, week: Optional[CalendarWeek] = None) -> QuerySet:
"""Get all personal notes of late persons for this lesson."""
if not week:
week = self.week
return self.personal_notes.filter(week=week.week, late__gt=0)
{# -*- engine:django -*- #} {# -*- engine:django -*- #}
{% extends "core/base.html" %} {% extends "core/base.html" %}
{% load week_helpers %}
{% load material_form i18n static %} {% load material_form i18n static %}
{% block browser_title %}{% blocktrans %}Lesson{% endblocktrans %}{% endblock %} {% block browser_title %}{% blocktrans %}Lesson{% endblocktrans %}{% endblock %}
...@@ -58,6 +59,53 @@ ...@@ -58,6 +59,53 @@
<div class="row"> <div class="row">
<div class="col s12 m12 l6 xl8"> <div class="col s12 m12 l6 xl8">
{% with prev_lesson=lesson_period.prev prev_doc=prev_lesson.get_lesson_documentation %}
{% with prev_doc=prev_lesson.get_lesson_documentation absences=prev_lesson.get_absences tardinesses=prev_lesson.get_tardinesses %}
{% if prev_doc %}
{% weekday_to_date prev_lesson.week prev_lesson.period.weekday as prev_date %}
<div class="card">
<div class="card-content">
<span class="card-title">
{% blocktrans %}Overview: Previous lesson{% endblocktrans %} ({{ prev_date }},
{% blocktrans with period=prev_lesson.period.period %}{{ period }}. period{% endblocktrans %})
</span>
<table>
{% if prev_doc.topic %}
<tr>
<th class="collection-item">{% trans "Lesson topic of previous lesson:" %}</th>
<td>{{ prev_doc.topic }}</td>
</tr>
{% endif %}
{% if prev_doc.homework %}
<tr>
<th class="collection-item">{% trans "Homework for this lesson:" %}</th>
<td>{{ prev_doc.homework }}</td>
</tr>
{% endif %}
{% if absences %}
<tr>
<th>{% trans "Absent persons:" %}</th>
<td>{% include "alsijil/partials/absences.html" with notes=absences %}</td>
</tr>
{% endif %}
{% if tardinesses %}
<tr>
<th>{% trans "Late persons:" %}</th>
<td>{% include "alsijil/partials/tardinesses.html" with notes=tardinesses %}</td>
</tr>
{% endif %}
</table>
</div>
</div>
{% endif %}
{% endwith %}
{% endwith %}
<div class="card"> <div class="card">
<div class="card-content"> <div class="card-content">
<span class="card-title"> <span class="card-title">
......
{% load i18n %}
{% for note in notes %}
<span class="{% if note.excused %}green-text{% else %}red-text{% endif %}">{{ note.person }}
{% if note.excused %}{% trans "(e)" %}{% else %}{% trans "(u)" %}{% endif %}{% if not forloop.last %},{% endif %}
</span>
{% endfor %}
{% for note in notes %}
<span>{{ note.person }} ({{ note.late }}'){% if not forloop.last %},{% endif %}</span>
{% endfor %}
...@@ -81,9 +81,7 @@ def lesson( ...@@ -81,9 +81,7 @@ def lesson(
context["day"] = wanted_week[lesson_period.period.weekday - 1] context["day"] = wanted_week[lesson_period.period.weekday - 1]
# Create or get lesson documentation object; can be empty when first opening lesson # Create or get lesson documentation object; can be empty when first opening lesson
lesson_documentation, created = LessonDocumentation.objects.get_or_create( lesson_documentation = lesson_period.get_or_create_lesson_documentation(wanted_week)
lesson_period=lesson_period, week=wanted_week.week
)
lesson_documentation_form = LessonDocumentationForm( lesson_documentation_form = LessonDocumentationForm(
request.POST or None, request.POST or None,
instance=lesson_documentation, instance=lesson_documentation,
......
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