diff options
author | Alban Gruin | 2017-09-08 21:30:21 +0200 |
---|---|---|
committer | Alban Gruin | 2017-09-08 21:30:21 +0200 |
commit | 74a51992dc6c91d939e8d89eb35a8646b1a67f27 (patch) | |
tree | 5b821f4f04d9d8daddd1aea0783fe46862f0ce8d /feeds.py | |
parent | 62e7f87c1f867e3ac4f2750e9d422c67788e65a9 (diff) |
Récupération des mises à jours à afficher dans le flux Atom. Il s’agit des 5 dernières mises à jour d’un emploi du temps
Diffstat (limited to 'feeds.py')
-rw-r--r-- | feeds.py | 23 |
1 files changed, 21 insertions, 2 deletions
@@ -15,12 +15,14 @@ from django.core.exceptions import ObjectDoesNotExist from django.contrib.syndication.views import Feed -from django.utils.feedgenerator import SyndicationFeed +from django.db.models import Q +from django.utils.feedgenerator import Atom1Feed, SyndicationFeed from icalendar import Calendar, Event -from .models import Course, Group, Timetable, Year +from .models import Course, Group, LastUpdate, Timetable, Year from .templatetags.rooms import format_rooms +from .utils import get_current_or_next_week ICAL_NAMES = ["summary", "description", "location", "start", "dtstart", "dtend"] @@ -70,3 +72,20 @@ class IcalFeed(Feed): "dtend": item.end, "summary": item.name, "location": format_rooms(item.rooms.all())} + + +class AtomFeed(Feed): + feed_type = Atom1Feed + + def get_object(self, request, year_slug, timetable_slug, group_slug): + year, week = get_current_or_next_week() + try: + group = Group.objects.get(timetable__year__slug=year_slug, timetable__slug=timetable_slug, slug=group_slug) + updates = LastUpdate.objects.filter(Q(year=year, week__lte=week) | Q(year__lt=year), timetable__year__slug=year_slug, timetable__slug=timetable_slug).order_by("-year", "-week")[:5] + except: + raise ObjectDoesNotExist + else: + return group, updates + + def items(self, obj): + pass |