aboutsummaryrefslogtreecommitdiff
path: root/feeds.py
diff options
context:
space:
mode:
Diffstat (limited to 'feeds.py')
-rw-r--r--feeds.py45
1 files changed, 38 insertions, 7 deletions
diff --git a/feeds.py b/feeds.py
index 4b42c47..609d422 100644
--- a/feeds.py
+++ b/feeds.py
@@ -14,19 +14,24 @@
# with celcatsanitizer; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+from django.core.exceptions import ObjectDoesNotExist
from django.contrib.syndication.views import Feed
from django.utils.feedgenerator import SyndicationFeed
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": "dtbegin",
+ "end": "dtend"}
+
class IcalFeedGenerator(SyndicationFeed):
content_type = "text/calendar; charset=utf-8"
- __ical_names = {"name": "summary",
- "notes": "description",
- "rooms": "location",
- "begin": "dtbegin",
- "end": "dtend"}
def write(self, outfile, encoding):
calendar = Calendar()
@@ -36,10 +41,36 @@ class IcalFeedGenerator(SyndicationFeed):
outfile.write(calendar.to_ical())
def write_events(self, calendar):
- print(self.items)
for item in self.items:
event = Event()
- for key, value in self.__ical_names.items():
+ for key, value in ICAL_NAMES.items():
if item.get(key) is not None:
event.add(value, item[key])
calendar.add_component(event)
+
+
+class IcalFeed(Feed):
+ feed_type = IcalFeedGenerator
+ link = ""
+
+ def get_object(self, request, timetable_slug, group_slug):
+ try:
+ timetable = Timetable.objects.get(slug=timetable_slug)
+ group = Group.objects.get(timetable=timetable, slug=group_slug)
+ except:
+ raise ObjectDoesNotExist
+ else:
+ return group
+
+ def item_link(self, item):
+ return ""
+
+ def items(self, obj):
+ 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())}