diff options
author | Alban Gruin | 2017-02-05 13:40:25 +0100 |
---|---|---|
committer | Alban Gruin | 2017-02-05 13:40:25 +0100 |
commit | 5363b70a7840f937f710e0a85fa83e48a35e083a (patch) | |
tree | 35371c3fc4b76a533293e97715faba87e4160fe5 | |
parent | 49eca350c06d9c3e2c45a1215e2d98acee0535c1 (diff) |
Ré-introduction du slug de l'emploi du temps dans les urls
-rw-r--r-- | models.py | 4 | ||||
-rw-r--r-- | templates/index.html | 2 | ||||
-rw-r--r-- | templates/timetable.html | 2 | ||||
-rw-r--r-- | urls.py | 6 | ||||
-rw-r--r-- | views.py | 14 |
5 files changed, 15 insertions, 13 deletions
@@ -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 { <section id="{{ timetable.slug }}"> <h3><a href="{{ timetable.url }}">{{ timetable.name }}</a></h3> <ul>{% for group in groups %}{% if group.timetable.id == timetable.id %} - <li><a class="text" href="{% url "timetable" group.slug %}">{{ group.name }}</a> – {% for week in group.weeks %}<a href="{% url "timetable" group.slug week.year week|dt_week %}">{{ week|dt_prettyprint }}</a> {% endfor %}</li>{% endif %}{% endfor %} + <li><a class="text" href="{% url "timetable" timetable.slug group.slug %}">{{ group.name }}</a> – {% for week in group.weeks %}<a href="{% url "timetable" timetable.slug group.slug week.year week|dt_week %}">{{ week|dt_prettyprint }}</a> {% endfor %}</li>{% endif %}{% endfor %} </ul> </section>{% endfor %}{% endblock %} </div> 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 @@ <li class="course"><b>{{ course.name }}</b>, de {{ course.begin|date:"H:i" }} à {{ course.end|date:"H:i" }}{% if course.rooms.all|length > 0 %}<br /><em>Salle{% if course.rooms.all|length > 1 %}s{% endif %} {% for room in course.rooms.all %}{{ room }} {% endfor %}</em>{% endif %}</li>{% endfor %} </ul> </section>{% endfor %} - <p><a class="subscribe" href="{% url "subscribe" group.slug year week %}">S'abonner à cet emploi du temps</a></p>{% endblock %} + <p><a class="subscribe" href="{% url "subscribe" group.timetable.slug group.slug year week %}">S'abonner à cet emploi du temps</a></p>{% endblock %} @@ -4,9 +4,9 @@ from . import views urlpatterns = [ url(r"^$", views.index, name="index"), - url(r"^(?P<group_slug>[-\w]+)/$", views.timetable, name="timetable"), - url(r"^(?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<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<timetable_slug>[-\w]+)/(?P<group_slug>[-\w]+)/$", 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])/$", 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"^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,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) |