From 36757e937abd7d5aa3434f4c815dfb040e1e3a71 Mon Sep 17 00:00:00 2001 From: Alban Gruin Date: Wed, 6 Sep 2017 11:46:37 +0200 Subject: Simplification du code icalendar --- feeds.py | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/feeds.py b/feeds.py index e97c29a..72d7873 100644 --- a/feeds.py +++ b/feeds.py @@ -23,11 +23,7 @@ from icalendar import Calendar, Event from .models import Course, Group, Timetable from .templatetags.rooms import format_rooms -ICAL_NAMES = {"name": "summary", - "notes": "description", - "rooms": "location", - "begin": "dtstart", - "end": "dtend"} +ICAL_NAMES = ["summary", "description", "location", "start", "dtstart", "dtend"] class IcalFeedGenerator(SyndicationFeed): @@ -43,9 +39,9 @@ class IcalFeedGenerator(SyndicationFeed): def write_events(self, calendar): for item in self.items: event = Event() - for key, value in ICAL_NAMES.items(): + for key in ICAL_NAMES: if item.get(key) is not None: - event.add(value, item[key]) + event.add(key, item[key]) calendar.add_component(event) @@ -62,6 +58,9 @@ class IcalFeed(Feed): else: return group + def item_description(self, item): + return item.notes + def item_link(self, item): return "" @@ -69,8 +68,7 @@ class IcalFeed(Feed): return Course.objects.get_courses_for_group(obj).order_by("begin") def item_extra_kwargs(self, item): - return {"begin": item.begin, - "end": item.end, - "name": item.name, - "notes": item.notes, - "rooms": format_rooms(item.rooms.all())} + return {"dtstart": item.begin, + "dtend": item.end, + "summary": item.name, + "location": format_rooms(item.rooms.all())} -- cgit v1.2.1