aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--feeds.py5
-rw-r--r--models.py21
-rw-r--r--templates/calendars.html13
-rw-r--r--templates/timetable.html2
-rw-r--r--urls.py2
-rw-r--r--views.py9
6 files changed, 42 insertions, 10 deletions
diff --git a/feeds.py b/feeds.py
index c2c5b14..66be12e 100644
--- a/feeds.py
+++ b/feeds.py
@@ -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()
diff --git a/models.py b/models.py
index 74fab9e..c546737 100644
--- a/models.py
+++ b/models.py
@@ -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> &ndash; <a href="{% url "rss" group.timetable.year.slug group.timetable.slug group.slug %}">RSS</a> &ndash; <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> &ndash; <a href="{% url "rss" group.timetable.year.slug group.timetable.slug group.slug %}">RSS</a> &ndash; <a href="{% url "atom" group.timetable.year.slug group.timetable.slug group.slug %}">Atom</a></p>{% endblock %}
diff --git a/urls.py b/urls.py
index 58cf019..c84ac75 100644
--- a/urls.py
+++ b/urls.py
@@ -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"),
diff --git a/views.py b/views.py
index 9c38524..7c19840 100644
--- a/views.py
+++ b/views.py
@@ -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]})