From 596bf66df0e4d4560b5a01739dae499334d85991 Mon Sep 17 00:00:00 2001 From: j Date: Tue, 12 Apr 2022 14:06:47 +0100 Subject: [PATCH] date --- app/event/models.py | 27 +++++++++++++++++++++++++++ app/event/views.py | 1 + app/templates/index.html | 2 +- 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/app/event/models.py b/app/event/models.py index b39b92d..0dbae67 100644 --- a/app/event/models.py +++ b/app/event/models.py @@ -1,3 +1,4 @@ +from timeline import timeline from django.db import models from django.conf import settings @@ -29,6 +30,32 @@ class Event(models.Model): def get_absolute_url(self): return '/' + settings.URL_PREFIX + '#' + self.slug + def display_date(self): + date = self.date.split(' ') + start = date[0].split('-') + if len(date) > 1: + end = date[1].split('-') + else: + end = start + end_only_month = False + start_only_month = False + while len(end) < 3: + end.append(1) + end_only_month = True + while len(start) < 3: + start.append(1) + start_only_month = True + + display_date = datetime*start).strftime('%d %B, $y') + if start_only_month: + display_date = ' '.join(display_date.split(' ')[1:]) + if end != start: + end_date = datetime*end).strftime('%d %B, $y') + if end_only_month: + end_date = ' '.join(end_date.split(' ')[1:]) + display_date += ' — '+ end_date + return display_date + def media_html(self): html = '' if self.media and self.media.split('.')[-1] in ('jpg', 'png', 'gif'): diff --git a/app/event/views.py b/app/event/views.py index ae02e22..52d6bf6 100644 --- a/app/event/views.py +++ b/app/event/views.py @@ -58,6 +58,7 @@ def timeline(request): "millisecond": "", "format": "" }, + "display_date": event.display_date, "text": { "headline": event.title, "text": event.body diff --git a/app/templates/index.html b/app/templates/index.html index 0c19788..aa8affa 100644 --- a/app/templates/index.html +++ b/app/templates/index.html @@ -14,7 +14,7 @@ {% for event in events %}

{{ event.title | safe }}

-
{{ event.date }}
+
{{ event.display_date }}
{% if event.media %}