Permalink
Browse files

Respect the local timezone (Pacific), and tidy up related imports.

  • Loading branch information...
1 parent a67ac50 commit b879063530ac14fcfa6ac22f974add71de275257 @mdhancher mdhancher committed with progrium May 13, 2010
Showing with 24 additions and 18 deletions.
  1. +9 −11 main.py
  2. +5 −7 models.py
  3. +10 −0 utils.py
View
@@ -7,18 +7,16 @@
from icalendar import Calendar
import logging, urllib
-from datetime import datetime, timedelta, time, date
-from pytz import timezone
-import pytz
+from datetime import datetime, timedelta
from models import Event, Feedback, ROOM_OPTIONS, GUESTS_PER_STAFF, PENDING_LIFETIME
-from utils import dojo, username, human_username, set_cookie
+from utils import dojo, username, human_username, set_cookie, local_today
from notices import *
class ExpireCron(webapp.RequestHandler):
def post(self):
# Expire events marked to expire today
- today = datetime.combine(datetime.today(), time())
+ today = local_today()
events = Event.all() \
.filter('status IN', ['pending', 'understaffed']) \
.filter('expired >=', today) \
@@ -30,7 +28,7 @@ def post(self):
class ExpireReminderCron(webapp.RequestHandler):
def post(self):
# Find events expiring in 10 days to warn owner
- ten_days = datetime.combine(datetime.today(), time()) + timedelta(days=10)
+ ten_days = local_today() + timedelta(days=10)
events = Event.all() \
.filter('status IN', ['pending', 'understaffed']) \
.filter('expired >=', ten_days) \
@@ -93,7 +91,7 @@ def get(self):
logout_url = users.create_logout_url('/')
else:
login_url = users.create_login_url('/')
- today = datetime.today()
+ today = local_today()
events = Event.get_approved_list()
tomorrow = today + timedelta(days=1)
self.response.out.write(template.render('templates/approved.html', locals()))
@@ -107,7 +105,7 @@ def get(self):
else:
login_url = users.create_login_url('/')
events = Event.all().filter('member = ', user).order('start_time')
- today = datetime.today()
+ today = local_today()
tomorrow = today + timedelta(days=1)
is_admin = username(user) in dojo('/groups/events')
self.response.out.write(template.render('templates/myevents.html', locals()))
@@ -119,7 +117,7 @@ def get(self):
logout_url = users.create_logout_url('/')
else:
login_url = users.create_login_url('/')
- today = datetime.today()
+ today = local_today()
events = Event.all().filter('start_time < ', today).order('-start_time')
is_admin = username(user) in dojo('/groups/events')
self.response.out.write(template.render('templates/past.html', locals()))
@@ -132,7 +130,7 @@ def get(self):
else:
login_url = users.create_login_url('/')
events = Event.get_pending_list()
- today = datetime.today()
+ today = local_today()
tomorrow = today + timedelta(days=1)
is_admin = username(user) in dojo('/groups/events')
self.response.out.write(template.render('templates/pending.html', locals()))
@@ -177,7 +175,7 @@ def post(self):
fee = self.request.get('fee'),
notes = self.request.get('notes'),
rooms = self.request.get_all('rooms'),
- expired = datetime.today() + timedelta(days=PENDING_LIFETIME), # Set expected expiration date
+ expired = local_today() + timedelta(days=PENDING_LIFETIME), # Set expected expiration date
)
event.put()
notify_owner_confirmation(event)
View
@@ -1,10 +1,8 @@
from google.appengine.ext import db
from google.appengine.api import urlfetch, memcache, users, mail
-from datetime import datetime, timedelta, time, date
+from datetime import datetime, timedelta
from icalendar import Calendar, Event as CalendarEvent
-from pytz import timezone
-import pytz
-from utils import human_username
+from utils import human_username, local_today
import logging
ROOM_OPTIONS = (
@@ -57,14 +55,14 @@ class Event(db.Model):
@classmethod
def get_approved_list(cls):
return cls.all() \
- .filter('start_time >', datetime.today()) \
+ .filter('start_time >', local_today()) \
.filter('status IN', ['approved', 'canceled']) \
.order('start_time')
@classmethod
def get_pending_list(cls):
return cls.all() \
- .filter('start_time >', datetime.today()) \
+ .filter('start_time >', local_today()) \
.filter('status IN', ['pending', 'understaffed', 'onhold', 'expired']) \
.order('start_time')
@@ -92,7 +90,7 @@ def is_deleted(self):
return self.status == 'deleted'
def is_past(self):
- return self.end_time < datetime.today()
+ return self.end_time < local_today()
def start_date(self):
return self.start_time.date()
View
@@ -1,5 +1,9 @@
from google.appengine.api import urlfetch, memcache
from django.utils import simplejson
+from datetime import datetime
+import pytz
+
+LOCAL_TZ = 'America/Los_Angeles'
# Hacker Dojo Domain API helper with caching
def dojo(path):
@@ -28,3 +32,9 @@ def human_username(user):
def set_cookie(headers, name, value):
headers.add_header('Set-Cookie', '%s=%s;' % (name, simplejson.dumps(value)))
+
+def local_today():
+ '''Return a datetime object representing the start of today, local time.'''
+ utc_now = pytz.utc.localize(datetime.utcnow())
+ local_now = utc_now.astimezone(pytz.timezone(LOCAL_TZ))
+ return datetime(*local_now.timetuple()[:3])

0 comments on commit b879063

Please sign in to comment.