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

Merge branch '112-do-not-allow-entries-in-holidays-configurable' into 'master'

Resolve "Do not allow entries in holidays (configurable)"

Closes #112

See merge request !101
parents ac14107d 1ee57edd
No related branches found
No related tags found
1 merge request!101Resolve "Do not allow entries in holidays (configurable)"
Pipeline #5059 passed
...@@ -58,3 +58,11 @@ class AllowOpenPeriodsOnSameDay(BooleanPreference): ...@@ -58,3 +58,11 @@ class AllowOpenPeriodsOnSameDay(BooleanPreference):
help_text = _( help_text = _(
"Lessons in the past are not affected by this setting, you can open them whenever you want." "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")
...@@ -16,7 +16,8 @@ from reversion.views import RevisionMixin ...@@ -16,7 +16,8 @@ from reversion.views import RevisionMixin
from rules.contrib.views import PermissionRequiredMixin, permission_required from rules.contrib.views import PermissionRequiredMixin, permission_required
from aleksis.apps.chronos.managers import TimetableType 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.apps.chronos.util.date import get_weeks_for_year, 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
...@@ -90,6 +91,13 @@ def lesson( ...@@ -90,6 +91,13 @@ def lesson(
_("You are not allowed to create a lesson documentation for a lesson in the future.") _("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) next_lesson = request.user.person.next_lesson(lesson_period, date_of_lesson)
prev_lesson = request.user.person.previous_lesson(lesson_period, date_of_lesson) prev_lesson = request.user.person.previous_lesson(lesson_period, date_of_lesson)
...@@ -98,69 +106,71 @@ def lesson( ...@@ -98,69 +106,71 @@ def lesson(
context["day"] = wanted_week[lesson_period.period.weekday] context["day"] = wanted_week[lesson_period.period.weekday]
context["next_lesson_person"] = next_lesson context["next_lesson_person"] = next_lesson
context["prev_lesson_person"] = prev_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 if not blocked_because_holidays:
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",
)
# Create a formset that holds all personal notes for all persons in this lesson # Create or get lesson documentation object; can be empty when first opening lesson
if not request.user.has_perm("alsijil.view_lesson_personalnote", lesson_period): lesson_documentation = lesson_period.get_or_create_lesson_documentation(wanted_week)
persons = Person.objects.filter(pk=request.user.person.pk) lesson_documentation_form = LessonDocumentationForm(
else: request.POST or None, instance=lesson_documentation, prefix="lesson_documentation",
persons = Person.objects.all() )
persons_qs = lesson_period.get_personal_notes(persons, wanted_week) # Create a formset that holds all personal notes for all persons in this lesson
personal_note_formset = PersonalNoteFormSet( if not request.user.has_perm("alsijil.view_lesson_personalnote", lesson_period):
request.POST or None, queryset=persons_qs, prefix="personal_notes" persons = Person.objects.filter(pk=request.user.person.pk)
) else:
persons = Person.objects.all()
if request.method == "POST": persons_qs = lesson_period.get_personal_notes(persons, wanted_week)
if lesson_documentation_form.is_valid() and request.user.has_perm( personal_note_formset = PersonalNoteFormSet(
"alsijil.edit_lessondocumentation", lesson_period request.POST or None, queryset=persons_qs, prefix="personal_notes"
): )
with reversion.create_revision():
reversion.set_user(request.user) if request.method == "POST":
lesson_documentation_form.save() if lesson_documentation_form.is_valid() and request.user.has_perm(
"alsijil.edit_lessondocumentation", lesson_period
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
): ):
with reversion.create_revision(): with reversion.create_revision():
reversion.set_user(request.user) reversion.set_user(request.user)
instances = personal_note_formset.save() lesson_documentation_form.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.")) messages.success(request, _("The lesson documentation has been saved."))
# Regenerate form here to ensure that programmatically substitution = lesson_period.get_substitution()
# changed data will be shown correctly if (
personal_note_formset = PersonalNoteFormSet( not getattr(substitution, "cancelled", False)
None, queryset=persons_qs, prefix="personal_notes" 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 messages.success(request, _("The personal notes have been saved."))
context["lesson_documentation_form"] = lesson_documentation_form
context["personal_note_formset"] = personal_note_formset # Regenerate form here to ensure that programmatically
context["prev_lesson"] = lesson_period.prev # changed data will be shown correctly
context["next_lesson"] = lesson_period.next 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) return render(request, "alsijil/class_register/lesson.html", context)
...@@ -361,6 +371,7 @@ def week_view( ...@@ -361,6 +371,7 @@ def week_view(
context["group"] = group context["group"] = group
context["select_form"] = select_form context["select_form"] = select_form
context["instance"] = instance context["instance"] = instance
context["weekdays"] = build_weekdays(TimePeriod.WEEKDAY_CHOICES, wanted_week)
week_prev = wanted_week - 1 week_prev = wanted_week - 1
week_next = wanted_week + 1 week_next = wanted_week + 1
...@@ -698,6 +709,12 @@ def register_absence(request: HttpRequest, id_: int) -> HttpResponse: ...@@ -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 to_period_on_day = to_period if i == delta.days else TimePeriod.period_max
day = start_date + timedelta(days=i) 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( affected_count += person.mark_absent(
day, day,
from_period_on_day, from_period_on_day,
......
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