Skip to content
Snippets Groups Projects
Commit ba98d8ed authored by Hangzhi Yu's avatar Hangzhi Yu
Browse files

Display initial lesson data with substituted lessons in daily lessons table

parent d96c7733
No related branches found
No related tags found
1 merge request!276Resolve "[UI] Redesign Daily Lessons"
Pipeline #96736 canceled
......@@ -13,6 +13,7 @@ Added
~~~~~
* Add filter to daily lessons page.
* Display initial lesson data with substituted lessons in daily lessons table.
Fixed
~~~~~
......
......@@ -2,10 +2,11 @@ from __future__ import annotations
from typing import Optional
from django.utils.html import format_html
from django.utils.translation import gettext_lazy as _
import django_tables2 as tables
from django_tables2.utils import A
from django_tables2.utils import A, Accessor
from .models import LessonPeriod
......@@ -23,6 +24,21 @@ def _css_class_from_lesson_state(
return ""
class SubstitutionColumn(tables.Column):
def render(self, value, record: Optional[LessonPeriod] = None):
if record.get_substitution():
return format_html(
"<s>{}</s> → {}",
value,
self.substitution_accessor.resolve(record.get_substitution()),
)
return value
def __init__(self, *args, **kwargs):
self.substitution_accessor = Accessor(kwargs.pop("substitution_accessor"))
super().__init__(*args, **kwargs)
class LessonsTable(tables.Table):
"""Table for daily lessons and management of substitutions."""
......@@ -32,9 +48,15 @@ class LessonsTable(tables.Table):
period__period = tables.Column(accessor="period__period")
lesson__groups = tables.Column(accessor="lesson__group_names", verbose_name=_("Groups"))
lesson__teachers = tables.Column(accessor="lesson__teacher_names", verbose_name=_("Teachers"))
lesson__subject = tables.Column(accessor="lesson__subject")
room = tables.Column(accessor="room")
lesson__teachers = SubstitutionColumn(
accessor="lesson__teacher_names",
substitution_accessor="teacher_names",
verbose_name=_("Teachers"),
)
lesson__subject = SubstitutionColumn(
accessor="lesson__subject", substitution_accessor="subject"
)
room = SubstitutionColumn(accessor="room", substitution_accessor="room")
edit_substitution = tables.LinkColumn(
"edit_substitution",
args=[A("id"), A("_week")],
......
......@@ -24,10 +24,6 @@
{% form form=lesson_periods_filter.form %}{% endform %}
{% trans "Search" as caption %}
{% include "core/partials/save_button.html" with caption=caption icon="mdi:search" %}
<button type="reset" class="btn red waves-effect waves-light">
<i class="material-icons iconify left" data-icon="mdi:close"></i>
{% trans "Clear" %}
</button>
</form>
<div class="row no-margin">
......
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