def build_timeline(events):
    ''' helper function for item page timelines '''
    timeline = {}
    timeline_min = 0
    timeline_max = 0
    if events:
        try:
            dates = [int(e['props']['date']) for e in events]
        except ValueError:
            logging.error('Failed to parse event dates')
        else:
            events_start = min(dates)
            events_end = max(dates)

            offset = 10  # +/- some number of years
            timeline_min = (events_start - offset) / 100 * 100
            timeline_max = (events_end + offset) / 100 * 100

            for event in events:
                note = event['note'] if 'note' in event else None
                timeline = helpers.add_to_timeline(
                    timeline, event,
                    event['props']['date'],
                    event['props']['date_precision'],
                    note=note,
                    allow_events=True)
    return timeline, timeline_min, timeline_max
Beispiel #2
0
def timeline_page():
    ''' timeline data display
    :return: rendered timeline page
    '''

    nodes = graph.timeline()['nodes']
    if not graph.timeline_labels:
        graph.timeline_labels = set([n['label'] for n in nodes])

    show = [l for l in graph.timeline_labels
            if l in request.args and request.values[l] == 'on']

    if show:
        nodes = [n for n in nodes if n['label'] in show]
    else:
        show = graph.timeline_labels

    timeline = {}
    for node in nodes:
        for event in date_params:
            if event not in node['props']:
                continue
            try:
                year = int(node['props'][event])
            except ValueError:
                continue

            date_precision = node['props'].get('date_precision', 'year')

            note = event if event not in ['year', 'date'] else None
            timeline = helpers.add_to_timeline(timeline, node, year,
                                               date_precision, note=note)

    end = date.today().year
    return render_template(request.url, 'timeline.html', data=timeline, end=end,
                           labels=graph.timeline_labels, show=show)