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

Merge branch '82-do-not-count-cancelled-lessons' into 'master'

Resolve "Do not allow to add personal notes for cancelled lessons"

Closes #82

See merge request !61
parents f58a00cf 22e3f80d
No related branches found
No related tags found
1 merge request!61Resolve "Do not allow to add personal notes for cancelled lessons"
Pipeline #3220 passed
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")
...@@ -59,9 +59,11 @@ ...@@ -59,9 +59,11 @@
<li class="tab"> <li class="tab">
<a href="#lesson-documentation">{% trans "Lesson documentation" %}</a> <a href="#lesson-documentation">{% trans "Lesson documentation" %}</a>
</li> </li>
<li class="tab"> {% if not lesson_period.get_substitution.cancelled or not request.site.preferences.alsijil__block_personal_notes_for_cancelled %}
<a href="#personal-notes">{% trans "Personal notes" %}</a> <li class="tab">
</li> <a href="#personal-notes">{% trans "Personal notes" %}</a>
</li>
{% endif %}
<li class="tab"> <li class="tab">
<a href="#version-history">{% trans "Change history" %}</a> <a href="#version-history">{% trans "Change history" %}</a>
</li> </li>
...@@ -146,87 +148,100 @@ ...@@ -146,87 +148,100 @@
</div> </div>
</div> </div>
<div class="col s12" id="personal-notes"> {% if not lesson_period.get_substitution.cancelled or not request.site.preferences.alsijil__block_personal_notes_for_cancelled %}
<div class="card"> <div class="col s12" id="personal-notes">
<div class="card-content"> <div class="card">
<div class="card-content">
<span class="card-title"> <span class="card-title">
{% blocktrans %}Personal notes{% endblocktrans %} {% blocktrans %}Personal notes{% endblocktrans %}
</span> </span>
{% form form=personal_note_formset.management_form %}{% endform %} {% form form=personal_note_formset.management_form %}{% endform %}
<table class="striped responsive-table alsijil-table"> <table class="striped responsive-table alsijil-table">
<thead> <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 %}
<tr> <tr>
{{ form.id }} <th>{% blocktrans %}Person{% endblocktrans %}</th>
<td>{{ form.person_name }}{{ form.person_name.value }}</td> <th>{% blocktrans %}Absent{% endblocktrans %}</th>
<td class="center-align"> <th>{% blocktrans %}Tardiness{% endblocktrans %}</th>
<label> <th>{% blocktrans %}Excused{% endblocktrans %}</th>
{{ form.absent }} <th>{% blocktrans %}Excuse type{% endblocktrans %}</th>
<span></span> <th>{% blocktrans %}Extra marks{% endblocktrans %}</th>
</label>
</td> <th>{% blocktrans %}Remarks{% endblocktrans %}</th>
<td> </tr>
<div class="input-field"> </thead>
{{ form.late }} <tbody>
<label for="{{ form.absent.id_for_label }}"> {% for form in personal_note_formset %}
{% trans "Tardiness (in m)" %} <tr>
{{ form.id }}
<td>{{ form.person_name }}{{ form.person_name.value }}</td>
<td class="center-align">
<label>
{{ form.absent }}
<span></span>
</label> </label>
</div> </td>
</td> <td>
<td class="center-align"> <div class="input-field">
<label> {{ form.late }}
{{ form.excused }} <label for="{{ form.absent.id_for_label }}">
<span></span> {% trans "Tardiness (in m)" %}
</label> </label>
</td> </div>
<td> </td>
<div class="input-field"> <td class="center-align">
{{ form.excuse_type }} <label>
<label for="{{ form.excuse_type.id_for_label }}"> {{ form.excused }}
{% trans "Excuse type" %} <span></span>
</label> </label>
</div> </td>
</td> <td>
<td> <div class="input-field">
{% for group, items in form.extra_marks|select_options %} {{ form.excuse_type }}
{% for choice, value, selected in items %} <label for="{{ form.excuse_type.id_for_label }}">
<label class="{% if selected %} active{% endif %} alsijil-check-box"> {% trans "Excuse type" %}
<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> </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 %}
{% endfor %} </td>
</td> <td>
<td> <div class="input-field">
<div class="input-field"> {{ form.remarks }}
{{ form.remarks }} <label for="{{ form.absent.id_for_label }}">
<label for="{{ form.absent.id_for_label }}"> {% trans "Remarks" %}
{% trans "Remarks" %} </label>
</label> </div>
</div> </td>
</td> <td>
</tr> <div class="input-field">
{% endfor %} {{ form.remarks }}
</tbody> <label for="{{ form.absent.id_for_label }}">
</table> {% trans "Remarks" %}
</label>
</div>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div> </div>
</div> </div>
</div>
{% endif %}
<div class="col s12" id="version-history"> <div class="col s12" id="version-history">
<div class="card"> <div class="card">
<div class="card-content"> <div class="card-content">
......
...@@ -8,17 +8,13 @@ ...@@ -8,17 +8,13 @@
{% period_to_time_start week period.period as time_start %} {% period_to_time_start week period.period as time_start %}
{% period_to_time_end week period.period as time_end %} {% 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> <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 %} {% 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> <i class="material-icons orange-text tooltipped {{ css_class }}" data-position="bottom" data-tooltip="{% trans "Pending" %}" title="{% trans "Pending" %}">more_horiz</i>
{% else %} {% elif period.get_substitution %}
{% if period.get_substitution %} <i class="material-icons orange-text tooltipped {{ css_class }}" data-position="bottom" data-tooltip="{% trans "Substitution" %}" title="{% trans "Substitution" %}">update</i>
{% 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 %}
{% endif %} {% endif %}
{% endif %} {% endif %}
...@@ -14,12 +14,13 @@ from reversion.views import RevisionMixin ...@@ -14,12 +14,13 @@ from reversion.views import RevisionMixin
from rules.contrib.views import PermissionRequiredMixin from rules.contrib.views import PermissionRequiredMixin
from aleksis.apps.chronos.managers import TimetableType 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.chronos_helpers import get_el_by_pk
from aleksis.apps.chronos.util.date import week_weekday_to_date from aleksis.apps.chronos.util.date import week_weekday_to_date
from aleksis.core.mixins import AdvancedCreateView, AdvancedDeleteView, AdvancedEditView from aleksis.core.mixins import AdvancedCreateView, AdvancedDeleteView, AdvancedEditView
from aleksis.core.models import Group, Person, SchoolTerm from aleksis.core.models import Group, Person, SchoolTerm
from aleksis.core.util import messages from aleksis.core.util import messages
from aleksis.core.util.core_helpers import get_site_preferences
from .forms import ( from .forms import (
ExcuseTypeForm, ExcuseTypeForm,
...@@ -114,18 +115,23 @@ def lesson( ...@@ -114,18 +115,23 @@ def lesson(
messages.success(request, _("The lesson documentation has been saved.")) messages.success(request, _("The lesson documentation has been saved."))
if personal_note_formset.is_valid(): substitution = lesson_period.get_substitution()
instances = personal_note_formset.save() if (
not getattr(substitution, "cancelled", False)
# Iterate over personal notes and carry changed absences to following lessons or not get_site_preferences()["alsijil__block_personal_notes_for_cancelled"]
for instance in instances: ):
instance.person.mark_absent( if personal_note_formset.is_valid():
wanted_week[lesson_period.period.weekday], instances = personal_note_formset.save()
lesson_period.period.period + 1,
instance.absent, # Iterate over personal notes and carry changed absences to following lessons
instance.excused, for instance in instances:
instance.excuse_type, 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.")) messages.success(request, _("The personal notes have been saved."))
......
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