diff options
author | Alban Gruin | 2017-11-03 18:09:41 +0100 |
---|---|---|
committer | Alban Gruin | 2017-11-03 18:09:41 +0100 |
commit | 959bbaa5170aea4a9600d774280d44fc5107fdae (patch) | |
tree | aba0b535096b0ae6fa75ed243fb5374df8ed73fb | |
parent | 1edd7f6b2431095b27fd98205bb2ce5f462183e9 (diff) | |
parent | 5082e2aa0083a1c78cd39e86cb141786c2ab6efe (diff) |
Merge branch 'fusion/alban'
-rw-r--r-- | feeds.py | 5 | ||||
-rw-r--r-- | models.py | 21 | ||||
-rw-r--r-- | templates/calendars.html | 13 | ||||
-rw-r--r-- | templates/timetable.html | 2 | ||||
-rw-r--r-- | urls.py | 2 | ||||
-rw-r--r-- | views.py | 9 |
6 files changed, 42 insertions, 10 deletions
@@ -87,6 +87,11 @@ class IcalFeed(Feed): "location": format_rooms(item.rooms.all())} +class IcalOnlyOneFeed(IcalFeed): + def items(self, obj): + return Course.objects.filter(groups=obj).order_by("begin") + + class RSSFeed(Feed): def get_object(self, request, year_slug, timetable_slug, group_slug): year, week = get_current_or_next_week() @@ -70,11 +70,21 @@ class Timetable(SlugModel): class GroupManager(Manager): + def get_parents(self, group): + groups_criteria = Q(subgroup__isnull=True) | \ + reduce(lambda x, y: x | y, + [Q(subgroup=group.subgroup[:i]) + for i in range(1, len(group.subgroup) + 1)]) + + return self.get_queryset().filter(groups_criteria, mention=group.mention, + timetable=group.timetable) + def get_relevant_groups(self, timetable, *args, **criteria): sub = Group.objects.filter(timetable=timetable,mention=OuterRef("mention"), subgroup__startswith=OuterRef("subgroup")) \ .order_by().values("mention").annotate(c=Count("*")).values("c") - return Group.objects.filter(*args, timetable=timetable, hidden=False, **criteria) \ + + return self.get_queryset().filter(*args, timetable=timetable, hidden=False, **criteria) \ .annotate(nbsub=Subquery(sub, output_field=models.IntegerField())) \ .filter(nbsub=1).order_by("name") @@ -146,15 +156,8 @@ class Room(models.Model): class CourseManager(Manager): def get_courses_for_group(self, group, **criteria): - groups_criteria = reduce(lambda x, y: x | y, - [Q(groups__subgroup=group.subgroup[:i]) - for i in range(1, len(group.subgroup) + 1)]) | \ - Q(groups__subgroup__isnull=True) - return self.get_queryset() \ - .filter(groups_criteria, - groups__mention=group.mention, - timetable=group.timetable, **criteria) \ + .filter(groups__in=Group.objects.get_parents(group), **criteria) \ .order_by("begin") def get_weeks(self, **criteria): diff --git a/templates/calendars.html b/templates/calendars.html new file mode 100644 index 0000000..d97ea78 --- /dev/null +++ b/templates/calendars.html @@ -0,0 +1,13 @@ +{% extends "index.html" %} + +{% block title %}ICS disponibles pour le groupe {{ group }} – {% endblock %} + +{% 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> +{% 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> +{% endfor %} + </ul> +{% endblock %} diff --git a/templates/timetable.html b/templates/timetable.html index e4dffe7..fc2065f 100644 --- a/templates/timetable.html +++ b/templates/timetable.html @@ -18,4 +18,4 @@ {% 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" %} - <p class="subscribe"><a href="{% url "ics" 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>{% endblock %} + <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>{% endblock %} @@ -22,7 +22,9 @@ urlpatterns = [ 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<year_slug>[-\w]+)/(?P<timetable_slug>[-\w]+)/(?P<group_slug>[-\w]+)/$", views.timetable, name="timetable"), + url(r"^(?P<year_slug>[-\w]+)/(?P<timetable_slug>[-\w]+)/(?P<group_slug>[-\w]+)/calendars", views.calendars, name="calendars"), url(r"^(?P<year_slug>[-\w]+)/(?P<timetable_slug>[-\w]+)/(?P<group_slug>[-\w]+)/calendar.ics$", feeds.IcalFeed(), name="ics"), + url(r"^(?P<year_slug>[-\w]+)/(?P<timetable_slug>[-\w]+)/(?P<group_slug>[-\w]+)/calendar-group.ics$", feeds.IcalOnlyOneFeed(), name="ics-group"), url(r"^(?P<year_slug>[-\w]+)/(?P<timetable_slug>[-\w]+)/(?P<group_slug>[-\w]+)/feed.atom$", feeds.AtomFeed(), name="atom"), url(r"^(?P<year_slug>[-\w]+)/(?P<timetable_slug>[-\w]+)/(?P<group_slug>[-\w]+)/feed.rss$", feeds.RSSFeed(), name="rss"), url(r"^(?P<year_slug>[-\w]+)/(?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"), @@ -17,6 +17,7 @@ import datetime from django.conf import settings from django.db.models import Max +from django.db.models.functions import Length from django.http import Http404 from django.shortcuts import get_object_or_404, render @@ -95,5 +96,13 @@ def timetable(request, year_slug, timetable_slug, group_slug, year=None, week=No "year": year, "week": int(week), "is_old_timetable": is_old_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) + groups = Group.objects.get_parents(group).annotate(length=Length("subgroup")) \ + .order_by("length") + + return render(request, "calendars.html", {"group": group, "groups": groups}) + def contact(request): return render(request, "contact.html", {"email": settings.ADMINS[0][1]}) |