[PATCH 1 of 1 calendar] [ical] Make TimeperiodICalendarAdapter inherite from ICalendarableAdapter

Simon Chabot simon.chabot at logilab.fr
Mon Mar 2 09:21:01 CET 2020


# HG changeset patch
# User Simon Chabot <simon.chabot at logilab.fr>
# Date 1583069744 -3600
#      Sun Mar 01 14:35:44 2020 +0100
# Node ID d8184d21213a8d28bc294337c39c80a3f0dd9a05
# Parent  148f7bcd325ef2b8a94d71f24c7e9e6826288a00
# Available At https://hg.logilab.org/review/cubes/calendar/
#              hg pull https://hg.logilab.org/review/cubes/calendar/ -r d8184d21213a
[ical] Make TimeperiodICalendarAdapter inherite from ICalendarableAdapter

Inheriting from ICalendarableAdapter make sure that all the attributes needed
for the adaptation are properly set up.

The regid is now provided by the parent class, therefore, there is not need to
repeat it.

In particular, this patch fixes the rendering of the Timeperiod's ical view
where the attribut `component` (see [0] line 53) is needed (see [0] line 88) and
was not specified.

A simple test is added. It asserts that the ical view works without any issue
(the same test fails before this patch). The 'vobject' module is added to
dev-requirements list, because it's needed to generate the 'ical' view.

[0]: https://hg.logilab.org/review/cubicweb/file/84937ac5060f/cubicweb/web/views/calendar.py

diff -r 148f7bcd325e -r d8184d21213a cubicweb_calendar/views/__init__.py
--- a/cubicweb_calendar/views/__init__.py	Thu Oct 03 16:50:07 2019 +0200
+++ b/cubicweb_calendar/views/__init__.py	Sun Mar 01 14:35:44 2020 +0100
@@ -6,10 +6,9 @@
 from logilab.common.date import todate, last_day
 
 from cubicweb import target
-from cubicweb.view import EntityAdapter
 from cubicweb.predicates import is_instance
 from cubicweb.web import action
-from cubicweb.web.views import uicfg, ibreadcrumbs
+from cubicweb.web.views import uicfg, ibreadcrumbs, calendar
 
 from cubicweb import _
 
@@ -85,9 +84,9 @@
                                   __redirectpath='/', holidays=1)
 
 
-class TimeperiodICalendarable(EntityAdapter):
-    __regid__ = 'ICalendarable'
+class TimeperiodICalendarable(calendar.ICalendarableAdapter):
     __select__ = is_instance('Timeperiod')
+
     @property
     def start(self):
         return self.entity.start
diff -r 148f7bcd325e -r d8184d21213a dev-requirements.txt
--- a/dev-requirements.txt	Thu Oct 03 16:50:07 2019 +0200
+++ b/dev-requirements.txt	Sun Mar 01 14:35:44 2020 +0100
@@ -1,1 +1,2 @@
 pytest
+vobject
diff -r 148f7bcd325e -r d8184d21213a test/unittest_calendar.py
--- a/test/unittest_calendar.py	Thu Oct 03 16:50:07 2019 +0200
+++ b/test/unittest_calendar.py	Sun Mar 01 14:35:44 2020 +0100
@@ -102,5 +102,28 @@
             self.assertEqual([W, W, NW, W, NW, NW, NW], dtypes)
 
 
+class CalendarTemplatableTC(CubicWebTC):
+    def test_timeperiod_to_ical(self):
+        with self.admin_access.repo_cnx() as cnx:
+            day_type = cnx.execute(
+                "Any X WHERE X is Daytype, X type %(t)s",
+                {"t": W}
+            ).one()
+            cal = cnx.find("Calendar", title=u"Calendrier Francais").one()
+            timeperiod = cnx.create_entity(
+                "Timeperiod",
+                start=datetime(2020, 3, 2, 8, 00),
+                stop=datetime(2020, 3, 2, 18, 30),
+                day_type=day_type,
+                reverse_periods=cal,
+            )
+            cnx.commit()
+        with self.admin_access.web_request(vid="ical", eid=timeperiod.eid) as req:
+            data = self.ctrl_publish(req, "view").decode("utf-8")
+            self.assertTrue(data.startswith("BEGIN:VCALENDAR"))
+            self.assertIn("START:20200302T080000", data)
+            self.assertIn("END:20200302T183000", data)
+
+
 if __name__ == '__main__':
     unittest.main()



More information about the cubicweb-devel mailing list