Skip to content
Snippets Groups Projects
Verified Commit 55d1b882 authored by Julian's avatar Julian Committed by Jonathan Weth
Browse files

Implement multiple selection in person overview

parent 944b3661
No related branches found
No related tags found
1 merge request!111Resolve "[Person overview] Implement multiple selection for marking absences as excused or for deleting"
span.input-field.inline > .select-wrapper > input {
color: red;
padding: 14px 0 0 0;
line-height: 2px;
height: 36px;
vertical-align: middle;
}
span.input-field.inline > .select-wrapper .caret {
top: 12px !important;
}
\ No newline at end of file
......@@ -4,6 +4,11 @@
{% load data_helpers %}
{% load week_helpers %}
{% load i18n %}
{% load static %}
{% block extra_head %}
<link rel="stylesheet" href="{% static "css/alsijil/person.css" %}">
{% endblock %}
{% block browser_title %}{% blocktrans %}Class register: person{% endblocktrans %}{% endblock %}
......@@ -33,51 +38,76 @@
<div class="row">
<div class="col s12 m12 l6">
<h5>{% trans "Unexcused absences" %}</h5>
<ul class="collection">
{% for note in unexcused_absences %}
<li class="collection-item">
{% has_perm "alsijil.edit_personalnote" user note as can_edit_personal_note %}
{% if can_edit_personal_note %}
<form action="" method="post" class="right hide-on-small-only" style="margin-top: -7px;">
<h5>{% trans "Unexcused absences" %}</h5>
<h6>
<form method="POST" id="excuse-multiple-form">
{% csrf_token %}
{% trans "Mark as" %}
<input type="hidden" value="{{ note.pk }}" name="personal_note">
{% include "alsijil/partials/mark_as_buttons.html" %}
<a class="btn-flat red-text" title="{% trans "Delete note" %}"
href="{% url "delete_personal_note" note.pk %}">
<i class="material-icons center">cancel</i>
</a>
</form>
{% endif %}
<i class="material-icons left red-text">warning</i>
<p class="no-margin">
<a href="{{ note.get_absolute_url }}">{{ note.date }}, {{ note.lesson_period }}</a>
</p>
{% if note.remarks %}
<p class="no-margin"><em>{{ note.remarks }}</em></p>
{% endif %}
{% if can_edit_personal_note %}
<form action="" method="post" class="hide-on-med-and-up">
{% csrf_token %}
{% trans "Mark as" %}
<input type="hidden" value="{{ note.pk }}" name="personal_note">
{% include "alsijil/partials/mark_as_buttons.html" %}
<a class="btn-flat red-text" title="{% trans "Delete note" %}"
href="{% url "delete_personal_note" note.pk %}">
<i class="material-icons center">cancel</i>
</a>
</form>
{% endif %}
</li>
{% empty %}
<li class="collection-item avatar valign-wrapper">
<i class="material-icons left materialize-circle green white-text">check</i>
<span class="title">{% trans "There are no unexcused lessons." %}</span>
</li>
{% endfor %}
</ul>
{% trans "Mark selected as" %}
<span class="input-field inline">
<select id="excuse-type-multiple" name="excuse_type">
<option value="e" selected>{% trans "Excused" %}</option>
{% for excuse_type in excuse_types %}
<option value="{{ excuse_type.pk }}">{{ excuse_type.name }}</option>
{% endfor %}
</select>
<label for="excuse-type-multiple" class="hide">{% trans "Excuse type" %}</label>
</span>
<button type="submit" class="btn secondary-color" name="excuse_multiple" value="1">
{% trans "Submit" %}<i class="material-icons right">send</i>
</button>
</form>
</h6>
<ul class="collection">
{% for note in unexcused_absences %}
{% weekday_to_date note.calendar_week note.lesson_period.period.weekday as note_date %}
<li class="collection-item">
{% has_perm "alsijil.edit_personalnote" user note as can_edit_personal_note %}
{% if can_edit_personal_note %}
<label class="left">
<input type="checkbox" name="selected_notes" value="{{ note.pk }}"
form="excuse-multiple-form"/>
<span></span>
</label>
<form action="" method="post" class="right hide-on-small-only" style="margin-top: -7px;">
{% csrf_token %}
{% trans "Mark as" %}
<input type="hidden" value="{{ note.pk }}" name="personal_note">
{% include "alsijil/partials/mark_as_buttons.html" %}
<a class="btn-flat red-text" title="{% trans "Delete note" %}"
href="{% url "delete_personal_note" note.pk %}">
<i class="material-icons center">cancel</i>
</a>
</form>
{% endif %}
<i class="material-icons left red-text">warning</i>
<p class="no-margin">
<a href="{% url "lesson_by_week_and_period" note.year note.week note.lesson_period.pk %}">{{ note_date }}, {{ note.lesson_period }}</a>
</p>
{% if note.remarks %}
<p class="no-margin"><em>{{ note.remarks }}</em></p>
{% endif %}
{% if can_edit_personal_note %}
<form action="" method="post" class="hide-on-med-and-up">
{% csrf_token %}
{% trans "Mark as" %}
<input type="hidden" value="{{ note.pk }}" name="personal_note">
{% include "alsijil/partials/mark_as_buttons.html" %}
<a class="btn-flat red-text" title="{% trans "Delete note" %}"
href="{% url "delete_personal_note" note.pk %}">
<i class="material-icons center">cancel</i>
</a>
</form>
{% endif %}
</li>
{% empty %}
<li class="collection-item avatar valign-wrapper">
<i class="material-icons left circle green white-text">check</i>
<span class="title">{% trans "There are no unexcused lessons." %}</span>
</li>
{% endfor %}
</ul>
{% if stats %}
<h5>{% trans "Statistics on absences, tardiness and remarks" %}</h5>
<ul class="collapsible">
......
from contextlib import nullcontext
from copy import deepcopy
from contextlib import suppress
from datetime import date, datetime, timedelta
from typing import Any, Dict, Optional
......@@ -736,7 +737,35 @@ def overview_person(request: HttpRequest, id_: Optional[int] = None) -> HttpResp
pass
if found:
if request.POST.get("date"):
if request.POST.get("excuse_multiple") and request.POST.get("selected_notes"):
if not request.user.has_perm(
"alsijil.edit_person_overview_personalnote", person
):
raise PermissionDenied()
lesson_pks = request.POST.getlist("selected_notes")
def convert_to_int_optional(x):
with suppress(ValueError):
return int(x)
lesson_pks = [convert_to_int_optional(pk) for pk in lesson_pks]
notes = person.personal_notes.filter(
pk__in=lesson_pks,
absent=True,
excused=False,
)
for note in notes:
note.excused = True
note.excuse_type = excuse_type
with reversion.create_revision():
reversion.set_user(request.user)
note.save()
messages.success(request, _("The absences have been marked as excused."))
elif request.POST.get("date"):
# Mark absences on date as excused
try:
date = datetime.strptime(request.POST["date"], "%Y-%m-%d").date()
......
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