import json from django.shortcuts import render from django.conf import settings from .models import Event from ..page.models import Page def index(request, slug=''): context = {} context['settings'] = settings context['events'] = Event.objects.all().order_by('position') context['postscript'], c = Page.objects.get_or_create(slug='postscript') context['intro'], c = Page.objects.get_or_create(slug='intro') return render(request, 'index.html', context) def timeline(request): context = {} context['settings'] = settings context['postscript'], c = Page.objects.get_or_create(slug='postscript') context['intro'], c = Page.objects.get_or_create(slug='intro') timeline = {'events': []} for event in Event.objects.all().order_by('position'): if not event.date: continue date = event.date.split(' ') start = date[0].split('-') if len(date) > 1: end = date[1].split('-') else: end = start while len(end) < 3: end.append(1) while len(start) < 3: start.append(1) timeline['events'].append({ "start_date": { "year": start[0], "month": start[1], "day": start[2], "hour": "", "minute": "", "second": "", "millisecond": "", "format": "" }, "end_date": { "year": end[0], "month": end[1], "day": end[2], "hour": "", "minute": "", "second": "", "millisecond": "", "format": "" }, #"media": { # "caption": event.title, # "credit": "", #}, "text": { "headline": event.title, "text": event.body }, "unique_id": event.slug }) context['timeline_json'] = json.dumps(timeline) return render(request, 'timeline.html', context)