diff --git a/aleksis/apps/alsijil/preferences.py b/aleksis/apps/alsijil/preferences.py new file mode 100644 index 0000000000000000000000000000000000000000..e2a55de885f3e415d9b4e461ab3192f899af2398 --- /dev/null +++ b/aleksis/apps/alsijil/preferences.py @@ -0,0 +1,16 @@ +from django.utils.translation import gettext as _ + +from dynamic_preferences.preferences import Section +from dynamic_preferences.types import BooleanPreference + +from aleksis.core.registries import site_preferences_registry + +alsijil = Section("alsijil", verbose_name=_("Class register")) + + +@site_preferences_registry.register +class BlockPersonalNotesForCancelled(BooleanPreference): + section = alsijil + name = "block_personal_notes_for_cancelled" + default = True + verbose_name = _("Block adding personal notes for cancelled lessons") diff --git a/aleksis/apps/alsijil/templates/alsijil/class_register/lesson.html b/aleksis/apps/alsijil/templates/alsijil/class_register/lesson.html index 3f2c5be29af5e4dcc48df7678d4019665774a7c1..9fca5de56fc8bd6316a4db3728ae449cd3882cbb 100644 --- a/aleksis/apps/alsijil/templates/alsijil/class_register/lesson.html +++ b/aleksis/apps/alsijil/templates/alsijil/class_register/lesson.html @@ -59,9 +59,11 @@ <li class="tab"> <a href="#lesson-documentation">{% trans "Lesson documentation" %}</a> </li> - <li class="tab"> - <a href="#personal-notes">{% trans "Personal notes" %}</a> - </li> + {% 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 %} <li class="tab"> <a href="#version-history">{% trans "Change history" %}</a> </li> @@ -146,87 +148,100 @@ </div> </div> - <div class="col s12" id="personal-notes"> - <div class="card"> - <div class="card-content"> + {% 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> - {% form form=personal_note_formset.management_form %}{% endform %} - - <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 %} + {% form form=personal_note_formset.management_form %}{% endform %} + + <table class="striped responsive-table alsijil-table"> + <thead> <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)" %} + <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 %} + <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.absent.id_for_label }}"> - {% trans "Remarks" %} - </label> - </div> - </td> - </tr> - {% endfor %} - </tbody> - </table> + </td> + <td> + <div class="input-field"> + {{ form.remarks }} + <label for="{{ form.absent.id_for_label }}"> + {% trans "Remarks" %} + </label> + </div> + </td> + <td> + <div class="input-field"> + {{ form.remarks }} + <label for="{{ form.absent.id_for_label }}"> + {% trans "Remarks" %} + </label> + </div> + </td> + </tr> + {% endfor %} + </tbody> + </table> + </div> </div> </div> - </div> + + {% endif %} + <div class="col s12" id="version-history"> <div class="card"> <div class="card-content"> diff --git a/aleksis/apps/alsijil/templates/alsijil/partials/lesson_status_icon.html b/aleksis/apps/alsijil/templates/alsijil/partials/lesson_status_icon.html index 08746b5c9791b1b3f118387b3835dd4cbc4eec03..57b71b661994baf0f2b37a71678098d564cc88ed 100644 --- a/aleksis/apps/alsijil/templates/alsijil/partials/lesson_status_icon.html +++ b/aleksis/apps/alsijil/templates/alsijil/partials/lesson_status_icon.html @@ -8,17 +8,13 @@ {% period_to_time_start week period.period as time_start %} {% period_to_time_end week period.period as time_end %} - {% if now_dt > time_end %} + {% if period.get_substitution.cancelled %} + <i class="material-icons red-text tooltipped {{ css_class }}" data-position="bottom" data-tooltip="{% trans "Lesson cancelled" %}" title="{% trans "Lesson cancelled" %}">cancel</i> + {% elif now_dt > time_end %} <i class="material-icons red-text tooltipped {{ css_class }}" data-position="bottom" data-tooltip="{% trans "Missing data" %}" title="{% trans "Missing data" %}">history</i> {% elif now_dt > time_start and now_dt < time_end %} <i class="material-icons orange-text tooltipped {{ css_class }}" data-position="bottom" data-tooltip="{% trans "Pending" %}" title="{% trans "Pending" %}">more_horiz</i> - {% else %} - {% if period.get_substitution %} - {% if period.get_substitution.cancelled %} - <i class="material-icons red-text tooltipped {{ css_class }}" data-position="bottom" data-tooltip="{% trans "Lesson cancelled" %}" title="{% trans "Lesson cancelled" %}">cancel</i> - {% else %} - <i class="material-icons orange-text tooltipped {{ css_class }}" data-position="bottom" data-tooltip="{% trans "Substitution" %}" title="{% trans "Substitution" %}">update</i> - {% endif %} - {% endif %} + {% elif period.get_substitution %} + <i class="material-icons orange-text tooltipped {{ css_class }}" data-position="bottom" data-tooltip="{% trans "Substitution" %}" title="{% trans "Substitution" %}">update</i> {% endif %} {% endif %} diff --git a/aleksis/apps/alsijil/views.py b/aleksis/apps/alsijil/views.py index dda455f5a3632171ff1dc35878db1fef0fcab15e..c5213e5f23aeade67cc70c7dde5471eb32b21696 100644 --- a/aleksis/apps/alsijil/views.py +++ b/aleksis/apps/alsijil/views.py @@ -14,12 +14,13 @@ from reversion.views import RevisionMixin from rules.contrib.views import PermissionRequiredMixin from aleksis.apps.chronos.managers import TimetableType -from aleksis.apps.chronos.models import LessonPeriod +from aleksis.apps.chronos.models import LessonPeriod, LessonSubstitution from aleksis.apps.chronos.util.chronos_helpers import get_el_by_pk from aleksis.apps.chronos.util.date import week_weekday_to_date from aleksis.core.mixins import AdvancedCreateView, AdvancedDeleteView, AdvancedEditView from aleksis.core.models import Group, Person, SchoolTerm from aleksis.core.util import messages +from aleksis.core.util.core_helpers import get_site_preferences from .forms import ( ExcuseTypeForm, @@ -114,18 +115,23 @@ def lesson( messages.success(request, _("The lesson documentation has been saved.")) - if personal_note_formset.is_valid(): - 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, - ) + 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(): + 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, + ) messages.success(request, _("The personal notes have been saved."))