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

Implement personal notes editing in lesson.

parent 5980f94d
No related branches found
No related tags found
No related merge requests found
from django import forms
from django.utils.translation import ugettext_lazy as _
from .models import LessonDocumentation
from .models import LessonDocumentation, PersonalNote
class LessonDocumentationForm(forms.ModelForm):
class Meta:
model = LessonDocumentation
fields = ['topic', 'homework']
PersonalNoteFormSet = forms.modelformset_factory(
PersonalNote, fields=('person', 'absent', 'late', 'excused', 'remarks'))
......@@ -5,7 +5,7 @@ from biscuit.core.mixins import SchoolRelated
class PersonalNote(SchoolRelated):
person = models.ForeignKey('core.Person', models.CASCADE)
person = models.ForeignKey('core.Person', models.CASCADE, editable=False)
week = models.IntegerField()
lesson_period = models.ForeignKey('chronos.LessonPeriod', models.CASCADE)
......
......@@ -39,9 +39,30 @@
{% blocktrans %}Personal notes{% endblocktrans %}
</div>
<div class="card-body">
<p class="card-text">
This feature is still missing.
</p>
<form method="post">
{% csrf_token %}
<table class="table table-striped table-bordered table-hover table-condensed table-responsive w-100">
<tr>
<th>{% blocktrans %}Person{% endblocktrans %}</th>
<th>{% blocktrans %}Absent{% endblocktrans %}</th>
<th>{% blocktrans %}Tardiness{% endblocktrans %}</th>
<th>{% blocktrans %}Excused{% endblocktrans %}</th>
<th>{% blocktrans %}Remarks{% endblocktrans %}</th>
</tr>
{% for form in personal_note_formset %}
<tr>
<td>{{ form.person }}</td>
<td>{{ form.absent }}</td>
<td>{{ form.late }}</td>
<td>{{ form.excused }}</td>
<td>{{ form.remarks }}</td>
</tr>
{% endfor %}
</table>
<input type="hidden" name="action" value="personal_notes" />
<input type="submit" value="Update" />
</form>
</div>
</div>
{% endblock %}
......
......@@ -9,7 +9,7 @@ from biscuit.apps.chronos.models import LessonPeriod
from biscuit.apps.chronos.util import current_lesson_periods, current_week
from .forms import LessonDocumentationForm
from .models import LessonDocumentation
from .models import LessonDocumentation, PersonalNote
@login_required
......@@ -34,12 +34,27 @@ def lesson(request: HttpRequest, week: Optional[int] = None, period_id: Optional
lesson_documentation, created = LessonDocumentation.objects.get_or_create(lesson_period=lesson_period, week=wanted_week)
lesson_documentation_form = LessonDocumentationForm(request.POST or None, instance=lesson_documentation)
# Create all missing personal notes about members of all groups in lesson
for group in lesson_period.lesson.groups:
for person in group.members:
note, created = PersonalNote.objects.get_or_create(person=person, lesson_period=lesson_period,
week=wanted_week)
# Create a formset that holds all personal notes for all persons in this lesson
persons_qs = PersonalNote.objects.filter(lesson_period=lesson_period, week=wanted_week)
personal_note_formset = PersonalNoteFormSet(request.POST or None, queryset=persons_qs)
if request.method == 'POST':
if request.POST.get('action', None) == 'lesson_documentation':
# Save the lesson documentation
if lesson_documentation_form.is_valid():
lesson_documentation_form.save()
elif request.POST.get('action', None) == 'personal_notes':
# Save all personal notes
if personal_note_formset.is_valid():
lesson_documentation_form.save()
context['lesson_documentation_form'] = lesson_documentation_form
context['personal_note_formset'] = personal_note_formset
return render(request, 'alsijil/lesson.html', context)
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