aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--models.py4
-rw-r--r--templates/index.html2
-rw-r--r--templates/timetable.html2
-rw-r--r--urls.py6
-rw-r--r--views.py14
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 {
<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> &ndash; {% 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> &ndash; {% 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 %}
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<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"),
]
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)