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

Merge branch '76-some-data-missing-in-substitutions-table-view' into 'master'

Resolve "Some data missing in substitutions table view"

Closes #76

See merge request !52
parents 1c4f0f28 04baf821
No related branches found
No related tags found
1 merge request!52Resolve "Some data missing in substitutions table view"
Showing
with 115 additions and 37 deletions
......@@ -428,19 +428,7 @@ class Room(ExtensibleModel):
ordering = ["name", "short_name"]
class Lesson(ExtensibleModel):
subject = models.ForeignKey("Subject", on_delete=models.CASCADE, related_name="lessons")
teachers = models.ManyToManyField("core.Person", related_name="lessons_as_teacher")
periods = models.ManyToManyField("TimePeriod", related_name="lessons", through="LessonPeriod")
groups = models.ManyToManyField("core.Group", related_name="lessons")
date_start = models.DateField(verbose_name=_("Effective start date of lesson"), null=True)
date_end = models.DateField(verbose_name=_("Effective end date of lesson"), null=True)
@property
def teacher_names(self, sep: Optional[str] = ", ") -> str:
return sep.join([teacher.full_name for teacher in self.teachers.all()])
class GroupPropertiesMixin:
@property
def group_names(self, sep: Optional[str] = ", ") -> str:
return sep.join([group.short_name for group in self.groups.all()])
......@@ -457,6 +445,22 @@ class Lesson(ExtensibleModel):
def groups_to_show_names(self, sep: Optional[str] = ", ") -> str:
return sep.join([group.short_name for group in self.groups_to_show])
class TeacherPropertiesMixin:
@property
def teacher_names(self, sep: Optional[str] = ", ") -> str:
return sep.join([teacher.full_name for teacher in self.teachers.all()])
class Lesson(ExtensibleModel, GroupPropertiesMixin, TeacherPropertiesMixin):
subject = models.ForeignKey("Subject", on_delete=models.CASCADE, related_name="lessons")
teachers = models.ManyToManyField("core.Person", related_name="lessons_as_teacher")
periods = models.ManyToManyField("TimePeriod", related_name="lessons", through="LessonPeriod")
groups = models.ManyToManyField("core.Group", related_name="lessons")
date_start = models.DateField(verbose_name=_("Effective start date of lesson"), null=True)
date_end = models.DateField(verbose_name=_("Effective end date of lesson"), null=True)
def get_calendar_week(self, week: int):
year = self.date_start.year
if week < int(self.date_start.strftime("%V")):
......@@ -1016,10 +1020,13 @@ class TimetableQuerySet(models.QuerySet):
class EventQuerySet(DateRangeQuerySet, TimetableQuerySet):
pass
def annotate_day(self, day: date):
""" Annotate all events in the QuerySet with the provided date. """
return self.annotate(_date=models.Value(day, models.DateField()))
class Event(ExtensibleModel):
class Event(ExtensibleModel, GroupPropertiesMixin, TeacherPropertiesMixin):
label_ = "event"
objects = models.Manager.from_queryset(EventQuerySet)()
......@@ -1042,6 +1049,22 @@ class Event(ExtensibleModel):
else:
return _("Event {}".format(self.pk))
@property
def period_from_on_day(self) -> int:
day = getattr(self, "_date", timezone.now().date())
if day != self.date_start:
return TimePeriod.period_min
else:
return self.period_from.period
@property
def period_to_on_day(self) -> int:
day = getattr(self, "_date", timezone.now().date())
if day != self.date_end:
return TimePeriod.period_max
else:
return self.period_to.period
class Meta:
ordering = ["date_start"]
indexes = [models.Index(fields=["period_from", "period_to", "date_start", "date_end"])]
......@@ -1064,10 +1087,10 @@ class ExtraLessonQuerySet(TimetableQuerySet):
)
def on_day(self, day:date):
self.within_dates(day, day)
return self.within_dates(day, day)
class ExtraLesson(ExtensibleModel):
class ExtraLesson(ExtensibleModel, GroupPropertiesMixin):
label_ = "extra_lesson"
objects = models.Manager.from_queryset(ExtraLessonQuerySet)()
......
......@@ -13,7 +13,7 @@
{# Teacher or class > Display rooms #}
{% if type == "teacher" or type == "group" %}
{% for room in event.rooms.all %}
{% include "chronos/partials/room.html" with room=room %}
{% include "chronos/partials/room.html" with room=room %}{% if not forloop.last %},{% endif %}
{% endfor %}
{% endif %}
......
<span class="tooltipped" data-position="bottom" data-tooltip="{{ room.name }}">
<a href="{% url "timetable" "room" room.pk %}">
{{ room.short_name }}
</a>
</span>
{% if room %}
<span class="tooltipped" data-position="bottom" data-tooltip="{{ room.name }}">
<a href="{% url "timetable" "room" room.pk %}">
{{ room.short_name }}
</a>
</span>
{% endif %}
......@@ -6,4 +6,6 @@
{% endif %}
{% elif item.type == "supervision_substitution" %}
blue-text
{% elif item.type == "event" %}
purple-text
{% endif %}
{% if el.title %}
<em>{{ el.title }}</em>
{% elif el.comment %}
<em>{{ el.comment }}</em>
{% endif %}
{% if type == "substitution" %}
{% include "chronos/partials/groups.html" with groups=el.lesson_period.lesson.groups.all %}
{% elif type == "extra_lesson" or type == "event" %}
{% include "chronos/partials/groups.html" with groups=el.groups.all %}
{% endif %}
<strong>
{% if type == "substitution" %}
{{ el.lesson_period.period.period }}.
{% elif type == "extra_lesson" %}
{{ el.period.period }}.
{% elif type == "event" %}
{% if el.period_from_on_day == el.period_to_on_day %}
{{ el.period_from_on_day }}.
{% else %}
{{ el.period_from_on_day }}.–{{ el.period_to_on_day }}.
{% endif %}
{% elif type == "supervision_substitution" %}
{% with break=el.supervision.break_item %}
{{ break.after_period_number }}./{{ break.before_period_number }}.
......
......@@ -30,4 +30,10 @@
{{ supervision.area.short_name }}
</span>
{% endwith %}
{% elif type == "extra_lesson" %}
{% include "chronos/partials/room.html" with room=el.room %}
{% elif type == "event" %}
{% for room in el.rooms.all %}
{% include "chronos/partials/room.html" with room=room %}{% if not forloop.last %},{% endif %}
{% endfor %}
{% endif %}
......@@ -15,14 +15,14 @@
<strong>{{ el.subject.abbrev }}</strong>
</span>
{% elif el.subject and not el.lesson_period.lesson.subject %}
<span data-position="bottom" class="tooltipped" data-tooltip="{{ el.subject.name }}">
<strong>{{ el.subject.abbrev }}</strong>
</span>
{% include "chronos/partials/subject.html" with subject=el.subject %}
{% else %}
<span data-position="bottom" class="tooltipped" data-tooltip="{{ el.lesson_period.lesson.subject.name }}">
<strong>{{ el.lesson_period.lesson.subject.abbrev }}</strong>
</span>
{% include "chronos/partials/subject.html" with subject=el.lesson_period.lesson.subject %}
{% endif %}
{% elif type == "supervision_substitution" %}
{% trans "Supervision" %}
{% elif type == "extra_lesson" %}
{% include "chronos/partials/subject.html" with subject=el.subject %}
{% elif type == "event" %}
{% trans "Event" %}
{% endif %}
......@@ -22,4 +22,6 @@
<strong>
{% include "chronos/partials/teachers.html" with teachers=el.teachers %}
</strong>
{% elif type == "extra_lesson" or type == "event" %}
{% include "chronos/partials/teachers.html" with teachers=el.teachers.all %}
{% endif %}
......@@ -61,9 +61,7 @@
<tr class="{% include "chronos/partials/subs/colour.html" with item=item %}">
{# TODO: Extend support for purple (events) #}
<td>
{% if item.type == "substitution" %}
{% include "chronos/partials/groups.html" with groups=item.el.lesson_period.lesson.groups.all %}
{% endif %}
{% include "chronos/partials/subs/groups.html" with type=item.type el=item.el %}
</td>
<td>
{% include "chronos/partials/subs/period.html" with type=item.type el=item.el %}
......@@ -81,7 +79,7 @@
<span class="hide-on-med-and-up">
{% include "chronos/partials/subs/badge.html" with sub=item.el %}
</span>
<em>{{ sub.comment|default:"" }}</em>
{% include "chronos/partials/subs/comment.html" with el=item.el %}
</td>
<td class="hide-on-small-and-down">
{% include "chronos/partials/subs/badge.html" with sub=item.el %}
......
......@@ -54,9 +54,7 @@
<tr class="{% include "chronos/partials/subs/colour.html" with item=item %}">
<td>
{% if item.type == "substitution" %}
{% include "chronos/partials/groups.html" with groups=item.el.lesson_period.lesson.groups.all %}
{% endif %}
{% include "chronos/partials/subs/groups.html" with type=item.type el=item.el %}
</td>
<td>
{% include "chronos/partials/subs/period.html" with type=item.type el=item.el %}
......@@ -72,7 +70,7 @@
</td>
<td>
{% include "chronos/partials/subs/badge.html" with sub=item.el %}
<em>{{ sub.comment|default:"" }}</em>
{% include "chronos/partials/subs/comment.html" with el=item.el %}
</td>
</tr>
{% endfor %}
......
......@@ -299,6 +299,35 @@ def build_substitutions_list(wanted_day: date) -> List[dict]:
}
rows.append(row)
# Get extra lessons
extra_lessons = ExtraLesson.objects.on_day(wanted_day)
for extra_lesson in extra_lessons:
row = {
"type": "extra_lesson",
"sort_a": "{}".format(extra_lesson.group_names),
"sort_b": "{}".format(extra_lesson.period.period),
"el": extra_lesson,
}
rows.append(row)
# Get events
events = Event.objects.on_day(wanted_day).annotate_day(wanted_day)
for event in events:
if event.groups.all():
sort_a = event.group_names
else:
sort_a = "Z.".format(event.teacher_names)
row = {
"type": "event",
"sort_a": sort_a,
"sort_b": "{}".format(event.period_from_on_day),
"el": event,
}
rows.append(row)
# Sort all items
def sorter(row: dict):
return row["sort_a"] + row["sort_b"]
......
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