Skip to content
Snippets Groups Projects
Verified Commit c36b5d8e authored by Tom Teichler's avatar Tom Teichler :beers:
Browse files

Turn group week view into general week view. Closes #34.

parent 28a358fa
No related branches found
No related tags found
1 merge request!16Turn group week view into general week view.
......@@ -2,7 +2,8 @@ from django import forms
from django.db.models import Count
from django.utils.translation import ugettext_lazy as _
from biscuit.core.models import Group
from biscuit.core.models import Group, Person
from biscuit.apps.chronos.models import Room
from .models import LessonDocumentation, PersonalNote
......@@ -33,6 +34,14 @@ class SelectForm(forms.Form):
group = forms.ModelChoiceField(
queryset=Group.objects.annotate(lessons_count=Count('lessons')).filter(lessons_count__gt=0),
label=_('Group'), required=False)
teacher = forms.ModelChoiceField(
queryset=Person.objects.annotate(lessons_count=Count(
'lessons')).filter(lessons_count__gt=0),
label=_('Teacher'), required=False)
room = forms.ModelChoiceField(
queryset=Room.objects.annotate(lessons_count=Count(
'lesson_periods')).filter(lessons_count__gt=0),
label=_('Room'), required=False)
PersonalNoteFormSet = forms.modelformset_factory(
......
......@@ -22,7 +22,7 @@
{% endif %}
</div>
{% if group %}
{% if group or teacher or room %}
<div class="row">
<div class="col-md-7">
<div class="card">
......
......@@ -11,7 +11,7 @@ from django.urls import reverse
from django.utils.translation import ugettext as _
from django.views.decorators.cache import cache_page
from biscuit.apps.chronos.models import LessonPeriod, TimePeriod
from biscuit.apps.chronos.models import LessonPeriod, TimePeriod, Room
from biscuit.apps.chronos.util import CalendarWeek, current_lesson_periods
from biscuit.core.models import Group, Person
......@@ -98,18 +98,7 @@ def group_week(request: HttpRequest, year: Optional[int] = None, week: Optional[
else:
wanted_week = CalendarWeek()
if request.GET.get('group', None):
# Use requested group
group = Group.objects.get(pk=request.GET['group'])
elif hasattr(request, 'user') and hasattr(request.user, 'person'):
# Try to select group from owned groups of user
group = request.user.person.owner_of.first()
else:
group = None
if group:
# Get all lesson periods for the selected group
lesson_periods = LessonPeriod.objects.annotate(
lesson_periods = LessonPeriod.objects.annotate(
has_documentation=Exists(LessonDocumentation.objects.filter(
~Q(topic__exact=''),
lesson_period=OuterRef('pk'),
......@@ -124,9 +113,26 @@ def group_week(request: HttpRequest, year: Optional[int] = None, week: Optional[
'lesson__groups', 'lesson__teachers', 'substitutions'
).extra(
select={'_week': wanted_week.week}
).filter(
Q(lesson__groups=group) | Q(lesson__groups__parent_groups=group)
).distinct()
)
teacher = None
group = None
room = None
if request.GET.get('group', None) or request.GET.get('teacher', None) or request.GET.get('room', None):
# Incrementally filter lesson periods by GET parameters
if 'group' in request.GET and request.GET['group']:
group = Group.objects.get(pk=request.GET['group'])
lesson_periods = lesson_periods.filter(
Q(lesson__groups__pk=int(request.GET['group'])) | Q(lesson__groups__parent_groups__pk=int(request.GET['group'])))
if 'teacher' in request.GET and request.GET['teacher']:
teacher = Person.objects.get(pk=request.GET['teacher'])
lesson_periods = lesson_periods.filter(
Q(substitutions__teachers__pk=int(request.GET['teacher']), substitutions__week=wanted_week.week) | Q(lesson__teachers__pk=int(request.GET['teacher'])))
if 'room' in request.GET and request.GET['room']:
room = Room.objects.get(pk=request.GET['room'])
lesson_periods = lesson_periods.filter(
room__pk=int(request.GET['room']))
# Aggregate all personal notes for this group and week
persons = Person.objects.filter(
......@@ -164,6 +170,8 @@ def group_week(request: HttpRequest, year: Optional[int] = None, week: Optional[
context['current_head'] = str(wanted_week)
context['week'] = wanted_week
context['group'] = group
context['teacher'] = teacher
context['room'] = room
context['lesson_periods'] = lesson_periods
context['persons'] = persons
context['select_form'] = select_form
......
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