diff options
author | Alban Gruin | 2017-09-06 11:46:37 +0200 |
---|---|---|
committer | Alban Gruin | 2017-09-06 11:46:37 +0200 |
commit | 36757e937abd7d5aa3434f4c815dfb040e1e3a71 (patch) | |
tree | 153e2ae1973fb576bf0c196bd90d1f43c1ebeced | |
parent | 493bbe8ac06a530ca02452da719258e2ad306c82 (diff) |
Simplification du code icalendar
-rw-r--r-- | feeds.py | 22 |
1 files changed, 10 insertions, 12 deletions
@@ -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())} |