From eb050fb7d00351bcac8048f75abd703e68783831 Mon Sep 17 00:00:00 2001 From: Alban Gruin Date: Sat, 9 Sep 2017 11:19:02 +0200 Subject: Rendu du contenu du flux atom. Il est loin d’être parfait par contre. --- feeds.py | 24 ++++++++++++++++++++++-- models.py | 2 +- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/feeds.py b/feeds.py index aa68934..1f6ff66 100644 --- a/feeds.py +++ b/feeds.py @@ -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] diff --git a/models.py b/models.py index 7609e7b..8fbd1da 100644 --- a/models.py +++ b/models.py @@ -62,7 +62,7 @@ class LastUpdate(models.Model): updated_at = models.DateTimeField(verbose_name="date de publication", null=True) def __str__(self): - return "{0}, semaine {1} de {2}".format(self.timetable.name, self.week, self.year) + return "{0}, semaine {1} de {2}".format(self.timetable, self.week, self.year) class Meta: -- cgit v1.2.1