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

Sort lessons in week view. Advances #8.

parent b01a0efc
No related branches found
No related tags found
No related merge requests found
from collections import OrderedDict
from typing import Optional from typing import Optional
from django.contrib.auth.decorators import login_required from django.contrib.auth.decorators import login_required
...@@ -6,7 +7,7 @@ from django.http import HttpRequest, HttpResponse ...@@ -6,7 +7,7 @@ from django.http import HttpRequest, HttpResponse
from django.shortcuts import render from django.shortcuts import render
from django.utils.translation import ugettext as _ from django.utils.translation import ugettext as _
from biscuit.apps.chronos.models import Lesson, LessonPeriod from biscuit.apps.chronos.models import Lesson, LessonPeriod, TimePeriod
from biscuit.apps.chronos.util import current_lesson_periods, current_week, week_days from biscuit.apps.chronos.util import current_lesson_periods, current_week, week_days
from biscuit.core.models import Group from biscuit.core.models import Group
...@@ -77,12 +78,16 @@ def group_week(request: HttpRequest, week: Optional[int] = None) -> HttpResponse ...@@ -77,12 +78,16 @@ def group_week(request: HttpRequest, week: Optional[int] = None) -> HttpResponse
else: else:
group = None group = None
periods_by_day = {} periods_by_day_unsorted = {}
if group: if group:
for lesson in group.lessons.filter(date_start__lte=week_start, date_end__gte=week_end): for lesson in group.lessons.filter(date_start__lte=week_start, date_end__gte=week_end):
for lesson_period in lesson.lesson_periods.all(): for lesson_period in lesson.lesson_periods.all():
periods_by_day.setdefault( periods_by_day_unsorted.setdefault(
lesson_period.period.get_weekday_display(), []).append(lesson_period) lesson_period.period.weekday, []).append(lesson_period)
periods_by_day = OrderedDict()
for weekday, periods in sorted(periods_by_day_unsorted.items()):
periods_by_day[dict(TimePeriod.WEEKDAY_CHOICES)[weekday]] = sorted(periods, key=lambda p: p.period.period)
context['week'] = wanted_week context['week'] = wanted_week
context['group'] = group context['group'] = group
......
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