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': []}
|
2022-03-18 18:36:06 +00:00
|
|
|
|
2021-11-12 18:21:51 +00:00
|
|
|
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": ""
|
|
|
|
},
|
2022-04-12 13:06:47 +00:00
|
|
|
"display_date": event.display_date,
|
2021-11-12 18:21:51 +00:00
|
|
|
"text": {
|
|
|
|
"headline": event.title,
|
|
|
|
"text": event.body
|
|
|
|
},
|
2022-03-18 18:39:57 +00:00
|
|
|
"group": event.type.lower().strip(),
|
2022-03-18 18:36:06 +00:00
|
|
|
"unique_id": event.slug,
|
2021-11-12 18:21:51 +00:00
|
|
|
})
|
2021-11-19 14:26:58 +00:00
|
|
|
if event.media:
|
2021-11-19 14:22:59 +00:00
|
|
|
timeline['events'][-1]['media'] = {
|
2021-11-19 14:26:58 +00:00
|
|
|
"url": event.media,
|
|
|
|
"caption": event.media_caption,
|
2021-11-19 14:22:59 +00:00
|
|
|
}
|
2021-11-12 18:21:51 +00:00
|
|
|
context['timeline_json'] = json.dumps(timeline)
|
|
|
|
return render(request, 'timeline.html', context)
|