diff options
-rw-r--r-- | models.py | 2 | ||||
-rw-r--r-- | templates/group_list.html | 16 | ||||
-rw-r--r-- | templates/index.html | 4 | ||||
-rw-r--r-- | templates/mention_list.html | 4 | ||||
-rw-r--r-- | urls.py | 4 | ||||
-rw-r--r-- | views.py | 17 |
6 files changed, 26 insertions, 21 deletions
@@ -45,7 +45,7 @@ class Timetable(models.Model): slug = models.SlugField(max_length=64, unique=True, default="") def __str__(self): - return self.name + return self.year.name + " " + self.name class Meta: diff --git a/templates/group_list.html b/templates/group_list.html index d4c3579..d8d7227 100644 --- a/templates/group_list.html +++ b/templates/group_list.html @@ -1,9 +1,11 @@ {% extends "index.html" %} +{% load dt_week %} -{% block body %}{% for timetable in timetables %} - <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"{% if group.weeks is not None %} href="{% url "timetable" timetable.slug group.slug %}"{% endif %}>{{ 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> {% empty %}<em>aucun cours</em>{% endfor %}</li>{% endif %}{% endfor %} - </ul> - </section>{% endfor %}{% endblock %} +{% block body %} + <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> + {% endfor %} + </ul> +{% endblock %} diff --git a/templates/index.html b/templates/index.html index 09bb0f6..e33f92a 100644 --- a/templates/index.html +++ b/templates/index.html @@ -1,4 +1,4 @@ -{% load dt_week %}<!DOCTYPE html> +<!DOCTYPE html> <html lang="fr"> <head> <meta charset="utf-8" /> @@ -63,7 +63,7 @@ li.course { <h3>Choisissez votre année</h3> <ul> {% for year in years %} - <li><a href="{% url "mentions" year.year %}">{{ year.year }}</a> <small>({{ year.count }})</small></li> + <li><a href="{% url "mentions" year.slug %}">{{ year }}</a></li> {% empty %} <p><em>Aucun emploi du temps à afficher</em></p> {% endfor %} diff --git a/templates/mention_list.html b/templates/mention_list.html index 142a17a..71cfaac 100644 --- a/templates/mention_list.html +++ b/templates/mention_list.html @@ -3,10 +3,10 @@ {% block title %}{{ year }} – {% endblock %} {% block body %} - <h3>Choisissez votre mention</h3> + <h3>{{ year }} – Choisissez votre mention</h3> <ul> {% for timetable in timetables %} - <li><a href="{% url "groups" year timetable.slug %}">{{ timetable.name }}</a></li> + <li><a href="{% url "groups" year.slug timetable.slug %}">{{ timetable }}</a></li> {% empty %} <p>Aucun emploi du temps à afficher</p> {% endfor %} @@ -19,8 +19,8 @@ from . import feeds, views urlpatterns = [ url(r"^$", views.index, name="index"), - url(r"^(?P<year>[-\w]+)/$", views.mention_list, name="mentions"), - url(r"^(?P<year>[-\w]+)/(?P<timetable_slug>[-\w]+)/$", views.group_list, name="groups"), + 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"), @@ -21,24 +21,27 @@ from django.template import Context, loader from django.db.models import Count from .forms import SubscribeForm -from .models import Timetable, LastUpdate, Group, Subscription, Course +from .models import Timetable, LastUpdate, Group, Subscription, Course, Year from .utils import get_current_week, get_week, group_courses def index(request): - years = Timetable.objects.order_by("year").values("year").annotate(count=Count("year")) + years = Year.objects.order_by("name") return render(request, "index.html", {"years": years}) -def mention_list(request, year): +def mention_list(request, year_slug): + year = get_object_or_404(Year, slug=year_slug) timetables = Timetable.objects.order_by("name").filter(year=year) + return render(request, "mention_list.html", {"year": year, "timetables": timetables}) -def group_list(request, year, timetable_slug): +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) - groups = Group.objects.get_relevant_groups(timetable=timetable).order_by("name") + groups = Group.objects.get_relevant_groups().order_by("name") year, week = get_current_week() start, _ = get_week(year, week) - groups_weeks = Course.objects.get_weeks(begin__gte=start).values("groups__timetable", "groups__mention", "groups__subgroup", "groups__td", "groups__tp", "year", "week") + groups_weeks = Course.objects.get_weeks(begin__gte=start).values("group__timetable", "groups__mention", "groups__subgroup", "groups__td", "groups__tp", "year", "week") for group in groups: for group_week in groups_weeks: @@ -53,7 +56,7 @@ def group_list(request, year, timetable_slug): if hasattr(group, "weeks"): group.weeks.sort() - return render(request, "group_list.html", {"timetables": timetables, "groups": groups}) + return render(request, "group_list.html", {"timetable": timetable, "groups": groups}) def timetable(request, timetable_slug, group_slug, year=None, week=None): if year is None or week is None: |