date
This commit is contained in:
parent
864c43987a
commit
596bf66df0
3 changed files with 29 additions and 1 deletions
|
@ -1,3 +1,4 @@
|
||||||
|
from timeline import timeline
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
|
||||||
|
@ -29,6 +30,32 @@ class Event(models.Model):
|
||||||
def get_absolute_url(self):
|
def get_absolute_url(self):
|
||||||
return '/' + settings.URL_PREFIX + '#' + self.slug
|
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):
|
def media_html(self):
|
||||||
html = ''
|
html = ''
|
||||||
if self.media and self.media.split('.')[-1] in ('jpg', 'png', 'gif'):
|
if self.media and self.media.split('.')[-1] in ('jpg', 'png', 'gif'):
|
||||||
|
|
|
@ -58,6 +58,7 @@ def timeline(request):
|
||||||
"millisecond": "",
|
"millisecond": "",
|
||||||
"format": ""
|
"format": ""
|
||||||
},
|
},
|
||||||
|
"display_date": event.display_date,
|
||||||
"text": {
|
"text": {
|
||||||
"headline": event.title,
|
"headline": event.title,
|
||||||
"text": event.body
|
"text": event.body
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
{% for event in events %}
|
{% for event in events %}
|
||||||
<div class="event" {% if event.date %}data-date="{{ event.date }}"{% endif %} id="{{ event.slug }}">
|
<div class="event" {% if event.date %}data-date="{{ event.date }}"{% endif %} id="{{ event.slug }}">
|
||||||
<h2 class="{{ event.type }}">{{ event.title | safe }}</h2>
|
<h2 class="{{ event.type }}">{{ event.title | safe }}</h2>
|
||||||
<div class="date">{{ event.date }}</div>
|
<div class="date">{{ event.display_date }}</div>
|
||||||
{% if event.media %}
|
{% if event.media %}
|
||||||
<div class="side-by-side">
|
<div class="side-by-side">
|
||||||
<div class="media">
|
<div class="media">
|
||||||
|
|
Loading…
Reference in a new issue