Commit 0a0b2f49 authored by Katia Saurfelt's avatar Katia Saurfelt
Browse files

[view] add colors on time events, other small fixes

parent 277c312a4726
......@@ -35,13 +35,17 @@ class SimileTimelineXMLView(EntityView):
content_type = 'application/xml'
date_fmt = '%Y'
colors = ['#58A0DC', '#097054', '#FFDE00', '#FF9900', '#660033', '#777B88', '#330033']
@timed
def call(self):
args = []
for entity in self.cw_rset.entities():
for i, entity in enumerate(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))
color = self.colors[i%len(self.colors)]
event_data = icalendarable.simpletimeline_data(date_fmt=self.date_fmt, color=color)
if event_data:
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)
......@@ -51,34 +55,43 @@ class SimpleTimelineMixIn(object):
""" helper class to be used in ICalendarable adaptators
"""
@timed
def simpletimeline_data(self, date_fmt='%Y-%m-%d %H:%M:%S'):
def simpletimeline_data(self, **kwargs):
"""converts `entity` into a XML object
<event start='1891' title='Portrait of Horace Brodsky'
description='by Henri Gaudier-Brzeska, French Sculptor, 1891-1915',
image='http://imagecache2.allposters.com/images/BRGPOD/102770_b.jpg',
link='http://www.allposters.com/-sp/Portrait-of-Horace-Brodsky-Posters_i1584413_.htm'>
</event>
# tileline label related data
# event_data['classname']
# event_data['textColor']
# timeline color
# event_data['color']
"""
date_fmt = kwargs['date_fmt']
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 ''
start = ustrftime(start, date_fmt)
start = start and ustrftime(start, date_fmt) or ''
if not start:
return {}
event_data = {'start':start,
'title':'%s (%s)' % (entity.dc_title(), start),
'link':entity.absolute_url(),
'description':entity.dc_description(format='text/html'),
'image': entity.depiction_url}
'title':'%s (%s)' % (entity.dc_title(), start),
'link':entity.absolute_url(),
'description':entity.dc_description(format='text/html'),
'image': entity.depiction_url,
}
if stop and start != stop:
event_data['end'] = ustrftime(stop, date_fmt)
event_data['isDuration'] = "true"
if 'color' in kwargs:
event_data['color'] = kwargs['color']
return event_data
class SimileTimeline(EntityView):
__regid__ = 'similetimeline'
__regid__ = 'ui.similetimeline'
__select__ = adaptable('ICalendarable')
paginable = False
needs_js = ('js/timeline-api.js?bundle=true',
......@@ -97,7 +110,7 @@ class SimileTimeline(EntityView):
def write_timeline(self):
self.w(self.html_template % self.options['id'])
def set_events_options(self, tltitle):
def set_events_options(self, tltitle, show_ticks=False):
rql = self.cw_rset.printable_rql()
events = []
for entity in self.cw_rset.entities():
......@@ -111,8 +124,8 @@ class SimileTimeline(EntityView):
else:
self.options['date'] = datetime.now()
self.options['url'] = self._cw.build_url('view', rql=rql, vid='similetimeline.xml',
tltitle=tltitle)
if events:
tltitle=tltitle)
if show_ticks and events:
events = sorted(set(events))
if len(events) > 10:
sorted_events = [events.pop(0), events.pop(-1)]
......@@ -125,8 +138,8 @@ class SimileTimeline(EntityView):
self.w(u'''<td><a href="javascript:centerTimeline(%(i)s);">%(i)s</a></td>''' % {'i':i})
self.w(u'''</tr></table></div>''')
def call(self, tltitle=u''):
def call(self, tltitle=u'', show_ticks=True):
self.init_options()
self.set_events_options(tltitle)
self.set_events_options(tltitle, show_ticks)
self.init_js()
self.write_timeline()
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