From 5363b70a7840f937f710e0a85fa83e48a35e083a Mon Sep 17 00:00:00 2001 From: Alban Gruin Date: Sun, 5 Feb 2017 13:40:25 +0100 Subject: Ré-introduction du slug de l'emploi du temps dans les urls --- models.py | 4 ++-- templates/index.html | 2 +- templates/timetable.html | 2 +- urls.py | 6 +++--- views.py | 14 ++++++++------ 5 files changed, 15 insertions(+), 13 deletions(-) diff --git a/models.py b/models.py index ff4897b..2f130a3 100644 --- a/models.py +++ b/models.py @@ -51,7 +51,7 @@ class Group(models.Model): td = models.IntegerField(verbose_name="groupe de TD", null=True) tp = models.IntegerField(verbose_name="groupe de TP", null=True) - slug = models.SlugField(max_length=64, unique=True, default="") + slug = models.SlugField(max_length=64, default="") def corresponds_to(self, timetable_id, mention, subgroup, td, tp): return self.timetable.id == timetable_id and self.mention == mention and self.subgroup == subgroup and (self.td == td or self.td is None or td is None) and (self.tp == tp or self.tp is None or tp is None) @@ -83,7 +83,7 @@ class Group(models.Model): class Meta: index_together = ("mention", "subgroup", "td", "tp",) - unique_together = (("name", "timetable",), ("celcat_name", "timetable",),) + unique_together = (("name", "timetable",), ("celcat_name", "timetable",), ("slug", "timetable",),) verbose_name = "groupe" verbose_name_plural = "groupes" diff --git a/templates/index.html b/templates/index.html index a89ab68..9e454e3 100644 --- a/templates/index.html +++ b/templates/index.html @@ -61,7 +61,7 @@ li.course {

{{ timetable.name }}

{% endfor %}{% endblock %} diff --git a/templates/timetable.html b/templates/timetable.html index 882e163..c4d83b0 100644 --- a/templates/timetable.html +++ b/templates/timetable.html @@ -11,4 +11,4 @@
  • {{ course.name }}, de {{ course.begin|date:"H:i" }} à {{ course.end|date:"H:i" }}{% if course.rooms.all|length > 0 %}
    Salle{% if course.rooms.all|length > 1 %}s{% endif %} {% for room in course.rooms.all %}{{ room }} {% endfor %}{% endif %}
  • {% endfor %} {% endfor %} -

    S'abonner à cet emploi du temps

    {% endblock %} +

    S'abonner à cet emploi du temps

    {% endblock %} diff --git a/urls.py b/urls.py index 6bb488a..7fb75f5 100644 --- a/urls.py +++ b/urls.py @@ -4,9 +4,9 @@ from . import views urlpatterns = [ url(r"^$", views.index, name="index"), - url(r"^(?P[-\w]+)/$", views.timetable, name="timetable"), - url(r"^(?P[-\w]+)/(?P[0-9]{4})/(?P[0-4]?[0-9]|5[0-3])/$", views.timetable, name="timetable"), - url(r"^(?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]+)/$", views.timetable, name="timetable"), + 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"^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 6204d9f..9f38032 100644 --- a/views.py +++ b/views.py @@ -34,7 +34,7 @@ def index(request): return render(request, "index.html", {"timetables": timetables, "groups": groups}) -def timetable(request, group_slug, year=None, week=None): +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: @@ -42,16 +42,18 @@ def timetable(request, group_slug, year=None, week=None): start, end = get_week(int(year), int(week)) - group = get_object_or_404(Group, slug=group_slug) - courses = Course.objects.get_courses_for_group(group, begin__gte=start, begin__lt=end) - last_update = LastUpdate.objects.get(timetable=group.timetable, week=week, year=year) + timetable = get_object_or_404(Timetable, slug=timetable_slug) + group = get_object_or_404(Group, slug=group_slug, timetable=timetable) + courses = Course.objects.get_courses_for_group(group, timetable=timetable, begin__gte=start, begin__lt=end) + last_update = LastUpdate.objects.get(timetable=timetable, week=week, year=year) 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)}) -def subscribe(request, group_slug, year, week): - group = get_object_or_404(Group, slug=group_slug) +def subscribe(request, timetable_slug, group_slug, year, week): + timetable = get_object_or_404(Timetable, slug=timetable_slug) + group = get_object_or_404(Group, slug=group_slug, timetable=timetable) if request.method == "POST": form = SubscribeForm(request.POST) -- cgit v1.2.1