diff options
Diffstat (limited to 'feeds.py')
-rw-r--r-- | feeds.py | 24 |
1 files changed, 22 insertions, 2 deletions
@@ -16,6 +16,7 @@ from django.core.exceptions import ObjectDoesNotExist from django.contrib.syndication.views import Feed from django.db.models import Q +from django.template import Context, loader from django.urls import reverse from django.utils.feedgenerator import Atom1Feed, SyndicationFeed @@ -23,7 +24,7 @@ from icalendar import Calendar, Event from .models import Course, Group, LastUpdate, Timetable, Year from .templatetags.rooms import format_rooms -from .utils import get_current_or_next_week +from .utils import get_current_or_next_week, get_week, group_courses ICAL_NAMES = ["summary", "description", "location", "start", "dtstart", "dtend"] @@ -93,5 +94,24 @@ class AtomFeed(Feed): link = reverse("timetable", kwargs={"year_slug": group.timetable.year.slug, "timetable_slug": group.timetable.slug, "group_slug": group.slug}) return link + def title(self, obj): + return "Emploi du temps du groupe {0}".format(obj[0]) + + 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, "year": item.year, "week": item.week}) + + def item_description(self, item): + template = loader.get_template("timetable.html") + context = {"group": item.group, "courses": item.courses, "last_update": item, "year": item.year, "week": item.week} + return template.render(context) + def items(self, obj): - return [] + for update in obj[1]: + start, end = get_week(update.year, update.week) + courses = Course.objects.get_courses_for_group(obj[0], begin__gte=start, begin__lt=end) + + update.group = obj[0] + update.courses = group_courses(courses) + + return obj[1] |