diff --git a/aleksis/apps/chronos/models.py b/aleksis/apps/chronos/models.py index 245d2f9b59231aa34fcc7b219eb6078eefe7f93a..9a93bf5700e4dd9655d3e67eb29ab3e43a881be5 100644 --- a/aleksis/apps/chronos/models.py +++ b/aleksis/apps/chronos/models.py @@ -508,6 +508,8 @@ class LessonSubstitution(ExtensibleModel): class LessonPeriod(ExtensibleModel): + label_ = "lesson_period" + objects = LessonPeriodManager.from_queryset(LessonPeriodQuerySet)() lesson = models.ForeignKey("Lesson", models.CASCADE, related_name="lesson_periods") diff --git a/aleksis/apps/chronos/templates/chronos/partials/elements.html b/aleksis/apps/chronos/templates/chronos/partials/elements.html new file mode 100644 index 0000000000000000000000000000000000000000..a2a90559662ff9655ef828de555416a22a6ae2d3 --- /dev/null +++ b/aleksis/apps/chronos/templates/chronos/partials/elements.html @@ -0,0 +1,9 @@ +<div class="card lesson-card"> + <div class="card-content"> + {% for element in elements %} + {% if element.label_ == "lesson_period" %} + {% include "chronos/partials/lesson.html" with lesson_period=element %} + {% endif %} + {% endfor %} + </div> +</div> diff --git a/aleksis/apps/chronos/templates/chronos/partials/lesson.html b/aleksis/apps/chronos/templates/chronos/partials/lesson.html index 8dc4f9fb2f264cfe188241502d298cf3e095ccf3..4ede1065ac1f7821410bc106e17bc6f599d6d669 100644 --- a/aleksis/apps/chronos/templates/chronos/partials/lesson.html +++ b/aleksis/apps/chronos/templates/chronos/partials/lesson.html @@ -1,131 +1,123 @@ {% load i18n %} -<div class="card lesson-card"> - <div class="card-content"> - - {# Every element of the lesson #} - {% for lesson_period in lessons %} - <div style=" - {# Display background color only if no badge exists and it is not the old room and there are no holidays #} - {% if not lesson_period.get_substitution.cancelled and not lesson_period.is_hol %} - {% if not lesson_period.room != lesson_period.get_room or type != 1 %} - {% if lesson_period.lesson.subject.colour_fg %} - color: {{ lesson_period.lesson.subject.colour_fg }}; - {% endif %} - {% if lesson_period.lesson.subject.colour_bg %} - background-color: {{ lesson_period.lesson.subject.colour_bg }}; - {% endif %} - {% endif %} - {% endif %} - " - {# Add CSS class for sub when it's a sub #} - class="{% if lesson_period.get_substitution and smart %}{% if lesson_period.substitution.table.is_event %}lesson-with-event{% else %}lesson-with-sub{% endif %}{% endif %}" - > - <p> - {% if lesson_period.is_hol and smart %} - {# Do nothing #} - {% elif lesson_period.get_substitution and smart %} - {% with sub=lesson_period.get_substitution %} - {# SUBSTITUTION #} - {% if type == "room" and lesson_period.room != lesson_period.get_room %} - {# When it's the old room, let it empty #} - - {% elif lesson_period.get_substitution.cancelled %} - {# When a badge (cancellation, etc.) exists, then display it with the teacher#} - - {# Class or room > Display teacher #} - {% if type == "group" or type == "room" and lesson_period.lesson.teachers.all %} - {% include "chronos/partials/teachers.html" with teachers=lesson_period.lesson.teachers.all %}<br/> - {% endif %} - - {# Badge #} - <span class="badge new green darken-2">{% trans "Cancelled" %}</span> - - {% else %} - {# Display sub #} - - {# Teacher or room > display classes #} - {% if type == "teacher" or type == "room" %} - {% include "chronos/partials/groups.html" with groups=lesson_period.lesson.groups.all %} - {% endif %} - - {# Display teacher with tooltip #} - {% include "chronos/partials/subs/teachers.html" %} - - {# Display subject #} - {% include "chronos/partials/subs/subject.html" %} - - {# Teacher or class > display room #} - {% if type == "teacher" or type == "group" %} - {% include "chronos/partials/subs/room.html" %} - {% endif %} - {% endif %} - - - {# When it isn't a room or the old plan, then display the extra text (e. g. work orders) AND NOT A EVENT#} - {% if not lesson_period.substitution.table.is_event %} - {% if not type == "room" or not lesson_period.is_old %} - <br> - <small> - <em>{{ lesson_period.substitution.table.text|default:"" }}</em> - </small> - {% endif %} - {% endif %} - {# Display the extra text for events #} - {% if lesson_period.substitution.table.is_event %} - {% if type == 0 and lesson_period.substitution.table.classes == "" and lesson_period.substitution.table.rooms|length == 0 and lesson_period.substitutions.table.teachers|length == 0 %} - <em>{{ lesson_period.substitution.table.text|default:"" }}</em> - {% elif type == 2 and lesson_period.substitution.table.teachers|length == 0 and lesson_period.substitution.table.rooms|length == 0 %} - <em>{{ lesson_period.substitution.table.text|default:"" }}</em> - {% elif type == 1 and lesson_period.substitution.table.teachers|length == 0 and lesson_period.substitution.table.classes == "" %} - <em>{{ lesson_period.substitution.table.text|default:"" }}</em> - {% else %} - <br> - <small> - <em>{{ lesson_period.substitution.table.text|default:"" }}</em> - </small> - {% endif %} - {% endif %} - {% endwith %} +<div style=" + {# Display background color only if no badge exists and it is not the old room and there are no holidays #} + {% if not lesson_period.get_substitution.cancelled and not lesson_period.is_hol %} + {% if not lesson_period.room != lesson_period.get_room or type != 1 %} + {% if lesson_period.lesson.subject.colour_fg %} + color: {{ lesson_period.lesson.subject.colour_fg }}; + {% endif %} + {% if lesson_period.lesson.subject.colour_bg %} + background-color: {{ lesson_period.lesson.subject.colour_bg }}; + {% endif %} + {% endif %} + {% endif %} + " + {# Add CSS class for sub when it's a sub #} + class=" + {% if lesson_period.get_substitution and smart %}{% if lesson_period.substitution.table.is_event %}lesson-with-event{% else %}lesson-with-sub{% endif %}{% endif %}" +> + <p> + {% if lesson_period.is_hol and smart %} + {# Do nothing #} + {% elif lesson_period.get_substitution and smart %} + {% with sub=lesson_period.get_substitution %} + {# SUBSTITUTION #} + {% if type == "room" and lesson_period.room != lesson_period.get_room %} + {# When it's the old room, let it empty #} + + {% elif lesson_period.get_substitution.cancelled %} + {# When a badge (cancellation, etc.) exists, then display it with the teacher#} + + {# Class or room > Display teacher #} + {% if type == "group" or type == "room" and lesson_period.lesson.teachers.all %} + {% include "chronos/partials/teachers.html" with teachers=lesson_period.lesson.teachers.all %}<br/> + {% endif %} + + {# Badge #} + <span class="badge new green darken-2">{% trans "Cancelled" %}</span> + + {% else %} + {# Display sub #} + + {# Teacher or room > display classes #} + {% if type == "teacher" or type == "room" %} + {% include "chronos/partials/groups.html" with groups=lesson_period.lesson.groups.all %} + {% endif %} + + {# Display teacher with tooltip #} + {% include "chronos/partials/subs/teachers.html" %} + + {# Display subject #} + {% include "chronos/partials/subs/subject.html" %} + + {# Teacher or class > display room #} + {% if type == "teacher" or type == "group" %} + {% include "chronos/partials/subs/room.html" %} + {% endif %} + {% endif %} + {# When it isn't a room or the old plan, then display the extra text (e. g. work orders) AND NOT A EVENT#} + {% if not lesson_period.substitution.table.is_event %} + {% if not type == "room" or not lesson_period.is_old %} + <br> + <small> + <em>{{ lesson_period.substitution.table.text|default:"" }}</em> + </small> + {% endif %} + {% endif %} + {# Display the extra text for events #} + {% if lesson_period.substitution.table.is_event %} + {% if type == 0 and lesson_period.substitution.table.classes == "" and lesson_period.substitution.table.rooms|length == 0 and lesson_period.substitutions.table.teachers|length == 0 %} + <em>{{ lesson_period.substitution.table.text|default:"" }}</em> + {% elif type == 2 and lesson_period.substitution.table.teachers|length == 0 and lesson_period.substitution.table.rooms|length == 0 %} + <em>{{ lesson_period.substitution.table.text|default:"" }}</em> + {% elif type == 1 and lesson_period.substitution.table.teachers|length == 0 and lesson_period.substitution.table.classes == "" %} + <em>{{ lesson_period.substitution.table.text|default:"" }}</em> {% else %} - {# Normal plan #} - - {# Teacher or room > Display classes #} - {% if type == "teacher" or type == "room" %} - {# {{ element_container.element.classes }}#} - {% if lesson_period.lesson.groups %} - {% include "chronos/partials/groups.html" with groups=lesson_period.lesson.groups.all %} - {% endif %} - {% endif %} + <br> + <small> + <em>{{ lesson_period.substitution.table.text|default:"" }}</em> + </small> + {% endif %} + {% endif %} + {% endwith %} - {# Class or room > Display teacher #} - {% if type == "room" or type == "group" %} - {% include "chronos/partials/teachers.html" with teachers=lesson_period.lesson.teachers.all %} - {% endif %} - {# Display subject #} - <strong> + {% else %} + {# Normal plan #} + + {# Teacher or room > Display classes #} + {% if type == "teacher" or type == "room" %} + {# {{ element_container.element.classes }}#} + {% if lesson_period.lesson.groups %} + {% include "chronos/partials/groups.html" with groups=lesson_period.lesson.groups.all %} + {% endif %} + {% endif %} + + {# Class or room > Display teacher #} + {% if type == "room" or type == "group" %} + {% include "chronos/partials/teachers.html" with teachers=lesson_period.lesson.teachers.all %} + {% endif %} + + {# Display subject #} + <strong> <span data-position="bottom" class="tooltipped" data-tooltip="{{ lesson_period.lesson.subject.name }}">{{ lesson_period.lesson.subject.abbrev }}</span> - </strong> + </strong> - {# Teacher or class > Display room #} - {% if type == "teacher" or type == "group" %} - {% if lesson_period.room %} - <span class="tooltipped" data-position="bottom" - data-tooltip="{{ lesson_period.room.name }}"> + {# Teacher or class > Display room #} + {% if type == "teacher" or type == "group" %} + {% if lesson_period.room %} + <span class="tooltipped" data-position="bottom" + data-tooltip="{{ lesson_period.room.name }}"> <a href="{% url "timetable" "room" lesson_period.room.pk %}"> {{ lesson_period.room.short_name }} </a> </span> - {% endif %} - {% endif %} - {% endif %} - </p> - </div> - - {% endfor %} - </div> + {% endif %} + {% endif %} + {% endif %} + </p> </div> diff --git a/aleksis/apps/chronos/templates/chronos/partials/lessons_col.html b/aleksis/apps/chronos/templates/chronos/partials/lessons_col.html index abb2710a6a147d2bbc67ab17be784a6c52f5da69..2777e27251872cb1d8be2a040cd8c7b5af3ba694 100644 --- a/aleksis/apps/chronos/templates/chronos/partials/lessons_col.html +++ b/aleksis/apps/chronos/templates/chronos/partials/lessons_col.html @@ -4,7 +4,7 @@ {% include "chronos/partials/period_time.html" with period=period periods=periods %} </div> <div class="col s8"> - {% include "chronos/partials/lesson.html" with lessons=lessons %} + {% include "chronos/partials/elements.html" with elements=lessons %} </div> </div> {% endfor %} diff --git a/aleksis/apps/chronos/templates/chronos/timetable.html b/aleksis/apps/chronos/templates/chronos/timetable.html index 097874dff89f0db8f3c0ece886af7e459c53d5be..bb0cf82acc885ff9bf7fbe04264ed7a5c116acf2 100644 --- a/aleksis/apps/chronos/templates/chronos/timetable.html +++ b/aleksis/apps/chronos/templates/chronos/timetable.html @@ -175,7 +175,7 @@ {% for col in row.cols %} {# A lesson #} <div class="col s2"> - {% include "chronos/partials/lesson.html" with lessons=col %} + {% include "chronos/partials/elements.html" with elements=col %} </div> {% endfor %} </div> @@ -197,17 +197,17 @@ {# #} </div> </div> - {% for period, lesson_periods_period in lesson_periods.items %} + {% for row in timetable %} <div class="row"> <div class="col s4"> - {% include "chronos/partials/period_time.html" with period=period periods=periods %} + {% include "chronos/partials/period_time.html" with period=row.period periods=periods %} </div> - {% for weekday, lessons in lesson_periods_period.items %} + {% for col in row.cols %} {% if forloop.counter0 == i %} <div class="col s8"> {# A lesson #} - {% include "chronos/partials/lesson.html" with lessons=lessons %} + {% include "chronos/partials/elements.html" with elements=col %} </div> {% endif %} {% endfor %}