From 57ffdbf0658042069abcf0b1f9184ff69a3139e2 Mon Sep 17 00:00:00 2001 From: Alban Gruin Date: Fri, 8 Sep 2017 11:53:49 +0200 Subject: Ajout de l’année dans les urls --- feeds.py | 7 ++++--- templates/group_list.html | 2 +- templates/subscribe.html | 2 +- templates/timetable.html | 2 +- urls.py | 8 ++++---- views.py | 14 ++++++++------ 6 files changed, 19 insertions(+), 16 deletions(-) diff --git a/feeds.py b/feeds.py index ca1c843..e2b0b3f 100644 --- a/feeds.py +++ b/feeds.py @@ -19,7 +19,7 @@ from django.utils.feedgenerator import SyndicationFeed from icalendar import Calendar, Event -from .models import Course, Group, Timetable +from .models import Course, Group, Timetable, Year from .templatetags.rooms import format_rooms ICAL_NAMES = ["summary", "description", "location", "start", "dtstart", "dtend"] @@ -48,9 +48,10 @@ class IcalFeed(Feed): feed_type = IcalFeedGenerator link = "" - def get_object(self, request, timetable_slug, group_slug): + def get_object(self, request, year_slug, timetable_slug, group_slug): try: - timetable = Timetable.objects.get(slug=timetable_slug) + year = Year.objects.get(slug=year_slug) + timetable = Timetable.objects.get(year=year, slug=timetable_slug) group = Group.objects.get(timetable=timetable, slug=group_slug) except: raise ObjectDoesNotExist diff --git a/templates/group_list.html b/templates/group_list.html index d8d7227..2530865 100644 --- a/templates/group_list.html +++ b/templates/group_list.html @@ -5,7 +5,7 @@

{{ timetable }}

{% endblock %} diff --git a/templates/subscribe.html b/templates/subscribe.html index 1c1bc3a..5e885df 100644 --- a/templates/subscribe.html +++ b/templates/subscribe.html @@ -4,7 +4,7 @@ {% block body %}

S'abonner à {{ group.timetable.name }} – {{ group.name }}

-
+ {% csrf_token %} {{ form }} diff --git a/templates/timetable.html b/templates/timetable.html index 149068d..a867fd0 100644 --- a/templates/timetable.html +++ b/templates/timetable.html @@ -16,4 +16,4 @@ {% endfor %} {% endfor %} -

{% endblock %} +

{% endblock %} diff --git a/urls.py b/urls.py index 725a46d..2df41f4 100644 --- a/urls.py +++ b/urls.py @@ -20,10 +20,10 @@ urlpatterns = [ url(r"^$", views.index, name="index"), url(r"^(?P[-\w]+)/$", views.mention_list, name="mentions"), url(r"^(?P[-\w]+)/(?P[-\w]+)/$", views.group_list, name="groups"), - url(r"^(?P[-\w]+)/(?P[-\w]+)/$", views.timetable, name="timetable"), - url(r"^(?P[-\w]+)/(?P[-\w]+)/calendar.ics$", feeds.IcalFeed(), name="ics"), - url(r"^(?P[-\w]+)/(?P[-\w]+)/(?P[0-9]{4})/(?P[0-4]?[0-9]|5[0-3])/$", views.timetable, name="timetable"), - url(r"^(?P[-\w]+)/(?P[-\w]+)/(?P[0-9]{4})/(?P[0-4]?[0-9]|5[0-3])/subscribe$", views.subscribe, name="subscribe"), + url(r"^(?P[-\w]+)/(?P[-\w]+)/(?P[-\w]+)/$", views.timetable, name="timetable"), + url(r"^(?P[-\w]+)/(?P[-\w]+)/(?P[-\w]+)/calendar.ics$", feeds.IcalFeed(), name="ics"), + url(r"^(?P[-\w]+)/(?P[-\w]+)/(?P[-\w]+)/(?P[0-9]{4})/(?P[0-4]?[0-9]|5[0-3])/$", views.timetable, name="timetable"), + url(r"^(?P[-\w]+)/(?P[-\w]+)/(?P[-\w]+)/(?P[0-9]{4})/(?P[0-4]?[0-9]|5[0-3])/subscribe$", views.subscribe, name="subscribe"), url(r"^subscriptions/confirm/(?P[0-9a-f]{40})$", views.confirm_subscription, name="confirm"), url(r"^subscriptions/cancel/(?P[0-9a-f]{40})$", views.cancel_subscription, name="cancel"), ] diff --git a/views.py b/views.py index 31a89f5..f48509d 100644 --- a/views.py +++ b/views.py @@ -34,8 +34,8 @@ def mention_list(request, year_slug): return render(request, "mention_list.html", {"year": year, "timetables": timetables}) def group_list(request, year_slug, timetable_slug): - get_object_or_404(Year, slug=year_slug) - timetable = get_object_or_404(Timetable, slug=timetable_slug) + year_obj = get_object_or_404(Year, slug=year_slug) + timetable = get_object_or_404(Timetable, year=year_obj, slug=timetable_slug) groups = Group.objects.get_relevant_groups(timetable=timetable).order_by("name") year, week = get_current_week() @@ -57,12 +57,13 @@ def group_list(request, year_slug, timetable_slug): return render(request, "group_list.html", {"timetable": timetable, "groups": groups}) -def timetable(request, timetable_slug, group_slug, year=None, week=None): +def timetable(request, year_slug, timetable_slug, group_slug, year=None, week=None): if year is None or week is None: year, week = get_current_week() start, end = get_week(int(year), int(week)) + get_object_or_404(Year, slug=year_slug) timetable = get_object_or_404(Timetable, 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) @@ -72,8 +73,9 @@ def timetable(request, timetable_slug, group_slug, year=None, week=None): return render(request, "timetable.html", {"group": group, "courses": grouped_courses, "last_update": last_update.date, "year": year, "week": int(week)}) -def subscribe(request, timetable_slug, group_slug, year, week): - timetable = get_object_or_404(Timetable, slug=timetable_slug) +def subscribe(request, year_slug, timetable_slug, group_slug, year, week): + year_obj = get_object_or_404(Year, slug=year_slug) + timetable = get_object_or_404(Timetable, year=year_obj, slug=timetable_slug) group = get_object_or_404(Group, slug=group_slug, timetable=timetable) if request.method == "POST": @@ -87,7 +89,7 @@ def subscribe(request, timetable_slug, group_slug, year, week): context = Context({"group": group, "admins": settings.ADMINS, "token": subscription.token, "domain": settings.DEFAULT_DOMAIN}) send_mail("Confirmation de l’abonnemenent", template.render(context), settings.DEFAULT_FROM_EMAIL, [request.POST["email"]]) - return redirect("timetable", timetable_slug=timetable_slug, group_slug=group_slug, year=year, week=int(week)) + return redirect("timetable", year_slug=year_slug, timetable_slug=timetable_slug, group_slug=group_slug, year=year, week=int(week)) else: form = SubscribeForm() -- cgit v1.2.1