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

Show supervisions in timetable view

parent b9adbe8e
No related branches found
No related tags found
1 merge request!47Advanced data in timetable views
......@@ -727,11 +727,43 @@ class Break(ExtensibleModel):
verbose_name_plural = _("Breaks")
class SupervisionQuerySet(models.QuerySet):
def annotate_week(self, week: Union[CalendarWeek, int]):
""" Annotate all lessons in the QuerySet with the number of the provided calendar week. """
if isinstance(week, CalendarWeek):
week_num = week.week
else:
week_num = week
return self.annotate(_week=models.Value(week_num, models.IntegerField()))
class Supervision(ExtensibleModel):
objects = models.Manager.from_queryset(SupervisionQuerySet)()
area = models.ForeignKey(SupervisionArea, models.CASCADE, verbose_name=_("Supervision area"), related_name="supervisions")
break_item = models.ForeignKey(Break, models.CASCADE, verbose_name=_("Break"), related_name="supervisions")
teacher = models.ForeignKey("core.Person", models.CASCADE, related_name="supervisions", verbose_name=_("Teacher"))
def get_substitution(
self, week: Optional[int] = None
) -> Optional[SupervisionSubstitution]:
wanted_week = week or getattr(self, "_week", None) or CalendarWeek().week
wanted_week = CalendarWeek(week=wanted_week)
# We iterate over all substitutions because this can make use of
# prefetching when this model is loaded from outside, in contrast
# to .filter()
for substitution in self.substitutions.all():
for weekday in range(0, 7):
if substitution.date == wanted_week[weekday]:
return substitution
return None
@property
def teachers(self):
return [self.teacher]
class Meta:
ordering = ["area", "break_item"]
verbose_name= _("Supervision")
......@@ -743,6 +775,10 @@ class SupervisionSubstitution(ExtensibleModel):
supervision = models.ForeignKey(Supervision, models.CASCADE, verbose_name=_("Supervision"), related_name="substitutions")
teacher = models.ForeignKey("core.Person", models.CASCADE, related_name="substituted_supervisions", verbose_name=_("Teacher"))
@property
def teachers(self):
return [self.teacher]
class Meta:
ordering = ["date", "supervision"]
verbose_name = _("Supervision substitution")
......
......@@ -26,6 +26,10 @@ li.active > a > .sidenav-badge {
min-height: 65px;
}
.supervision-card {
min-height: 35px;
}
.lesson-card .card-content {
padding: 0;
text-align: center;
......
{% load i18n %}
<div class="card lesson-card supervision-card">
<div class="card-content">
{% if supervision %}
<div style="
{% if supervision.area.colour_fg %}
color: {{ supervision.area.colour_fg }};
{% endif %}
{% if supervision.area.colour_bg %}
background-color: {{ supervision.area.colour_bg }};
{% endif %}
" class="{% if supervision.get_substitution and smart %}lesson-with-sub{% endif %}">
<p>
<strong>{% trans "Supervision" %}</strong>
<span data-position="bottom" class="tooltipped"
data-tooltip="{{ supervision.area.name }}" title="{{ supervision.area.name }}">
{{ supervision.area.short_name }}
</span>
{% if supervision.get_substitution and smart %}
<s>
{% include "chronos/partials/teachers.html" with teachers=supervision.teachers %}
</s>
<strong>
{% include "chronos/partials/teachers.html" with teachers=supervision.get_substitution.teachers %}
</strong>
{% elif type == "supervision_area" %}
{% include "chronos/partials/teachers.html" with teachers=supervision.teachers %}
{% endif %}
</p>
</div>
{% endif %}
</div>
</div>
......@@ -120,15 +120,17 @@
<div class="col s2">
{% if row.type == "period" %}
{% include "chronos/partials/period_time.html" with period=row.period periods=periods %}
{% else %}
{% trans "Break" %}
{% endif %}
</div>
{% for col in row.cols %}
{# A lesson #}
<div class="col s2">
{% include "chronos/partials/elements.html" with elements=col %}
{% if row.type == "period" %}
{% include "chronos/partials/elements.html" with elements=col %}
{% else %}
{% include "chronos/partials/supervision.html" with supervision=col %}
{% endif %}
</div>
{% endfor %}
</div>
......@@ -160,7 +162,11 @@
{% if forloop.counter0 == i %}
<div class="col s8">
{# A lesson #}
{% include "chronos/partials/elements.html" with elements=col %}
{% if row.type == "period" %}
{% include "chronos/partials/elements.html" with elements=col %}
{% else %}
{% include "chronos/partials/supervision.html" with supervision=col %}
{% endif %}
</div>
{% endif %}
{% endfor %}
......
......@@ -2,7 +2,7 @@ from collections import OrderedDict
from calendarweek import CalendarWeek
from aleksis.apps.chronos.models import LessonPeriod, TimePeriod, Break
from aleksis.apps.chronos.models import LessonPeriod, TimePeriod, Break, Supervision
def build_timetable(type_: str, pk: int, week: CalendarWeek):
......@@ -25,13 +25,31 @@ def build_timetable(type_: str, pk: int, week: CalendarWeek):
lesson_periods_per_period[period][weekday].append(lesson_period)
if type_ == "teacher":
# Get matching supervisions
supervisions = Supervision.objects.filter(teacher=pk).annotate_week(week)
supervisions_per_period_after = {}
for supervision in supervisions:
weekday = supervision.break_item.weekday
period_after_break = supervision.break_item.before_period_number
print(supervision, weekday, period_after_break)
if period_after_break not in needed_breaks:
needed_breaks.append(period_after_break)
if period_after_break not in supervisions_per_period_after:
supervisions_per_period_after[period_after_break] = {}
supervisions_per_period_after[period_after_break][weekday] = supervision
# Get ordered breaks
breaks = OrderedDict(sorted(Break.get_breaks_dict().items()))
rows = []
for period, break_ in breaks.items(): # period is period after break
# Break
if period in needed_breaks:
if type_ == "teacher" and period in needed_breaks:
row = {
"type": "break",
"after_period": break_.after_period_number,
......@@ -42,7 +60,12 @@ def build_timetable(type_: str, pk: int, week: CalendarWeek):
cols = []
# ...
for weekday in range(TimePeriod.weekday_min, TimePeriod.weekday_max + 1):
col = None
if period in supervisions_per_period_after:
if weekday in supervisions_per_period_after[period]:
col = supervisions_per_period_after[period][weekday]
cols.append(col)
row["cols"] = cols
rows.append(row)
......
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