From ce5b7fb5e79e4088fe08018df7e8515263d6364d Mon Sep 17 00:00:00 2001 From: Tom Teichler <tom.teichler@teckids.org> Date: Tue, 19 Nov 2019 17:54:25 +0100 Subject: [PATCH] Add first part of issue. --- biscuit/apps/alsijil/forms.py | 9 ++++++ biscuit/apps/alsijil/menus.py | 5 ++++ .../templates/alsijil/manage_absence.html | 29 +++++++++++++++++++ biscuit/apps/alsijil/urls.py | 3 +- biscuit/apps/alsijil/views.py | 24 ++++++++++++++- 5 files changed, 68 insertions(+), 2 deletions(-) create mode 100644 biscuit/apps/alsijil/templates/alsijil/manage_absence.html diff --git a/biscuit/apps/alsijil/forms.py b/biscuit/apps/alsijil/forms.py index 7912bcf8b..90f7c8b07 100644 --- a/biscuit/apps/alsijil/forms.py +++ b/biscuit/apps/alsijil/forms.py @@ -47,3 +47,12 @@ class SelectForm(forms.Form): PersonalNoteFormSet = forms.modelformset_factory( PersonalNote, form=PersonalNoteForm, max_num=0, extra=0) + + +class AbsentExcusedForm(forms.Form): + date_start = forms.DateField(label=_('Start date'), widget=forms.SelectDateWidget) + date_end = forms.DateField(label=_('End date'), widget=forms.SelectDateWidget) + starting_lesson = forms.ChoiceField(label=_('Starting lesson')) + person = forms.ModelChoiceField(label=_('Person'), queryset=Person.objects.all(), widget=Select2Widget) + absent = forms.BooleanField(label=_('Absent')) + excused = forms.BooleanField(label=_('Excused')) diff --git a/biscuit/apps/alsijil/menus.py b/biscuit/apps/alsijil/menus.py index b53893561..6184cbe5d 100644 --- a/biscuit/apps/alsijil/menus.py +++ b/biscuit/apps/alsijil/menus.py @@ -17,6 +17,11 @@ MENUS = { 'name': _('Current week'), 'url': 'week_view', 'validators': ['menu_generator.validators.is_authenticated'] + }, + { + 'name': _('Manage absence'), + 'url': 'manage_absence', + 'validators': ['menu_generator.validators.is_superuser'] } ] } diff --git a/biscuit/apps/alsijil/templates/alsijil/manage_absence.html b/biscuit/apps/alsijil/templates/alsijil/manage_absence.html new file mode 100644 index 000000000..16231893f --- /dev/null +++ b/biscuit/apps/alsijil/templates/alsijil/manage_absence.html @@ -0,0 +1,29 @@ +{# -*- engine:django -*- #} +{% extends "core/base.html" %} +{% load bootstrap4 i18n static %} + +{% block bootstrap4_extra_head %} + {{ block.super }} + {{ manage_absence_form.media.css }} +{% endblock %} + +{% block bootstrap4_extra_script %} + {{ block.super }} + {{ manage_absence_form.media.js }} +{% endblock %} + +{% block bootstrap4_title %}{% blocktrans%}Manage absence{% endblocktrans %} - {{ block.super }}{% endblock %} + +{% block page_title %}Manage absences{% endblock %} + +{% block content %} + + <form method="post"> + {% csrf_token %} + {% bootstrap_form manage_absence_form %} + <button type="submit" class="btn btn-dark"> + {% blocktrans %}Save{% endblocktrans %} + </button> + </form> + +{% endblock %} diff --git a/biscuit/apps/alsijil/urls.py b/biscuit/apps/alsijil/urls.py index e8d4c6b25..717459432 100644 --- a/biscuit/apps/alsijil/urls.py +++ b/biscuit/apps/alsijil/urls.py @@ -11,5 +11,6 @@ urlpatterns = [ path('week/<int:year>/<int:week>', views.week_view, name='week_view_by_week'), path('print/group/<int:id_>', views.full_register_group, - name='full_register_group') + name='full_register_group'), + path('absences/new', views.absences_excuses, name='manage_absence'), ] diff --git a/biscuit/apps/alsijil/views.py b/biscuit/apps/alsijil/views.py index 497576ce2..3c5984886 100644 --- a/biscuit/apps/alsijil/views.py +++ b/biscuit/apps/alsijil/views.py @@ -12,8 +12,9 @@ from django.utils.translation import ugettext as _ from biscuit.apps.chronos.models import LessonPeriod from biscuit.apps.chronos.util import CalendarWeek from biscuit.core.models import Group, Person +from biscuit.core.decorators import admin_required -from .forms import LessonDocumentationForm, PersonalNoteFormSet, SelectForm +from .forms import AbsentExcusedForm, LessonDocumentationForm, PersonalNoteFormSet, SelectForm from .models import LessonDocumentation @@ -202,3 +203,24 @@ def full_register_group(request: HttpRequest, id_: int) -> HttpResponse: context['today'] = date.today() return render(request, 'alsijil/print/full_register.html', context) + + +@admin_required +def absences_excuses(request: HttpRequest) -> HttpResponse: + context = {} + + manage_absence_form = AbsentExcusedForm( + request.POST or None, initial={'absent': True, 'excused': True}) + + if request.method == 'POST': + if manage_absence_form.is_valid(): + # Get person from form + person = Person.objects.get(id=manage_absence_form.cleaned_data['person']) + + + messages.success(request, _('The absence has been saved.')) + return redirect(request, 'index.html') + + context['manage_absence_form'] = manage_absence_form + + return render(request, 'alsijil/manage_absence.html', context) -- GitLab