Skip to content
Snippets Groups Projects
Verified Commit 4cf0c8e6 authored by Jonathan Weth's avatar Jonathan Weth :keyboard:
Browse files

Merge branch 'master' into 73-add-rules-and-permissions

parents f3cc545c 607ae327
No related branches found
No related tags found
1 merge request!49Resolve "Add rules and permissions"
......@@ -19,6 +19,11 @@ class LessonDocumentationForm(forms.ModelForm):
model = LessonDocumentation
fields = ["topic", "homework"]
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.fields["homework"].label = _("Homework for the next lesson")
class PersonalNoteForm(forms.ModelForm):
class Meta:
......
from datetime import date
from typing import Optional, Union
from django.db.models import Exists, OuterRef, QuerySet
from django.utils.translation import gettext as _
......@@ -8,7 +9,7 @@ from calendarweek import CalendarWeek
from aleksis.apps.chronos.models import LessonPeriod
from aleksis.core.models import Group, Person
from .models import PersonalNote
from .models import LessonDocumentation, PersonalNote
@Person.method
......@@ -123,3 +124,60 @@ Group.add_permission(
Person.add_permission(
"register_absence_person", _("Can register an absence for a person")
)
@LessonPeriod.method
def get_lesson_documentation(
self, week: Optional[CalendarWeek] = None
) -> Union[LessonDocumentation, None]:
"""Get lesson documentation object for this lesson."""
if not week:
week = self.week
try:
return LessonDocumentation.objects.get(lesson_period=self, week=week.week)
except LessonDocumentation.DoesNotExist:
return None
@LessonPeriod.method
def get_or_create_lesson_documentation(
self, week: Optional[CalendarWeek] = None
) -> LessonDocumentation:
"""Get or create lesson documentation object for this lesson."""
if not week:
week = self.week
lesson_documentation, created = LessonDocumentation.objects.get_or_create(
lesson_period=self, week=week.week
)
return lesson_documentation
@LessonPeriod.method
def get_absences(self, week: Optional[CalendarWeek] = None) -> QuerySet:
"""Get all personal notes of absent persons for this lesson."""
if not week:
week = self.week
return self.personal_notes.filter(week=week.week, absent=True)
@LessonPeriod.method
def get_excused_absences(self, week: Optional[CalendarWeek] = None) -> QuerySet:
"""Get all personal notes of excused absent persons for this lesson."""
if not week:
week = self.week
return self.personal_notes.filter(week=week.week, absent=True, excused=True)
@LessonPeriod.method
def get_unexcused_absences(self, week: Optional[CalendarWeek] = None) -> QuerySet:
"""Get all personal notes of unexcused absent persons for this lesson."""
if not week:
week = self.week
return self.personal_notes.filter(week=week.week, absent=True, excused=False)
@LessonPeriod.method
def get_tardinesses(self, week: Optional[CalendarWeek] = None) -> QuerySet:
"""Get all personal notes of late persons for this lesson."""
if not week:
week = self.week
return self.personal_notes.filter(week=week.week, late__gt=0)
@page {
size: A4;
table.small-print {
font-size: 10pt;
}
body {
font-family: Arial, Helvetica, san-serif;
font-size: 10pt;
#signatures {
padding-top: 3em;
}
section.sheet.smallprint {
font-size: 8pt;
#signatures .signature {
display: inline-block;
width: 12em;
border-top: 1px solid;
margin-right: 20px;
}
section.sheet.bigprint {
font-size: 12pt;
tr {
border-bottom: 1px solid rgba(0, 0, 0, 0.3);
}
span.signature-line {
display: inline-block;
width: 10em;
border-bottom: 1px solid;
}
#titlepage {
display: flex;
flex-direction: column;
justify-content: space-around;
}
#titlepage h1 {
text-align: center;
}
#titlepage img#school-logo {
display: block;
margin-left: auto;
margin-right: auto;
width: 50%;
}
#titlepage p#group-desc {
font-weight: bold;
font-size: 150%;
text-align: center;
}
#titlepage p#printed-info {
text-align: center;
}
#titlepage p#group-owners {
font-size: 130%;
text-align: center;
}
#titlepage p#signatures {
padding-top: 2em;
}
table {
width: 100%;
border: 1px solid black;
border-collapse: collapse;
}
th, td {
border: 1px solid black;
}
tr:nth-child(even) {
background-color: #f2f2f2;
td, th {
padding: 1px;
}
tr.lessons-day-first {
border-top: 2px solid;
border-top: 3px solid rgba(0, 0, 0, 0.3);
}
th.lessons-day-head {
transform: rotate(-90deg);
text-align: center;
transform: rotate(-90deg);
}
tr.lesson-cancelled td.subj {
text-decoration: line-through;
text-decoration: line-through;
}
tr.lesson-cancelled td {
background-color: #dc3545;
background-color: #EF9A9A;
}
tr.lesson-substituted td.lesson-subj {
text-decoration: line-through;
text-decoration: line-through;
}
tr.lesson-substituted td {
background-color: #ffc107;
background-color: #ffb74d;
}
td.lesson-notes {
font-size: 80%;
font-size: 80%;
}
td.lesson-notes span.lesson-note-absent {
color: #cc0000;
color: #cc0000;
}
td.lesson-notes span.lesson-note-late {
color: #ff9933;
color: #ff9933;
}
td.lesson-notes span.lesson-note-excused {
color: #009933;
color: #009933;
}
table.person-info {
border: none;
border: none;
}
table.person-info td.person-img {
text-align: center;
text-align: center;
}
table.person-info td.person-img img {
max-height: 30mm;
}
.sheet {
overflow: visible;
height: auto !important;
}
.sheet * {
page-break-inside: avoid;
max-height: 30mm;
}
img.max-size-600 {
max-width: 600px;
max-height: 600px;
}
img.center{
position: relative;
left: 50%;
transform: translateX(-50%);
max-width: 600px;
max-height: 600px;
}
{# -*- engine:django -*- #}
{% extends "core/base.html" %}
{% load material_form i18n static rules %}
{% load week_helpers material_form i18n static rules %}
{% block browser_title %}{% blocktrans %}Lesson{% endblocktrans %}{% endblock %}
......@@ -28,9 +28,31 @@
{% endblock %}
{% block content %}
<<<<<<< HEAD
{% has_perm "alsijil.view_lessondocumentation" user lesson_period as can_view_lesson_documentation %}
{% has_perm "alsijil.edit_lessondocumentation" user lesson_period as can_edit_lesson_documentation %}
{% has_perm "alsijil.edit_personalnote" user lesson_period as can_edit_personalnote %}
=======
<div class="row">
<div class="col s12">
{% with prev_lesson=lesson_period.prev %}
<a class="btn-flat left waves-effect waves-light"
href="{% url "lesson_by_week_and_period" prev_lesson.week.year prev_lesson.week.week prev_lesson.id %}">
<i class="material-icons left">arrow_back</i>
{% trans "Previous lesson" %}
</a>
{% endwith %}
{% with next_lesson=lesson_period.next %}
<a class="btn-flat right waves-effect waves-light"
href="{% url "lesson_by_week_and_period" next_lesson.week.year next_lesson.week.week next_lesson.id %}">
<i class="material-icons right">arrow_forward</i>
{% trans "Next lesson" %}
</a>
{% endwith %}
</div>
</div>
>>>>>>> master
<form method="post">
<div class="row">
......@@ -43,6 +65,53 @@
{% csrf_token %}
<div class="row">
<div class="col s12 m12 l6 xl8">
{% with prev_lesson=lesson_period.prev prev_doc=prev_lesson.get_lesson_documentation %}
{% with prev_doc=prev_lesson.get_lesson_documentation absences=prev_lesson.get_absences tardinesses=prev_lesson.get_tardinesses %}
{% if prev_doc %}
{% weekday_to_date prev_lesson.week prev_lesson.period.weekday as prev_date %}
<div class="card">
<div class="card-content">
<span class="card-title">
{% blocktrans %}Overview: Previous lesson{% endblocktrans %} ({{ prev_date }},
{% blocktrans with period=prev_lesson.period.period %}{{ period }}. period{% endblocktrans %})
</span>
<table>
{% if prev_doc.topic %}
<tr>
<th class="collection-item">{% trans "Lesson topic of previous lesson:" %}</th>
<td>{{ prev_doc.topic }}</td>
</tr>
{% endif %}
{% if prev_doc.homework %}
<tr>
<th class="collection-item">{% trans "Homework for this lesson:" %}</th>
<td>{{ prev_doc.homework }}</td>
</tr>
{% endif %}
{% if absences %}
<tr>
<th>{% trans "Absent persons:" %}</th>
<td>{% include "alsijil/partials/absences.html" with notes=absences %}</td>
</tr>
{% endif %}
{% if tardinesses %}
<tr>
<th>{% trans "Late persons:" %}</th>
<td>{% include "alsijil/partials/tardinesses.html" with notes=tardinesses %}</td>
</tr>
{% endif %}
</table>
</div>
</div>
{% endif %}
{% endwith %}
{% endwith %}
<div class="card">
<div class="card-content">
<span class="card-title">
......
{% load i18n %}
{% for note in notes %}
<span class="{% if note.excused %}green-text{% else %}red-text{% endif %}">{{ note.person }}
{% if note.excused %}{% trans "(e)" %}{% else %}{% trans "(u)" %}{% endif %}{% if not forloop.last %},{% endif %}
</span>
{% endfor %}
{% for note in notes %}
<span>{{ note.person }} ({{ note.late }}'){% if not forloop.last %},{% endif %}</span>
{% endfor %}
......@@ -66,7 +66,7 @@ def lesson(
if (
datetime.combine(
wanted_week[lesson_period.period.weekday - 1],
wanted_week[lesson_period.period.weekday],
lesson_period.period.time_start,
)
> datetime.now()
......@@ -80,12 +80,10 @@ def lesson(
context["lesson_period"] = lesson_period
context["week"] = wanted_week
context["day"] = wanted_week[lesson_period.period.weekday - 1]
context["day"] = wanted_week[lesson_period.period.weekday]
# Create or get lesson documentation object; can be empty when first opening lesson
lesson_documentation, created = LessonDocumentation.objects.get_or_create(
lesson_period=lesson_period, week=wanted_week.week
)
lesson_documentation = lesson_period.get_or_create_lesson_documentation(wanted_week)
lesson_documentation_form = LessonDocumentationForm(
request.POST or None,
instance=lesson_documentation,
......@@ -115,7 +113,7 @@ def lesson(
# 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 - 1],
wanted_week[lesson_period.period.weekday],
lesson_period.period.period + 1,
instance.absent,
instance.excused,
......@@ -295,7 +293,7 @@ def full_register_group(request: HttpRequest, id_: int) -> HttpResponse:
periods_by_day = {}
for lesson_period in lesson_periods:
for week in weeks:
day = week[lesson_period.period.weekday - 1]
day = week[lesson_period.period.weekday]
if lesson_period.lesson.date_start <= day <= lesson_period.lesson.date_end:
documentations = list(
......
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