aboutsummaryrefslogtreecommitdiff
path: root/views.py
diff options
context:
space:
mode:
authorAlban Gruin2017-09-24 17:16:10 +0200
committerAlban Gruin2017-09-24 17:16:10 +0200
commite30b0c673cae607175c5bae6df6e87d8b100bdf3 (patch)
tree2ffc269ad5e56ff93e2ecd3bded5843a585c4fe7 /views.py
parent77748ec01d1ef59d8436597a9b52675b309e1c4d (diff)
Suppression du modèle LastUpdate, utilisation du champ last_update à
la place.
Diffstat (limited to 'views.py')
-rw-r--r--views.py12
1 files changed, 8 insertions, 4 deletions
diff --git a/views.py b/views.py
index 302b375..eb6a7ac 100644
--- a/views.py
+++ b/views.py
@@ -14,9 +14,11 @@
# along with celcatsanitizer. If not, see <http://www.gnu.org/licenses/>.
from django.conf import settings
+from django.db.models import Max
+from django.http import Http404
from django.shortcuts import get_object_or_404, render
-from .models import Timetable, LastUpdate, Group, Course, Year
+from .models import Timetable, Group, Course, Year
from .utils import get_current_week, get_week, group_courses
def index(request):
@@ -60,12 +62,14 @@ def timetable(request, year_slug, timetable_slug, group_slug, year=None, week=No
timetable = get_object_or_404(Timetable, year__slug=year_slug, slug=timetable_slug)
group = get_object_or_404(Group, slug=group_slug, timetable=timetable)
- last_update = get_object_or_404(LastUpdate, timetable=timetable, week=week, year=year)
- courses = Course.objects.get_courses_for_group(group, begin__gte=start, begin__lt=end)
+
+ courses = Course.objects.get_courses_for_group(group, begin__gte=start, begin__lt=end).annotate(Max("last_update"))
+ if courses.count == 0:
+ raise Http404
grouped_courses = group_courses(courses)
- return render(request, "timetable.html", {"group": group, "courses": grouped_courses, "last_update": last_update.date, "year": year, "week": int(week)})
+ return render(request, "timetable.html", {"group": group, "courses": grouped_courses, "last_update": courses.first().last_update__max, "year": year, "week": int(week)})
def contact(request):
return render(request, "contact.html", {"email": settings.ADMINS[0][1]})