event-timeline/app/event/views.py

72 lines
2.1 KiB
Python
Raw Normal View History

2021-11-12 18:21:51 +00:00
import json
2021-11-12 16:49:35 +00:00
from django.shortcuts import render
2021-11-12 16:58:31 +00:00
from django.conf import settings
2021-11-12 16:49:35 +00:00
from .models import Event
from ..page.models import Page
def index(request, slug=''):
context = {}
2021-11-12 16:58:31 +00:00
context['settings'] = settings
2021-11-12 16:49:35 +00:00
context['events'] = Event.objects.all().order_by('position')
2021-11-12 18:03:19 +00:00
context['postscript'], c = Page.objects.get_or_create(slug='postscript')
context['intro'], c = Page.objects.get_or_create(slug='intro')
2021-11-12 16:49:35 +00:00
return render(request, 'index.html', context)
2021-11-12 18:21:51 +00:00
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:
2021-11-12 18:22:49 +00:00
start.append(1)
2021-11-12 18:21:51 +00:00
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)