makes vobject optional tls-sprint
authorsylvain.thenault@logilab.fr
Mon, 04 May 2009 13:31:04 +0200
branchtls-sprint
changeset 1644 45bec81a9e1c
parent 1643 59c5cec05bbd
child 1645 374586978230
makes vobject optional
web/views/calendar.py
--- a/web/views/calendar.py	Mon May 04 13:30:47 2009 +0200
+++ b/web/views/calendar.py	Mon May 04 13:31:04 2009 +0200
@@ -7,8 +7,6 @@
 
 from datetime import datetime, date, timedelta
 
-from vobject import iCalendar
-
 from logilab.mtconverter import html_escape
 
 from cubicweb.interfaces import ICalendarable
@@ -32,35 +30,40 @@
 
 # Calendar views ##############################################################
 
+try:
+    from vobject import iCalendar
 
-class iCalView(EntityView):
-    """A calendar view that generates a iCalendar file (RFC 2445)
+    class iCalView(EntityView):
+        """A calendar view that generates a iCalendar file (RFC 2445)
 
-    Does apply to ICalendarable compatible entities
-    """
-    __select__ = implements(ICalendarable)
-    need_navigation = False
-    content_type = 'text/calendar'
-    title = _('iCalendar')
-    templatable = False
-    id = 'ical'
+        Does apply to ICalendarable compatible entities
+        """
+        __select__ = implements(ICalendarable)
+        need_navigation = False
+        content_type = 'text/calendar'
+        title = _('iCalendar')
+        templatable = False
+        id = 'ical'
 
-    def call(self):
-        ical = iCalendar()
-        for i in range(len(self.rset.rows)):
-            task = self.complete_entity(i)
-            event = ical.add('vevent')
-            event.add('summary').value = task.dc_title()
-            event.add('description').value = task.dc_description()
-            if task.start:
-                event.add('dtstart').value = task.start
-            if task.stop:
-                event.add('dtend').value = task.stop
+        def call(self):
+            ical = iCalendar()
+            for i in range(len(self.rset.rows)):
+                task = self.complete_entity(i)
+                event = ical.add('vevent')
+                event.add('summary').value = task.dc_title()
+                event.add('description').value = task.dc_description()
+                if task.start:
+                    event.add('dtstart').value = task.start
+                if task.stop:
+                    event.add('dtend').value = task.stop
 
-        buff = ical.serialize()
-        if not isinstance(buff, unicode):
-            buff = unicode(buff, self.req.encoding)
-        self.w(buff)
+            buff = ical.serialize()
+            if not isinstance(buff, unicode):
+                buff = unicode(buff, self.req.encoding)
+            self.w(buff)
+
+except ImportError:
+    pass
 
 class hCalView(EntityView):
     """A calendar view that generates a hCalendar file