diff options
author | Alban Gruin | 2018-04-23 16:20:38 +0200 |
---|---|---|
committer | Alban Gruin | 2018-04-23 16:20:38 +0200 |
commit | 63ceb7ff232cd4015ae148bec31c6d72d9239c19 (patch) | |
tree | 9aee056480b5fae0c97f5e1c8be4ab1358602926 /feeds.py | |
parent | af055dbf703af0eca03862194de1a0f34ac1fcc5 (diff) | |
parent | 9853d375d9e482c23f5fdbed9a3cf041029a92cb (diff) |
Merge branch 'qsjps' into futur
Diffstat (limited to 'feeds.py')
-rw-r--r-- | feeds.py | 65 |
1 files changed, 35 insertions, 30 deletions
@@ -21,10 +21,11 @@ from django.db.models.functions import ExtractWeek, ExtractYear from django.template import loader from django.urls import reverse from django.utils.feedgenerator import Atom1Feed, SyndicationFeed +from django.utils.timezone import get_current_timezone_name 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 @@ -39,6 +40,11 @@ class IcalFeedGenerator(SyndicationFeed): calendar = Calendar() calendar.add("prodid", "-//celcatsanitizer//NONSGML v1.0//EN") calendar.add("version", "2.0") + calendar.add("calscale", "GREGORIAN") + calendar.add("method", "PUBLISH") + calendar.add("x-wr-timezone", get_current_timezone_name()) + calendar.add("x-wr-calname", self.feed["title"]) + calendar.add("x-wr-caldesc", self.feed["title"]) self.write_events(calendar) outfile.write(calendar.to_ical()) @@ -58,8 +64,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(source=timetable.source, slug=group_slug) except: raise ObjectDoesNotExist @@ -81,7 +88,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), @@ -91,6 +98,9 @@ class IcalFeed(Feed): "summary": self.item_summary(item), "location": format_rooms(item.rooms.all())} + def title(self, obj): + return "Emploi du temps du groupe {0}".format(obj) + class IcalOnlyOneFeed(IcalFeed): def items(self, obj): @@ -103,39 +113,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(source=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 +151,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 +160,20 @@ 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"]} + "week": update["week"], + "group_mode": True} - update["group"] = group update["description"] = template.render(context) - return obj[1] + return obj class AtomFeed(RSSFeed): |