diff options
author | Alban Gruin | 2017-09-08 11:53:49 +0200 |
---|---|---|
committer | Alban Gruin | 2017-09-08 11:53:49 +0200 |
commit | 57ffdbf0658042069abcf0b1f9184ff69a3139e2 (patch) | |
tree | 85ab2f0cf55fc85dec62b065b7eb246b7de46e4c | |
parent | 0a287c2013bcfd1cb71926fbd0835170369521f7 (diff) |
Ajout de l’année dans les urls
-rw-r--r-- | feeds.py | 7 | ||||
-rw-r--r-- | templates/group_list.html | 2 | ||||
-rw-r--r-- | templates/subscribe.html | 2 | ||||
-rw-r--r-- | templates/timetable.html | 2 | ||||
-rw-r--r-- | urls.py | 8 | ||||
-rw-r--r-- | views.py | 14 |
6 files changed, 19 insertions, 16 deletions
@@ -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 @@ <h3><a href="{{ timetable.url }}">{{ timetable }}</a></h3> <ul> {% for group in groups %} - <li><a class="text"{% if group.weeks is not None %} href="{% url "timetable" timetable.slug group.slug %}"{% endif %}>{{ group }}</a> – {% for week in group.weeks %}<a href="{% url "timetable" timetable.slug group.slug week.year week|dt_week %}">{{ week|dt_prettyprint }}</a> {% empty %}<em>aucun cours</em>{% endfor %}</li> + <li><a class="text"{% if group.weeks is not None %} href="{% url "timetable" timetable.year.slug timetable.slug group.slug %}"{% endif %}>{{ group }}</a> – {% for week in group.weeks %}<a href="{% url "timetable" timetable.year.slug timetable.slug group.slug week.year week|dt_week %}">{{ week|dt_prettyprint }}</a> {% empty %}<em>aucun cours</em>{% endfor %}</li> {% endfor %} </ul> {% 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 %} <h2>S'abonner à {{ group.timetable.name }} – {{ group.name }}</h2> - <form action="{% url "subscribe" group.timetable.slug group.slug year week %}" method="post"> + <form action="{% url "subscribe" group.timetable.year.slug group.timetable.slug group.slug year week %}" method="post"> {% csrf_token %} {{ form }} <input type="submit" value="S'abonner" /> 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 @@ </li>{% endfor %} </ul> </section>{% endfor %} - <p><a class="subscribe" href="{% url "subscribe" group.timetable.slug group.slug year week %}">S’abonner à cet emploi du temps</a></p>{% endblock %} + <p><a class="subscribe" href="{% url "subscribe" group.timetable.year.slug group.timetable.slug group.slug year week %}">S’abonner à cet emploi du temps</a></p>{% endblock %} @@ -20,10 +20,10 @@ urlpatterns = [ url(r"^$", views.index, name="index"), url(r"^(?P<year_slug>[-\w]+)/$", views.mention_list, name="mentions"), url(r"^(?P<year_slug>[-\w]+)/(?P<timetable_slug>[-\w]+)/$", views.group_list, name="groups"), - url(r"^(?P<timetable_slug>[-\w]+)/(?P<group_slug>[-\w]+)/$", views.timetable, name="timetable"), - url(r"^(?P<timetable_slug>[-\w]+)/(?P<group_slug>[-\w]+)/calendar.ics$", feeds.IcalFeed(), name="ics"), - url(r"^(?P<timetable_slug>[-\w]+)/(?P<group_slug>[-\w]+)/(?P<year>[0-9]{4})/(?P<week>[0-4]?[0-9]|5[0-3])/$", views.timetable, name="timetable"), - url(r"^(?P<timetable_slug>[-\w]+)/(?P<group_slug>[-\w]+)/(?P<year>[0-9]{4})/(?P<week>[0-4]?[0-9]|5[0-3])/subscribe$", views.subscribe, name="subscribe"), + url(r"^(?P<year_slug>[-\w]+)/(?P<timetable_slug>[-\w]+)/(?P<group_slug>[-\w]+)/$", views.timetable, name="timetable"), + url(r"^(?P<year_slug>[-\w]+)/(?P<timetable_slug>[-\w]+)/(?P<group_slug>[-\w]+)/calendar.ics$", feeds.IcalFeed(), name="ics"), + url(r"^(?P<year_slug>[-\w]+)/(?P<timetable_slug>[-\w]+)/(?P<group_slug>[-\w]+)/(?P<year>[0-9]{4})/(?P<week>[0-4]?[0-9]|5[0-3])/$", views.timetable, name="timetable"), + url(r"^(?P<year_slug>[-\w]+)/(?P<timetable_slug>[-\w]+)/(?P<group_slug>[-\w]+)/(?P<year>[0-9]{4})/(?P<week>[0-4]?[0-9]|5[0-3])/subscribe$", views.subscribe, name="subscribe"), url(r"^subscriptions/confirm/(?P<token>[0-9a-f]{40})$", views.confirm_subscription, name="confirm"), url(r"^subscriptions/cancel/(?P<token>[0-9a-f]{40})$", views.cancel_subscription, name="cancel"), ] @@ -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() |