diff --git a/aleksis/apps/alsijil/preferences.py b/aleksis/apps/alsijil/preferences.py index 07ed2153a26e8b5af09131dc464b9d6ab4f7b74e..4ced04f41ba56db628b4dc4438242a81bc36f5eb 100644 --- a/aleksis/apps/alsijil/preferences.py +++ b/aleksis/apps/alsijil/preferences.py @@ -58,3 +58,11 @@ class AllowOpenPeriodsOnSameDay(BooleanPreference): help_text = _( "Lessons in the past are not affected by this setting, you can open them whenever you want." ) + + +@site_preferences_registry.register +class AllowEntriesInHolidays(BooleanPreference): + section = alsijil + name = "allow_entries_in_holidays" + default = False + verbose_name = _("Allow teachers to add data for lessons in holidays") diff --git a/aleksis/apps/alsijil/templates/alsijil/class_register/lesson.html b/aleksis/apps/alsijil/templates/alsijil/class_register/lesson.html index b001b70061ac572d998834198ce05ea977271e1a..23c96614dba54513c8c8dc4d033fd10cdc2665d6 100644 --- a/aleksis/apps/alsijil/templates/alsijil/class_register/lesson.html +++ b/aleksis/apps/alsijil/templates/alsijil/class_register/lesson.html @@ -67,8 +67,10 @@ <form method="post" class="row"> <p> - {% if can_edit_lesson_documentation or can_edit_lesson_personalnote %} - {% include "core/partials/save_button.html" %} + {% if not blocked_because_holidays %} + {% if can_edit_lesson_documentation or can_edit_lesson_personalnote %} + {% include "core/partials/save_button.html" %} + {% endif %} {% endif %} <a class="btn waves-effect waves-light primary" @@ -90,284 +92,307 @@ {% csrf_token %} - <div class="row"> - <div class="col s12"> - <ul class="tabs"> - <li class="tab"> - <a href="#lesson-documentation">{% trans "Lesson documentation" %}</a> - </li> - {% if not lesson_period.get_substitution.cancelled or not request.site.preferences.alsijil__block_personal_notes_for_cancelled %} + {% if not blocked_because_holidays %} + + <div class="row"> + <div class="col s12"> + <ul class="tabs"> <li class="tab"> - <a href="#personal-notes">{% trans "Personal notes" %}</a> + <a href="#lesson-documentation">{% trans "Lesson documentation" %}</a> </li> - {% endif %} - {% has_perm "alsijil.view_lessondocumentation" user lesson_period.prev as can_view_prev_lesson_documentation %} - {% if lesson_period.prev.get_lesson_documentation and can_view_prev_lesson_documentation %} + {% if not lesson_period.get_substitution.cancelled or not request.site.preferences.alsijil__block_personal_notes_for_cancelled %} + <li class="tab"> + <a href="#personal-notes">{% trans "Personal notes" %}</a> + </li> + {% endif %} + {% has_perm "alsijil.view_lessondocumentation" user lesson_period.prev as can_view_prev_lesson_documentation %} + {% if lesson_period.prev.get_lesson_documentation and can_view_prev_lesson_documentation %} + <li class="tab"> + <a href="#previous-lesson">{% trans "Previous lesson" %}</a> + </li> + {% endif %} <li class="tab"> - <a href="#previous-lesson">{% trans "Previous lesson" %}</a> + <a href="#version-history">{% trans "Change history" %}</a> </li> - {% endif %} - <li class="tab"> - <a href="#version-history">{% trans "Change history" %}</a> - </li> - </ul> - </div> - - <div class="col s12" id="lesson-documentation"> - <div class="card"> - <div class="card-content"> - <span class="card-title"> - {% blocktrans %}Lesson documentation{% endblocktrans %} - </span> - - {% if can_edit_lesson_documentation %} - {% form form=lesson_documentation_form %}{% endform %} - {% elif can_view_lesson_documentation %} - <table> - <tr> - <th> - {% trans "Lesson topic" %} - </th> - <td> - {{ lesson_documentation.topic }} - </td> - </tr> - <tr> - <th> - {% trans "Homework" %} - </th> - <td> - {{ lesson_documentation.homework }} - </td> - </tr> - <tr> - <th> - {% trans "Group note" %} - </th> - <td> - {{ lesson_documentation.group_note }} - </td> - </tr> - </table> - {% endif %} - </div> + </ul> </div> - </div> - - {% with prev_lesson=lesson_period.prev prev_doc=prev_lesson.get_lesson_documentation %} - {% with absences=prev_lesson.get_absences tardinesses=prev_lesson.get_tardinesses extra_marks=prev_lesson.get_extra_marks %} - {% has_perm "alsijil.view_lessondocumentation" user prev_lesson as can_view_prev_lesson_documentation %} - {% if prev_doc and can_view_prev_lesson_documentation %} - {% weekday_to_date prev_lesson.week prev_lesson.period.weekday as prev_date %} - <div class="col s12" id="previous-lesson"> - <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 prev_doc.group_note %} - <tr> - <th class="collection-item">{% trans "Group notes for previous lesson:" %}</th> - <td>{{ prev_doc.group_note }}</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 %} - - {% for extra_mark, notes in extra_marks.items %} - <tr> - <th>{{ extra_mark.name }}</th> - <td> - {% for note in notes %} - {% has_perm "alsijil.view_personalnote" user note as can_view_personalnote %} - {% if can_view_personalnote %} - <span>{{ note.person }}{% if not forloop.last %},{% endif %}</span> - {% endif %} - {% endfor %} - </td> - </tr> - {% endfor %} - - </table> - </div> - </div> - </div> - {% endif %} - {% endwith %} - {% endwith %} - - {% if not lesson_period.get_substitution.cancelled or not request.site.preferences.alsijil__block_personal_notes_for_cancelled %} - <div class="col s12" id="personal-notes"> + <div class="col s12" id="lesson-documentation"> <div class="card"> <div class="card-content"> <span class="card-title"> - {% blocktrans %}Personal notes{% endblocktrans %} + {% blocktrans %}Lesson documentation{% endblocktrans %} </span> - {% if can_edit_lesson_personalnote %} - {% form form=personal_note_formset.management_form %}{% endform %} + + {% if can_edit_lesson_documentation %} + {% form form=lesson_documentation_form %}{% endform %} + {% elif can_view_lesson_documentation %} + <table> + <tr> + <th> + {% trans "Lesson topic" %} + </th> + <td> + {{ lesson_documentation.topic }} + </td> + </tr> + <tr> + <th> + {% trans "Homework" %} + </th> + <td> + {{ lesson_documentation.homework }} + </td> + </tr> + <tr> + <th> + {% trans "Group note" %} + </th> + <td> + {{ lesson_documentation.group_note }} + </td> + </tr> + </table> {% endif %} + </div> + </div> + </div> - <table class="striped responsive-table alsijil-table"> - <thead> - <tr> - <th>{% blocktrans %}Person{% endblocktrans %}</th> - <th>{% blocktrans %}Absent{% endblocktrans %}</th> - <th>{% blocktrans %}Tardiness{% endblocktrans %}</th> - <th>{% blocktrans %}Excused{% endblocktrans %}</th> - <th>{% blocktrans %}Excuse type{% endblocktrans %}</th> - <th>{% blocktrans %}Extra marks{% endblocktrans %}</th> - <th>{% blocktrans %}Remarks{% endblocktrans %}</th> - </tr> - </thead> - <tbody> - {% for form in personal_note_formset %} - {% if can_edit_lesson_personalnote %} - <tr> - {{ form.id }} - <td>{{ form.person_name }}{{ form.person_name.value }}</td> - <td class="center-align"> - <label> - {{ form.absent }} - <span></span> - </label> - </td> - <td> - <div class="input-field"> - {{ form.late }} - <label for="{{ form.absent.id_for_label }}"> - {% trans "Tardiness (in m)" %} + {% with prev_lesson=lesson_period.prev prev_doc=prev_lesson.get_lesson_documentation %} + {% with absences=prev_lesson.get_absences tardinesses=prev_lesson.get_tardinesses extra_marks=prev_lesson.get_extra_marks %} + {% has_perm "alsijil.view_lessondocumentation" user prev_lesson as can_view_prev_lesson_documentation %} + {% if prev_doc and can_view_prev_lesson_documentation %} + {% weekday_to_date prev_lesson.week prev_lesson.period.weekday as prev_date %} + <div class="col s12" id="previous-lesson"> + <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 prev_doc.group_note %} + <tr> + <th class="collection-item">{% trans "Group notes for previous lesson:" %}</th> + <td>{{ prev_doc.group_note }}</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 %} + + {% for extra_mark, notes in extra_marks.items %} + <tr> + <th>{{ extra_mark.name }}</th> + <td> + {% for note in notes %} + {% has_perm "alsijil.view_personalnote" user note as can_view_personalnote %} + {% if can_view_personalnote %} + <span>{{ note.person }}{% if not forloop.last %},{% endif %}</span> + {% endif %} + {% endfor %} + </td> + </tr> + {% endfor %} + + </table> + </div> + </div> + </div> + {% endif %} + {% endwith %} + {% endwith %} + + {% if not lesson_period.get_substitution.cancelled or not request.site.preferences.alsijil__block_personal_notes_for_cancelled %} + <div class="col s12" id="personal-notes"> + <div class="card"> + <div class="card-content"> + <span class="card-title"> + {% blocktrans %}Personal notes{% endblocktrans %} + </span> + {% if can_edit_lesson_personalnote %} + {% form form=personal_note_formset.management_form %}{% endform %} + {% endif %} + + <table class="striped responsive-table alsijil-table"> + <thead> + <tr> + <th>{% blocktrans %}Person{% endblocktrans %}</th> + <th>{% blocktrans %}Absent{% endblocktrans %}</th> + <th>{% blocktrans %}Tardiness{% endblocktrans %}</th> + <th>{% blocktrans %}Excused{% endblocktrans %}</th> + <th>{% blocktrans %}Excuse type{% endblocktrans %}</th> + <th>{% blocktrans %}Extra marks{% endblocktrans %}</th> + <th>{% blocktrans %}Remarks{% endblocktrans %}</th> + </tr> + </thead> + <tbody> + {% for form in personal_note_formset %} + {% if can_edit_lesson_personalnote %} + <tr> + {{ form.id }} + <td>{{ form.person_name }}{{ form.person_name.value }}</td> + <td class="center-align"> + <label> + {{ form.absent }} + <span></span> </label> - </div> - </td> - <td class="center-align"> - <label> - {{ form.excused }} - <span></span> - </label> - </td> - <td> - <div class="input-field"> - {{ form.excuse_type }} - <label for="{{ form.excuse_type.id_for_label }}"> - {% trans "Excuse type" %} + </td> + <td> + <div class="input-field"> + {{ form.late }} + <label for="{{ form.absent.id_for_label }}"> + {% trans "Tardiness (in m)" %} + </label> + </div> + </td> + <td class="center-align"> + <label> + {{ form.excused }} + <span></span> </label> - </div> - </td> - <td> - {% for group, items in form.extra_marks|select_options %} - {% for choice, value, selected in items %} - <label class="{% if selected %} active{% endif %} alsijil-check-box"> - <input type="checkbox" - {% if value == None or value == '' %}disabled{% else %}value="{{ value }}"{% endif %} - {% if selected %} checked="checked"{% endif %} - name="{{ form.extra_marks.html_name }}"> - <span>{{ choice }}</span> + </td> + <td> + <div class="input-field"> + {{ form.excuse_type }} + <label for="{{ form.excuse_type.id_for_label }}"> + {% trans "Excuse type" %} </label> + </div> + </td> + <td> + {% for group, items in form.extra_marks|select_options %} + {% for choice, value, selected in items %} + <label class="{% if selected %} active{% endif %} alsijil-check-box"> + <input type="checkbox" + {% if value == None or value == '' %}disabled{% else %}value="{{ value }}"{% endif %} + {% if selected %} checked="checked"{% endif %} + name="{{ form.extra_marks.html_name }}"> + <span>{{ choice }}</span> + </label> + {% endfor %} {% endfor %} - {% endfor %} - </td> - <td> - <div class="input-field"> - {{ form.remarks }} - <label for="{{ form.remarks.id_for_label }}"> - {% trans "Remarks" %} - </label> - </div> - </td> - </tr> - {% else %} - <tr> - <td>{{ form.person_name.value }}</td> - <td><i class="material-icons center">{{ form.absent.value|yesno:"check,clear" }}</i></td> - <td> - <i class="material-icons center">{{ form.late.value|yesno:"check,clear" }}</i> - <span class="alsijil-tardiness-text"> + </td> + <td> + <div class="input-field"> + {{ form.remarks }} + <label for="{{ form.remarks.id_for_label }}"> + {% trans "Remarks" %} + </label> + </div> + </td> + </tr> + {% else %} + <tr> + <td>{{ form.person_name.value }}</td> + <td><i class="material-icons center">{{ form.absent.value|yesno:"check,clear" }}</i></td> + <td> + <i class="material-icons center">{{ form.late.value|yesno:"check,clear" }}</i> + <span class="alsijil-tardiness-text"> {% if form.late.value %}{{ form.late.value|to_time|time:"i\m" }}{% endif %} </span> - </td> - <td><i class="material-icons center">{{ form.excused.value|yesno:"check,clear" }}</i></td> - <td>{% firstof form.excuse_type.value "–" %}</td> - <td> - {% for extra_mark in form.extra_marks.value %} - {{ extra_mark }}{% if not forloop.last %},{% endif %} - {% empty %} - – - {% endfor %} - </td> - <td>{% firstof form.remarks.value "–" %}</td> - </tr> - {% endif %} - {% endfor %} - </tbody> - </table> + </td> + <td><i class="material-icons center">{{ form.excused.value|yesno:"check,clear" }}</i></td> + <td>{% firstof form.excuse_type.value "–" %}</td> + <td> + {% for extra_mark in form.extra_marks.value %} + {{ extra_mark }}{% if not forloop.last %},{% endif %} + {% empty %} + – + {% endfor %} + </td> + <td>{% firstof form.remarks.value "–" %}</td> + </tr> + {% endif %} + {% endfor %} + </tbody> + </table> + </div> </div> </div> - </div> - {% endif %} + {% endif %} - {% if can_view_lesson_documentation %} - <div class="col s12" id="version-history"> - <div class="card"> - <div class="card-content"> - <span class="card-title"> - {% blocktrans %}Change history{% endblocktrans %} - </span> - {% include 'core/partials/crud_events.html' with obj=lesson_documentation %} + {% if can_view_lesson_documentation %} + <div class="col s12" id="version-history"> + <div class="card"> + <div class="card-content"> + <span class="card-title"> + {% blocktrans %}Change history{% endblocktrans %} + </span> + {% include 'core/partials/crud_events.html' with obj=lesson_documentation %} + </div> </div> </div> - </div> - {% endif %} - </div> + {% endif %} + </div> - <p> - {% if can_edit_lesson_documentation or can_edit_lesson_personalnote %} - {% include "core/partials/save_button.html" %} - {% endif %} - <a class="btn primary waves-effect waves-light" - href="{% url "lesson_by_week_and_period" prev_lesson.week.year prev_lesson.week.week prev_lesson.id %}"> - <i class="material-icons left">arrow_back</i> - {% blocktrans with subject=lesson_period.get_subject.name %} - Previous {{ subject }} lesson - {% endblocktrans %} - </a> + <p> + {% if can_edit_lesson_documentation or can_edit_lesson_personalnote %} + {% include "core/partials/save_button.html" %} + {% endif %} - <a class="btn primary right waves-effect waves-light" - href="{% url "lesson_by_week_and_period" next_lesson.week.year next_lesson.week.week next_lesson.id %}"> - <i class="material-icons right">arrow_forward</i> - {% blocktrans with subject=lesson_period.get_subject.name %} - Next {{ subject }} lesson - {% endblocktrans %} - </a> - </p> + <a class="btn primary waves-effect waves-light" + href="{% url "lesson_by_week_and_period" prev_lesson.week.year prev_lesson.week.week prev_lesson.id %}"> + <i class="material-icons left">arrow_back</i> + {% blocktrans with subject=lesson_period.get_subject.name %} + Previous {{ subject }} lesson + {% endblocktrans %} + </a> + + <a class="btn primary right waves-effect waves-light" + href="{% url "lesson_by_week_and_period" next_lesson.week.year next_lesson.week.week next_lesson.id %}"> + <i class="material-icons right">arrow_forward</i> + {% blocktrans with subject=lesson_period.get_subject.name %} + Next {{ subject }} lesson + {% endblocktrans %} + </a> + </p> + + {% else %} + <div class="row no-margin"> + <div class="container"> + <div class="card"> + <div class="card-content center-align"> + <p> + <i class="material-icons medium orange-text">warning</i> + </p> + <p class="card-title"> + {% blocktrans %} + This lesson overlaps with holidays and can't be edited. + {% endblocktrans %} + </p> + <span class="badge new blue no-float no-margin">{{ holiday }}</span> + </div> + </div> + </div> + </div> + {% endif %} </form> {% endblock %} diff --git a/aleksis/apps/alsijil/templates/alsijil/class_register/week_view.html b/aleksis/apps/alsijil/templates/alsijil/class_register/week_view.html index 6328de5bf81e056e75ac33454b2cfe02eb176289..0f55e11eaeffe87ca49564074b10cbbae1acc398 100644 --- a/aleksis/apps/alsijil/templates/alsijil/class_register/week_view.html +++ b/aleksis/apps/alsijil/templates/alsijil/class_register/week_view.html @@ -64,175 +64,200 @@ <div class="row"> <div class="col s12"> <ul class="tabs"> - <li class="tab col s6"><a class="active" href="#week-overview">{% trans "Lesson documentations" %}</a></li> - <li class="tab col s6"><a class="active" href="#personal-notes">{% trans "Personal notes" %}</a></li> + <li class="tab col s6"> + <a class="active" href="#week-overview">{% trans "Lesson documentations" %}</a> + </li> + <li class="tab col s6"> + <a class="active" href="#personal-notes">{% trans "Personal notes" %}</a> + </li> </ul> </div> <div class="col s12" id="week-overview"> {% regroup lesson_periods by period.get_weekday_display as periods_by_day %} {% for weekday, periods in periods_by_day %} - <div class="card show-on-extra-large"> - <div class="card-content"> - {% weekday_to_date week periods.0.period.weekday as current_date %} - <span class="card-title"> - {{ weekday }}, {{ current_date }} - </span> - <table class="striped datatable"> - <thead> - <tr> - <th></th> - <th>{% blocktrans %}Period{% endblocktrans %}</th> - {% if not group %} - <th>{% blocktrans %}Groups{% endblocktrans %}</th> - {% endif %} - <th>{% blocktrans %}Subject{% endblocktrans %}</th> - <th>{% blocktrans %}Teachers{% endblocktrans %}</th> - <th>{% blocktrans %}Lesson topic{% endblocktrans %}</th> - <th>{% blocktrans %}Homework{% endblocktrans %}</th> - <th>{% blocktrans %}Group note{% endblocktrans %}</th> - </tr> - </thead> - <tbody> - {% for period in periods %} - {% has_perm "alsijil.view_lessondocumentation" user period as can_view_lesson_documentation %} - {% if can_view_lesson_documentation %} + {% with weekdays|get_dict:forloop.counter0 as advanced_weekday %} + {% weekday_to_date week periods.0.period.weekday as current_date %} + + {% if advanced_weekday.holiday and not request.site.preferences.alsijil__allow_entries_in_holidays %} + <div class="card"> + <div class="card-content"> + {% weekday_to_date week periods.0.period.weekday as current_date %} + <span class="card-title"> + {{ weekday }}, {{ current_date }} <span class="badge new blue no-float">{{ advanced_weekday.holiday }}</span> + </span> + </div> + </div> + {% else %} + <div class="card show-on-extra-large"> + <div class="card-content"> + <span class="card-title"> + {{ weekday }}, {{ current_date }} + </span> + <table class="striped datatable"> + <thead> <tr> - <td class="center-align"> - {% include "alsijil/partials/lesson_status_icon.html" with period=period %} - </td> - <td class="tr-link"> - <a class="tr-link" href="{% url 'lesson_by_week_and_period' week.year week.week period.id %}"> - {{ period.period.period }}. - </a> - </td> + <th></th> + <th>{% blocktrans %}Period{% endblocktrans %}</th> {% if not group %} - <td> - <a class="tr-link" href="{% url 'lesson_by_week_and_period' week.year week.week period.id %}"> - {{ period.lesson.group_names }} - </a> - </td> + <th>{% blocktrans %}Groups{% endblocktrans %}</th> {% endif %} - <td> - <a class="tr-link" href="{% url 'lesson_by_week_and_period' week.year week.week period.id %}"> - {{ period.get_subject.name }} - </a> - </td> - <td> - <a class="tr-link" href="{% url 'lesson_by_week_and_period' week.year week.week period.id %}"> - {{ period.get_teacher_names }} - </a> - </td> - <td> - <a class="tr-link" href="{% url 'lesson_by_week_and_period' week.year week.week period.id %}"> - {% firstof period.get_lesson_documentation.topic "–" %} - </a> - </td> - <td> - <a class="tr-link" href="{% url 'lesson_by_week_and_period' week.year week.week period.id %}"> - {% firstof period.get_lesson_documentation.homework "–" %} - </a> - </td> - <td> - <a class="tr-link" href="{% url 'lesson_by_week_and_period' week.year week.week period.id %}"> - {% firstof period.get_lesson_documentation.group_note "–" %} - </a> - </td> + <th>{% blocktrans %}Subject{% endblocktrans %}</th> + <th>{% blocktrans %}Teachers{% endblocktrans %}</th> + <th>{% blocktrans %}Lesson topic{% endblocktrans %}</th> + <th>{% blocktrans %}Homework{% endblocktrans %}</th> + <th>{% blocktrans %}Group note{% endblocktrans %}</th> </tr> - {% endif %} - {% endfor %} - </tbody> - </table> - </div> - </div> - <ul class="collapsible hide-on-extra-large-only"> - <li class=""> - {% weekday_to_date week periods.0.period.weekday as current_date %} - <div class="collapsible-header flow-text"> - {{ weekday }}, {{ current_date }} <i class="material-icons collapsible-icon-right">expand_more</i> - </div> - <div class="collapsible-body"> - <div class="collection"> - {% for period in periods %} - {% has_perm "alsijil.view_lessondocumentation" user period as can_view_lesson_documentation %} - {% if can_view_lesson_documentation %} - <a class="collection-item avatar" - href="{% url 'lesson_by_week_and_period' week.year week.week period.id %}"> - {% include "alsijil/partials/lesson_status_icon.html" with period=period css_class="materialize-circle" color_suffix=" " %} - <table class="hide-on-med-and-down"> - <tr> - <th>{% trans "Subject" %}</th> - <td>{{ period.period.period }}. {{ period.get_subject.name }}</td> - </tr> + </thead> + <tbody> + {% for period in periods %} + {% has_perm "alsijil.view_lessondocumentation" user period as can_view_lesson_documentation %} + {% if can_view_lesson_documentation %} + <tr> + <td class="center-align"> + {% include "alsijil/partials/lesson_status_icon.html" with period=period %} + </td> + <td class="tr-link"> + <a class="tr-link" + href="{% url 'lesson_by_week_and_period' week.year week.week period.id %}"> + {{ period.period.period }}. + </a> + </td> {% if not group %} - <tr> - <th>{% trans "Group" %}</th> - <td>{{ period.lesson.group_names }}</td> - </tr> - {% endif %} - <tr> - <th>{% trans "Teachers" %}</th> - <td>{{ period.lesson.teacher_names }}</td> - </tr> - <tr> - <th>{% trans "Lesson topic" %}</th> - <td>{% firstof period.get_lesson_documentation.topic "–" %}</td> - </tr> - {% with period.get_lesson_documentation as lesson_documentation %} - {% if lesson_documentation.homework %} - <tr> - <th>{% trans "Homework" %}</th> - <td>{% firstof period.get_lesson_documentation.homework "–" %}</td> - </tr> - {% endif %} - {% if lesson_documentation.group_note %} - <tr> - <th>{% trans "Group note" %}</th> - <td>{% firstof period.get_lesson_documentation.group_note "–" %}</td> - </tr> - {% endif %} - {% endwith %} - </table> - <div class="hide-on-large-only"> - <ul class="collection"> - <li class="collection-item"> - {{ period.period.period }}. {{ period.get_subject.name }} - </li> - {% if not group %} - <li class="collection-item"> - + <td> + <a class="tr-link" + href="{% url 'lesson_by_week_and_period' week.year week.week period.id %}"> {{ period.lesson.group_names }} - - </li> - {% endif %} - <li class="collection-item"> - {{ period.lesson.teacher_names }} - </li> - <li class="collection-item"> - {{ period.get_lesson_documentation.topic }} - </li> - {% with period.get_lesson_documentation as lesson_documentation %} - {% if lesson_documentation.homework %} - <li class="collection-item"> - <strong>{% trans "Homework" %}</strong> - {% firstof period.get_lesson_documentation.homework "–" %} - </li> - {% endif %} - {% if lesson_documentation.group_note %} - <li class="collection-item"> - <strong>{% trans "Group note" %}</strong> - {% firstof period.get_lesson_documentation.group_note "–" %} - </li> - {% endif %} - {% endwith %} - </ul> - </div> - </a> - {% endif %} - {% endfor %} + </a> + </td> + {% endif %} + <td> + <a class="tr-link" + href="{% url 'lesson_by_week_and_period' week.year week.week period.id %}"> + {{ period.get_subject.name }} + </a> + </td> + <td> + <a class="tr-link" + href="{% url 'lesson_by_week_and_period' week.year week.week period.id %}"> + {{ period.get_teacher_names }} + </a> + </td> + <td> + <a class="tr-link" + href="{% url 'lesson_by_week_and_period' week.year week.week period.id %}"> + {% firstof period.get_lesson_documentation.topic "–" %} + </a> + </td> + <td> + <a class="tr-link" + href="{% url 'lesson_by_week_and_period' week.year week.week period.id %}"> + {% firstof period.get_lesson_documentation.homework "–" %} + </a> + </td> + <td> + <a class="tr-link" + href="{% url 'lesson_by_week_and_period' week.year week.week period.id %}"> + {% firstof period.get_lesson_documentation.group_note "–" %} + </a> + </td> + </tr> + {% endif %} + {% endfor %} + </tbody> + </table> </div> </div> - </li> - </ul> + <ul class="collapsible hide-on-extra-large-only"> + <li class=""> + {% weekday_to_date week periods.0.period.weekday as current_date %} + <div class="collapsible-header flow-text"> + {{ weekday }}, {{ current_date }} <i class="material-icons collapsible-icon-right">expand_more</i> + </div> + <div class="collapsible-body"> + <div class="collection"> + {% for period in periods %} + {% has_perm "alsijil.view_lessondocumentation" user period as can_view_lesson_documentation %} + {% if can_view_lesson_documentation %} + <a class="collection-item avatar" + href="{% url 'lesson_by_week_and_period' week.year week.week period.id %}"> + {% include "alsijil/partials/lesson_status_icon.html" with period=period css_class="materialize-circle" color_suffix=" " %} + <table class="hide-on-med-and-down"> + <tr> + <th>{% trans "Subject" %}</th> + <td>{{ period.period.period }}. {{ period.get_subject.name }}</td> + </tr> + {% if not group %} + <tr> + <th>{% trans "Group" %}</th> + <td>{{ period.lesson.group_names }}</td> + </tr> + {% endif %} + <tr> + <th>{% trans "Teachers" %}</th> + <td>{{ period.lesson.teacher_names }}</td> + </tr> + <tr> + <th>{% trans "Lesson topic" %}</th> + <td>{% firstof period.get_lesson_documentation.topic "–" %}</td> + </tr> + {% with period.get_lesson_documentation as lesson_documentation %} + {% if lesson_documentation.homework %} + <tr> + <th>{% trans "Homework" %}</th> + <td>{% firstof period.get_lesson_documentation.homework "–" %}</td> + </tr> + {% endif %} + {% if lesson_documentation.group_note %} + <tr> + <th>{% trans "Group note" %}</th> + <td>{% firstof period.get_lesson_documentation.group_note "–" %}</td> + </tr> + {% endif %} + {% endwith %} + </table> + <div class="hide-on-large-only"> + <ul class="collection"> + <li class="collection-item"> + {{ period.period.period }}. {{ period.get_subject.name }} + </li> + {% if not group %} + <li class="collection-item"> + + {{ period.lesson.group_names }} + + </li> + {% endif %} + <li class="collection-item"> + {{ period.lesson.teacher_names }} + </li> + <li class="collection-item"> + {{ period.get_lesson_documentation.topic }} + </li> + {% with period.get_lesson_documentation as lesson_documentation %} + {% if lesson_documentation.homework %} + <li class="collection-item"> + <strong>{% trans "Homework" %}</strong> + {% firstof period.get_lesson_documentation.homework "–" %} + </li> + {% endif %} + {% if lesson_documentation.group_note %} + <li class="collection-item"> + <strong>{% trans "Group note" %}</strong> + {% firstof period.get_lesson_documentation.group_note "–" %} + </li> + {% endif %} + {% endwith %} + </ul> + </div> + </a> + {% endif %} + {% endfor %} + </div> + </div> + </li> + </ul> + {% endif %} + {% endwith %} {% endfor %} </div> <div class="col s12" id="personal-notes"> @@ -251,7 +276,8 @@ {% endif %} {% has_perm "alsijil.register_absence" user person.person as can_register_absence %} {% if can_register_absence %} - <a class="btn primary-color waves-effect waves-light right" href="{% url "register_absence" person.person.pk %}"> + <a class="btn primary-color waves-effect waves-light right" + href="{% url "register_absence" person.person.pk %}"> <i class="material-icons left">rate_review</i> {% trans "Register absence" %} </a> @@ -262,7 +288,7 @@ ({{ person.person.unexcused_count }} {% trans "unexcused" %}) </p> <p class="card-text"> - {% trans "Summed up tardiness" %}: {% firstof person.person.tardiness_sum|to_time|time:"H\h i\m" "–" %} + {% trans "Summed up tardiness" %}: {% firstof person.person.tardiness_sum|to_time|time:"H\h i\m" "–" %} </p> <p class="card-text"> {% trans "Count of tardiness" %}: {{ person.person.tardiness_count }} × @@ -306,14 +332,14 @@ {% endif %} <script> - $(document).ready(function () { - $("#id_group").change(function () { - $("#id_teacher").val("").formSelect(); - }); - $("#id_teacher").change(function () { - $("#id_group").val("").formSelect(); + $(document).ready(function () { + $("#id_group").change(function () { + $("#id_teacher").val("").formSelect(); + }); + $("#id_teacher").change(function () { + $("#id_group").val("").formSelect(); + }); }); - }); </script> {% endblock %} diff --git a/aleksis/apps/alsijil/views.py b/aleksis/apps/alsijil/views.py index d01214b4259ecd710a0c97840c58c7cfe6dd82d9..6b5c693313b598884fa4a5e46f1256df7d912866 100644 --- a/aleksis/apps/alsijil/views.py +++ b/aleksis/apps/alsijil/views.py @@ -16,7 +16,8 @@ from reversion.views import RevisionMixin from rules.contrib.views import PermissionRequiredMixin, permission_required from aleksis.apps.chronos.managers import TimetableType -from aleksis.apps.chronos.models import LessonPeriod, TimePeriod +from aleksis.apps.chronos.models import Holiday, LessonPeriod, TimePeriod +from aleksis.apps.chronos.util.build import build_weekdays from aleksis.apps.chronos.util.date import get_weeks_for_year, week_weekday_to_date from aleksis.core.mixins import AdvancedCreateView, AdvancedDeleteView, AdvancedEditView from aleksis.core.models import Group, Person, SchoolTerm @@ -90,6 +91,13 @@ def lesson( _("You are not allowed to create a lesson documentation for a lesson in the future.") ) + holiday = Holiday.on_day(date_of_lesson) + blocked_because_holidays = ( + holiday is not None and not get_site_preferences()["alsijil__allow_entries_in_holidays"] + ) + context["blocked_because_holidays"] = blocked_because_holidays + context["holiday"] = holiday + next_lesson = request.user.person.next_lesson(lesson_period, date_of_lesson) prev_lesson = request.user.person.previous_lesson(lesson_period, date_of_lesson) @@ -98,69 +106,71 @@ def lesson( context["day"] = wanted_week[lesson_period.period.weekday] context["next_lesson_person"] = next_lesson context["prev_lesson_person"] = prev_lesson + context["prev_lesson"] = lesson_period.prev + context["next_lesson"] = lesson_period.next - # Create or get lesson documentation object; can be empty when first opening lesson - lesson_documentation = lesson_period.get_or_create_lesson_documentation(wanted_week) - lesson_documentation_form = LessonDocumentationForm( - request.POST or None, instance=lesson_documentation, prefix="lesson_documentation", - ) + if not blocked_because_holidays: - # Create a formset that holds all personal notes for all persons in this lesson - if not request.user.has_perm("alsijil.view_lesson_personalnote", lesson_period): - persons = Person.objects.filter(pk=request.user.person.pk) - else: - persons = Person.objects.all() + # Create or get lesson documentation object; can be empty when first opening lesson + lesson_documentation = lesson_period.get_or_create_lesson_documentation(wanted_week) + lesson_documentation_form = LessonDocumentationForm( + request.POST or None, instance=lesson_documentation, prefix="lesson_documentation", + ) - persons_qs = lesson_period.get_personal_notes(persons, wanted_week) - personal_note_formset = PersonalNoteFormSet( - request.POST or None, queryset=persons_qs, prefix="personal_notes" - ) + # Create a formset that holds all personal notes for all persons in this lesson + if not request.user.has_perm("alsijil.view_lesson_personalnote", lesson_period): + persons = Person.objects.filter(pk=request.user.person.pk) + else: + persons = Person.objects.all() - if request.method == "POST": - if lesson_documentation_form.is_valid() and request.user.has_perm( - "alsijil.edit_lessondocumentation", lesson_period - ): - with reversion.create_revision(): - reversion.set_user(request.user) - lesson_documentation_form.save() - - messages.success(request, _("The lesson documentation has been saved.")) - - substitution = lesson_period.get_substitution() - if ( - not getattr(substitution, "cancelled", False) - or not get_site_preferences()["alsijil__block_personal_notes_for_cancelled"] - ): - if personal_note_formset.is_valid() and request.user.has_perm( - "alsijil.edit_lesson_personalnote", lesson_period + persons_qs = lesson_period.get_personal_notes(persons, wanted_week) + personal_note_formset = PersonalNoteFormSet( + request.POST or None, queryset=persons_qs, prefix="personal_notes" + ) + + if request.method == "POST": + if lesson_documentation_form.is_valid() and request.user.has_perm( + "alsijil.edit_lessondocumentation", lesson_period ): with reversion.create_revision(): reversion.set_user(request.user) - instances = personal_note_formset.save() - - # Iterate over personal notes and carry changed absences to following lessons - for instance in instances: - instance.person.mark_absent( - wanted_week[lesson_period.period.weekday], - lesson_period.period.period + 1, - instance.absent, - instance.excused, - instance.excuse_type, - ) + lesson_documentation_form.save() - messages.success(request, _("The personal notes have been saved.")) + messages.success(request, _("The lesson documentation has been saved.")) - # Regenerate form here to ensure that programmatically - # changed data will be shown correctly - personal_note_formset = PersonalNoteFormSet( - None, queryset=persons_qs, prefix="personal_notes" - ) + substitution = lesson_period.get_substitution() + if ( + not getattr(substitution, "cancelled", False) + or not get_site_preferences()["alsijil__block_personal_notes_for_cancelled"] + ): + if personal_note_formset.is_valid() and request.user.has_perm( + "alsijil.edit_lesson_personalnote", lesson_period + ): + with reversion.create_revision(): + reversion.set_user(request.user) + instances = personal_note_formset.save() + + # Iterate over personal notes and carry changed absences to following lessons + for instance in instances: + instance.person.mark_absent( + wanted_week[lesson_period.period.weekday], + lesson_period.period.period + 1, + instance.absent, + instance.excused, + instance.excuse_type, + ) - context["lesson_documentation"] = lesson_documentation - context["lesson_documentation_form"] = lesson_documentation_form - context["personal_note_formset"] = personal_note_formset - context["prev_lesson"] = lesson_period.prev - context["next_lesson"] = lesson_period.next + messages.success(request, _("The personal notes have been saved.")) + + # Regenerate form here to ensure that programmatically + # changed data will be shown correctly + personal_note_formset = PersonalNoteFormSet( + None, queryset=persons_qs, prefix="personal_notes" + ) + + context["lesson_documentation"] = lesson_documentation + context["lesson_documentation_form"] = lesson_documentation_form + context["personal_note_formset"] = personal_note_formset return render(request, "alsijil/class_register/lesson.html", context) @@ -361,6 +371,7 @@ def week_view( context["group"] = group context["select_form"] = select_form context["instance"] = instance + context["weekdays"] = build_weekdays(TimePeriod.WEEKDAY_CHOICES, wanted_week) week_prev = wanted_week - 1 week_next = wanted_week + 1 @@ -698,6 +709,12 @@ def register_absence(request: HttpRequest, id_: int) -> HttpResponse: to_period_on_day = to_period if i == delta.days else TimePeriod.period_max day = start_date + timedelta(days=i) + # Skip holidays if activated + if not get_site_preferences()["alsijil__allow_entries_in_holidays"]: + holiday = Holiday.on_day(day) + if holiday: + continue + affected_count += person.mark_absent( day, from_period_on_day,