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

refactoring

parent 041c52ba7595
......@@ -19,6 +19,7 @@
from datetime import datetime
from logilab.common.date 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'
@timed
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":"http://simile.mit.edu/shelf/",
"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(E.data(*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
"""
@timed
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):
link='http://www.allposters.com/-sp/Portrait-of-Horace-Brodsky-Posters_i1584413_.htm'>
</event>
"""
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),
'title':entity.dc_title(),
start = ustrftime(start, date_fmt)
event_data = {'start':start,
'title':'%s (%s)' % (entity.dc_title(), start),
'link':entity.absolute_url(),
'description':entity.dc_description(format='text/html'),
'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