diff options
author | Alban Gruin | 2017-11-27 16:04:27 +0100 |
---|---|---|
committer | Alban Gruin | 2017-11-27 16:04:27 +0100 |
commit | e1c4eea3c706bb45cd73416e2e8626bd50a97cfb (patch) | |
tree | 7c750d87b4f5901e69b507cc7b693820efa85111 | |
parent | 703cec5da11e7b859ef0172f5cc656bd8040a846 (diff) |
Correction des interfaces utilisateur
-rw-r--r-- | feeds.py | 53 | ||||
-rw-r--r-- | templates/calendars.html | 4 | ||||
-rw-r--r-- | templates/timetable.html | 14 | ||||
-rw-r--r-- | views.py | 25 |
4 files changed, 44 insertions, 52 deletions
@@ -24,7 +24,7 @@ from django.utils.feedgenerator import Atom1Feed, SyndicationFeed from icalendar import Calendar, Event -from .models import Course, Group +from .models import Course, Group, Timetable from .templatetags.rooms import format_rooms from .utils import get_current_or_next_week, get_week, group_courses @@ -58,8 +58,9 @@ class IcalFeed(Feed): def get_object(self, request, year_slug, timetable_slug, group_slug): try: - group = Group.objects.get(timetable__year__slug=year_slug, - timetable__slug=timetable_slug, + timetable = Timetable.objects.get(year__slug=year_slug, + slug=timetable_slug) + group = Group.objects.get(timetable=timetable.source, slug=group_slug) except: raise ObjectDoesNotExist @@ -81,7 +82,7 @@ class IcalFeed(Feed): return item.name def items(self, obj): - return Course.objects.get_courses_for_group(obj) + return Course.objects.get_courses(obj) def item_extra_kwargs(self, item): return {"uid": "{0}@celcatsanitizer".format(item.id), @@ -103,39 +104,37 @@ class RSSFeed(Feed): _, end = get_week(year, week) try: - group = Group.objects.get(timetable__year__slug=year_slug, - timetable__slug=timetable_slug, - slug=group_slug) + self.timetable = Timetable.objects.get(year__slug=year_slug, + slug=timetable_slug) + self.group = Group.objects.get(timetable=self.timetable.source, + slug=group_slug) except: raise ObjectDoesNotExist else: - updates = Course.objects.get_courses_for_group(group, - begin__lt=end) \ + updates = Course.objects.get_courses(self.group, begin__lt=end) \ .annotate(year=ExtractYear("begin"), week=ExtractWeek("begin")) \ .values("year", "week") \ .annotate(Count("year", distinct=True), Max("last_update")) \ .order_by("-year", "-week")[:5] - return group, updates + return updates def link(self, obj): - group = obj[0] link = reverse("timetable", - kwargs={"year_slug": group.timetable.year.slug, - "timetable_slug": group.timetable.slug, - "group_slug": group.slug}) + kwargs={"year_slug": self.timetable.year.slug, + "timetable_slug": self.timetable.slug, + "group_slug": self.group.slug}) return link def title(self, obj): - return "Emploi du temps du groupe {0}".format(obj[0]) + return "Emploi du temps du groupe {0}".format(self.group) def item_link(self, item): - group = item["group"] return reverse("timetable", - kwargs={"year_slug": group.timetable.year.slug, - "timetable_slug": group.timetable.slug, - "group_slug": group.slug, + kwargs={"year_slug": self.timetable.year.slug, + "timetable_slug": self.timetable.slug, + "group_slug": self.group.slug, "year": item["year"], "week": item["week"]}) @@ -143,7 +142,7 @@ class RSSFeed(Feed): return item["description"] def item_title(self, item): - return "{0}, semaine {1} de {2}".format(item["group"], + return "{0}, semaine {1} de {2}".format(self.group, item["week"], item["year"]) @@ -152,23 +151,19 @@ class RSSFeed(Feed): def items(self, obj): template = loader.get_template("timetable_common.html") - group = obj[0] - for update in obj[1]: + for update in obj: start, end = get_week(update["year"], update["week"]) - courses = Course.objects.get_courses_for_group(group, - begin__gte=start, - begin__lt=end) - context = {"group": group, - "courses": group_courses(courses), + courses = Course.objects.get_courses(self.group, begin__gte=start, + begin__lt=end) + context = {"courses": group_courses(courses), "last_update": update["last_update__max"], "year": update["year"], "week": update["week"]} - update["group"] = group update["description"] = template.render(context) - return obj[1] + return obj class AtomFeed(RSSFeed): diff --git a/templates/calendars.html b/templates/calendars.html index d97ea78..52c3a11 100644 --- a/templates/calendars.html +++ b/templates/calendars.html @@ -5,9 +5,9 @@ {% block body %} <h2>ICS disponibles pour le groupe {{ group }}</h2> <ul> - <li><a href="{% url "ics" group.timetable.year.slug group.timetable.slug group.slug %}">Un seul ICS pour tous les cours</a></li> + <li><a href="{% url "ics" timetable.year.slug timetable.slug group.slug %}">Un seul ICS pour tous les cours</a></li> {% for group in groups %} - <li><a href="{% url "ics-group" group.timetable.year.slug group.timetable.slug group.slug %}">ICS des cours du groupe {{ group }} uniquement</a></li> + <li><a href="{% url "ics-group" timetable.year.slug timetable.slug group.slug %}">ICS des cours du groupe {{ group }} uniquement</a></li> {% endfor %} </ul> {% endblock %} diff --git a/templates/timetable.html b/templates/timetable.html index 4c921fd..8fafeed 100644 --- a/templates/timetable.html +++ b/templates/timetable.html @@ -2,20 +2,20 @@ {% block head %}{% if group_mode %} <meta name="description" content="Emploi du temps du groupe {{ group }} – Semaine {{ week }}" /> - <link rel="alternate" type="application/atom+xml" title="Emploi du temps du groupe {{ group }} (Atom)" href="{% url "atom" group.timetable.year.slug group.timetable.slug group.slug %}" /> - <link rel="alternate" type="application/rss+xml" title="Emploi du temps du groupe {{ group }} (RSS)" href="{% url "rss" group.timetable.year.slug group.timetable.slug group.slug %}" /> - <link rel="alternate" type="text/calendar" title="Emploi du temps du groupe {{ group }} (iCalendar)" href="{% url "ics" group.timetable.year.slug group.timetable.slug group.slug %}"> + <link rel="alternate" type="application/atom+xml" title="Emploi du temps du groupe {{ group }} (Atom)" href="{% url "atom" timetable.year.slug timetable.slug group.slug %}" /> + <link rel="alternate" type="application/rss+xml" title="Emploi du temps du groupe {{ group }} (RSS)" href="{% url "rss" timetable.year.slug timetable.slug group.slug %}" /> + <link rel="alternate" type="text/calendar" title="Emploi du temps du groupe {{ group }} (iCalendar)" href="{% url "ics" timetable.year.slug timetable.slug group.slug %}"> {% endif %}{% endblock %} -{% block title %}{% if group_mode %}{{ group.timetable }} –{% else %}Salle{% endif %} {{ group }} – Semaine {{ week }} – {% endblock %} +{% block title %}{% if group_mode %}{{ timetable }} –{% else %}Salle{% endif %} {{ group }} – Semaine {{ week }} – {% endblock %} {% block body %} - <h2>{% if group_mode %}{{ group.timetable }} –{% else %}Salle{% endif %} {{ group }} – Semaine {{ week }}</h2> + <h2>{% if group_mode %}{{ timetable }} –{% else %}Salle{% endif %} {{ group }} – Semaine {{ week }}</h2> <p> {% if is_old_timetable %} - <b><a href="{% if group_mode %}{% url "timetable" group.timetable.year.slug group.timetable.slug group.slug %}{% else %}{% url "room-timetable" group.slug %}{% endif %}">Accéder à l’emploi du temps de cette semaine.</b></a><br /> + <b><a href="{% if group_mode %}{% url "timetable" timetable.year.slug timetable.slug group.slug %}{% else %}{% url "room-timetable" group.slug %}{% endif %}">Accéder à l’emploi du temps de cette semaine.</b></a><br /> {% endif %} {% if last_update %}Dernière mise à jour le {{ last_update|date:"l j F o" }} à {{ last_update|date:"H:i" }}{% endif %} </p> {% include "timetable_common.html" %} - {% if group_mode %}<p class="subscribe"><a href="{% url "calendars" group.timetable.year.slug group.timetable.slug group.slug %}">ICS</a> – <a href="{% url "rss" group.timetable.year.slug group.timetable.slug group.slug %}">RSS</a> – <a href="{% url "atom" group.timetable.year.slug group.timetable.slug group.slug %}">Atom</a></p>{% endif %}{% endblock %} + {% if group_mode %}<p class="subscribe"><a href="{% url "calendars" timetable.year.slug timetable.slug group.slug %}">ICS</a> – <a href="{% url "rss" timetable.year.slug timetable.slug group.slug %}">RSS</a> – <a href="{% url "atom" timetable.year.slug timetable.slug group.slug %}">Atom</a></p>{% endif %}{% endblock %} @@ -37,7 +37,7 @@ def mention_list(request, year_slug): def group_list(request, year_slug, timetable_slug): timetable = get_object_or_404(Timetable, year__slug=year_slug, slug=timetable_slug) - groups = Group.objects.filter(timetable=timetable, hidden=False).order_by("name") + groups = Group.objects.filter(timetable=timetable.source, hidden=False).order_by("name") start, _ = get_week(*get_current_week()) end = start + datetime.timedelta(weeks=4) @@ -61,7 +61,7 @@ def group_list(request, year_slug, timetable_slug): return render(request, "group_list.html", {"timetable": timetable, "groups": groups}) -def timetable_common(request, obj, year=None, week=None): +def timetable_common(request, obj, year=None, week=None, timetable=None): current_year, current_week = get_current_or_next_week() is_old_timetable, provided_week = False, True @@ -84,27 +84,24 @@ def timetable_common(request, obj, year=None, week=None): "last_update": last_update, "year": year, "week": int(week), "is_old_timetable": is_old_timetable, - "group_mode": isinstance(obj, Group)}) + "group_mode": isinstance(obj, Group), + "timetable": timetable}) def timetable(request, year_slug, timetable_slug, group_slug, year=None, week=None): timetable = get_object_or_404(Timetable, year__slug=year_slug, slug=timetable_slug) - group = get_object_or_404(Group, slug=group_slug, timetable=timetable) + group = get_object_or_404(Group, slug=group_slug, timetable=timetable.source) - if Group.objects.filter(timetable=timetable, mention=group.mention, - subgroup__startswith=group.subgroup).count() > 1: - subgroups = Group.objects.get_relevant_groups(timetable, mention=group.mention, - subgroup__startswith=group.subgroup) - return group_list_common(request, timetable, subgroups) - - return timetable_common(request, group, year, week) + return timetable_common(request, group, year, week, timetable) def calendars(request, year_slug, timetable_slug, group_slug): - group = get_object_or_404(Group, timetable__year__slug=year_slug, - timetable__slug=timetable_slug, slug=group_slug) + timetable = get_object_or_404(Timetable, year__slug=year_slug, + slug=timetable_slug) + group = get_object_or_404(Group, timetable=timetable.source, slug=group_slug) groups = Group.objects.get_parents(group).annotate(length=Length("subgroup")) \ .order_by("length") - return render(request, "calendars.html", {"group": group, "groups": groups}) + return render(request, "calendars.html", {"timetable": timetable, + "group": group, "groups": groups}) def rooms(request): # On récupère les dates allant de cette semaine à dans un mois |