Permalink
Browse files

(For #12) Show every day of multiple day events

  • Loading branch information...
1 parent 1ad395b commit 411c89f1b896529618ff31163545e4d67b35f3a9 @mikeharris100 mikeharris100 committed Dec 5, 2011
Showing with 38 additions and 3 deletions.
  1. +1 −1 main.py
  2. +36 −1 models.py
  3. +1 −1 templates/list_event.html
View
@@ -341,7 +341,7 @@ def get(self):
login_url = users.create_login_url('/')
today = local_today()
show_all_nav = user
- events = Event.get_approved_list()
+ events = Event.get_approved_list_with_multiday()
tomorrow = today + timedelta(days=1)
whichbase = 'base.html'
if self.request.get('base'):
View
@@ -1,6 +1,7 @@
from google.appengine.ext import db
from google.appengine.api import urlfetch, memcache, users, mail
-from datetime import datetime, timedelta
+from datetime import datetime, timedelta, time
+from copy import copy
from utils import human_username, local_today, to_sentence_list
import logging
import pytz
@@ -84,6 +85,29 @@ def get_approved_list(cls):
.filter('start_time >', local_today()) \
.filter('status IN', ['approved', 'canceled']) \
.order('start_time')
+
+ @classmethod
+ def get_approved_list_with_multiday(cls):
+ events = list(cls.all() \
+ .filter('end_time >', local_today()) \
+ .filter('status IN', ['approved', 'canceled']))
+
+ # create dupe event objects for each day of multiday events
+ for event in list(events):
+ if event.start_time < local_today():
+ # remove original if it started before today
+ events.remove(event)
+ for day in range(1, event.num_days):
+ if event.start_time + timedelta(days=day) >= local_today():
+ clone = copy(event)
+ clone.start_time = datetime.combine(event.start_date(), time()) + timedelta(days=day)
+ clone.is_continued = True
+ events.append(clone)
+
+
+ events.sort(key = lambda event: event.start_time)
+
+ return events
@classmethod
def get_recent_past_and_future(cls):
@@ -156,6 +180,17 @@ def is_not_approved(self):
def start_date(self):
return self.start_time.date()
+ def end_date(self):
+ return self.end_time.date()
+
+ @property
+ def num_days(self):
+ num_days = (self.end_date() - self.start_date()).days + 1
+ if num_days > 1 and self.end_time.timetuple()[3] < 8:
+ # only count that day if the event runs past 8am
+ num_days -= 1
+ return num_days
+
def approve(self):
user = users.get_current_user()
if self.is_staffed():
@@ -1,5 +1,5 @@
<tr>
- <td width="75">{{event.start_time|date:"g:iA"|lower}}</td>
+ <td width="75">{% if event.is_continued %}(Contd){% else %}{{event.start_time|date:"g:iA"|lower}}{% endif %}</td>
<td>
<a {% if event.is_canceled %}style="text-decoration: line-through;"{% endif %} {% ifnotequal event.status "approved" %}rel="nofollow"{% endifnotequal %} href="/event/{{event.key.id}}-{{event.name|slugify}}">
{{event.name}}

0 comments on commit 411c89f

Please sign in to comment.