aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlban Gruin2017-01-22 20:00:52 +0100
committerAlban Gruin2017-01-22 20:00:52 +0100
commit22faec68b77a48681df12036713f44f9d8df7bfd (patch)
treed0f88c28f5eabfd11b166a17e2ea0ed853eb3ffa
parent245b978ee20a7091cb2924bc14ae36f4d0460477 (diff)
Regroupement des cours effectué à l'aide d'une fonction pour éviter la duplication de code
-rw-r--r--utils.py10
-rw-r--r--views.py9
2 files changed, 12 insertions, 7 deletions
diff --git a/utils.py b/utils.py
index 5cc6648..3479b47 100644
--- a/utils.py
+++ b/utils.py
@@ -8,3 +8,13 @@ def get_week(year, week):
end = start + datetime.timedelta(weeks=1)
return start, end
+
+def group_courses(courses):
+ grouped_courses = []
+ for i, course in enumerate(courses):
+ if i == 0 or courses[i - 1].begin.day != course.begin.day:
+ grouped_courses.append([course])
+ else:
+ grouped_courses[-1].append(course)
+
+ return grouped_courses
diff --git a/views.py b/views.py
index c106668..28c8746 100644
--- a/views.py
+++ b/views.py
@@ -5,7 +5,7 @@ from django.utils import timezone
from edt.forms import SubscribeForm
from edt.models import Timetable, LastUpdate, Group, Subscription, Course
-from edt.utils import get_week
+from edt.utils import get_week, group_courses
import datetime
@@ -34,12 +34,7 @@ def timetable(request, timetable_slug, year, week, group_slug):
courses = Course.objects.get_courses_for_group(group, begin__gte=start, begin__lt=end)
last_update = LastUpdate.objects.get(timetable=timetable, week=week, year=year)
- grouped_courses = []
- for i, course in enumerate(courses):
- if i == 0 or courses[i - 1].begin.day != course.begin.day:
- grouped_courses.append([course])
- else:
- grouped_courses[-1].append(course)
+ grouped_courses = group_courses(courses)
return render(request, "timetable.html", {"timetable": timetable, "group": group, "courses": grouped_courses, "last_update": last_update.date, "year": year, "week": week})