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 tags found
1 merge request!101Resolve "Do not allow entries in holidays (configurable)"
Pipeline #5059 passed
......@@ -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")
......@@ -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,
......
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