aboutsummaryrefslogtreecommitdiff
path: root/views.py
diff options
context:
space:
mode:
Diffstat (limited to 'views.py')
-rw-r--r--views.py17
1 files changed, 7 insertions, 10 deletions
diff --git a/views.py b/views.py
index fca7e8e..9d441b8 100644
--- a/views.py
+++ b/views.py
@@ -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)