diff options
author | Alban Gruin | 2017-02-05 16:12:51 +0100 |
---|---|---|
committer | Alban Gruin | 2017-02-05 16:12:51 +0100 |
commit | 706983d73996637148d640281b5a5e97f217b9b5 (patch) | |
tree | 287ee3507aba1e30cfb96edb2b309c7bfee31681 /views.py | |
parent | 04162486502fee0fc6aa26aecd6919bde4cd3f73 (diff) |
Mise en commun de la fonction de récupération des semaines
Diffstat (limited to 'views.py')
-rw-r--r-- | views.py | 17 |
1 files changed, 7 insertions, 10 deletions
@@ -8,7 +8,7 @@ from django.template import Context, loader from edt.forms import SubscribeForm from edt.models import Timetable, LastUpdate, Group, Subscription, Course -from edt.utils import get_week, group_courses +from edt.utils import get_current_or_next_week, get_week, group_courses import datetime @@ -16,8 +16,8 @@ def index(request): timetables = Timetable.objects.all() groups = Group.objects.filter(tp__isnull=False).order_by("name") - current_year, current_week, _ = timezone.now().isocalendar() - start, _ = get_week(current_year, current_week) + year, week = get_current_or_next_week() + start, _ = get_week(year, week) groups_weeks = Course.objects.get_weeks(begin__gte=start).values("groups__timetable", "groups__mention", "groups__subgroup", "groups__td", "groups__tp", "year", "week") for group in groups: @@ -30,15 +30,14 @@ def index(request): if date not in group.weeks: group.weeks.append(date) - group.weeks.sort() + if hasattr(group, "weeks"): + group.weeks.sort() return render(request, "index.html", {"timetables": timetables, "groups": groups}) def timetable(request, timetable_slug, group_slug, year=None, week=None): if year is None or week is None: - year, week, day = timezone.now().isocalendar() - if day >= 6: - year, week, _ = (timezone.now() + datetime.timedelta(weeks=1)).isocalendar() + year, week = get_current_or_next_week() start, end = get_week(int(year), int(week)) @@ -79,9 +78,7 @@ def confirm_subscription(request, token): subscription.active = True subscription.save() - year, week, day = timezone.now().isocalendar() - if day >= 6: - year, week, _ = (timezone.now() + datetime.timedelta(weeks=1)).isocalendar() + year, week = get_current_or_next_week() return redirect("timetable", group_slug=subscription.group.slug, year=year, week=week) |