From 4d4c83b0aed3111f59d7f6e8bcd0671253664582 Mon Sep 17 00:00:00 2001 From: Martin Bauer Date: Sat, 11 Jan 2014 11:46:53 +0100 Subject: [PATCH] Bugfix for Countdown - error when for the next event no displaytime was available - better display when no time or location for the next event is known --- eventplanner/models.py | 8 +++++++- website/templates/website/event_countdown.html | 4 ++-- website/views.py | 6 +++--- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/eventplanner/models.py b/eventplanner/models.py index 1ac8dab..8bd01aa 100644 --- a/eventplanner/models.py +++ b/eventplanner/models.py @@ -61,8 +61,14 @@ class Event ( models.Model ): else: return self.meeting_time + @property + def displaydatetime(self): + if not self.displaytime == None: + return datetime.combine( self.date, self.displaytime() ) + else: + return datetime.combine( self.date, datetime.min.time()) - + class EventParticipation( models.Model ): OPTIONS = ( ('?' , _('?' )), diff --git a/website/templates/website/event_countdown.html b/website/templates/website/event_countdown.html index 164048d..ae63648 100644 --- a/website/templates/website/event_countdown.html +++ b/website/templates/website/event_countdown.html @@ -39,8 +39,8 @@

Der nächste Termin:

{{countdown.event.title}} am {{countdown.event.date | date:"D, d.m.y" }} - um {{countdown.event.displaytime | time:"H:i" }} Uhr - in {{countdown.event.location}} + {% if coundown.event.displaytime %} um {{countdown.event.displaytime | time:"H:i" }} Uhr {% endif %} + {% if coundown.event.location %} in {{countdown.event.location}} {% endif %}
{% if 'participation' in countdown %} diff --git a/website/views.py b/website/views.py index f193f43..4d091e7 100644 --- a/website/views.py +++ b/website/views.py @@ -32,7 +32,8 @@ def home_view(request): if ( len(events) > 0 ): i = 0 nextEvent = events[0] - while datetime.combine( nextEvent.date, nextEvent.time ) < datetime.now(): + + while nextEvent.displaydatetime < datetime.now(): if len(events ) <= i: return else: @@ -43,8 +44,7 @@ def home_view(request): part = EventParticipation.objects.filter( user = request.user ).filter( event = nextEvent ) countdown['participation'] = part[0].status - eventTime = datetime( nextEvent.date.year, nextEvent.date.month, nextEvent.date.day, - nextEvent.displaytime.hour, nextEvent.displaytime.minute ) + eventTime = nextEvent.displaydatetime countdown['event'] = nextEvent countdown['epoch'] = int( (eventTime - datetime.now() ).total_seconds() * 1000 )