Commit a0ed7e44 authored by Katia Saurfelt's avatar Katia Saurfelt
Browse files


parent 041c52ba7595
......@@ -19,6 +19,7 @@
from datetime import datetime
from import ustrftime
from logilab.common.decorators import timed
from cubicweb.view import EntityView
from cubicweb.selectors import adaptable
......@@ -34,17 +35,23 @@ class SimileTimelineXMLView(EntityView):
content_type = 'application/xml'
date_fmt = '%Y'
def call(self):
args = (self.build_event(entity, E) for entity in self.cw_rset.entities())
args = []
for entity in self.cw_rset.entities():
icalendarable = entity.cw_adapt_to('ICalendarable')
event_data = icalendarable.simpletimeline_data(date_fmt=self.date_fmt)
args.append(E.event(event_data.pop('description'), **event_data))
kwargs = {"wiki-url":"",
"wiki-section":"Simile %s" % self._cw.form.get('tltitle', u'')}
self.w(u'<?xml version="1.0" encoding="%s"?>\n' % self._cw.encoding)
return self.w(etree.tostring(*args, **kwargs)) + u'\n')
def image_url_info(self, entity):
return entity.depiction_url
def build_event(self, entity, ex):
class SimpleTimelineMixIn(object):
""" helper class to be used in ICalendarable adaptators
def simpletimeline_data(self, date_fmt='%Y-%m-%d %H:%M:%S'):
"""converts `entity` into a XML object
<event start='1891' title='Portrait of Horace Brodsky'
description='by Henri Gaudier-Brzeska, French Sculptor, 1891-1915',
......@@ -52,21 +59,23 @@ class SimileTimelineXMLView(EntityView):
entity = self.entity
icalendarable = entity.cw_adapt_to('ICalendarable')
start = icalendarable.start
stop = icalendarable.stop
start = start and start or stop
if start is None:
return ''
kwargs = {'start':ustrftime(start, self.date_fmt),
start = ustrftime(start, date_fmt)
event_data = {'start':start,
'title':'%s (%s)' % (entity.dc_title(), start),
'image': self.image_url_info(entity)}
'image': entity.depiction_url}
if stop and start != stop:
kwargs['end'] = ustrftime(stop, self.date_fmt)
kwargs['isDuration'] = "true"
return ex.event(entity.dc_title, **kwargs)
event_data['end'] = ustrftime(stop, date_fmt)
event_data['isDuration'] = "true"
return event_data
class SimileTimeline(EntityView):
__regid__ = 'similetimeline'
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment