Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

(for better or for worse) refactoring

  • Loading branch information...
commit 7bd06ad1435cf83066d1a31d1e0210a6a2d3f5ea 1 parent bd598f7
Ethan Holda authored
Showing with 35 additions and 33 deletions.
  1. +33 −31 controllers/calendar.py
  2. +2 −2 templates/calendar.html
64 controllers/calendar.py
View
@@ -11,49 +11,51 @@
class Calendar(Controller):
def GET(self, action=None, param0=None, param1=None, param2=None):
if (Config.get('features').get('is_calendar_enabled')):
- if (action == 'show'):
- return self.showCalendar(param0, param1)
- elif (action == 'get'):
- return self.getCalendar(param0, param1)
+ if (action == 'show' or action == 'get'):
+ if (not param0 or not param1):
+ year, month = self.getCurrentYearMonth()
+ else:
+ year, month = (param0, param1)
+
+ d = datetime(int(year), int(month), 1)
+ start = "%s-%s" % (year, month)
+ end = (d + timedelta(days = 32)).strftime('%Y-%m')
+ events = self.getEvents(start, end)
+
+ if (action == 'show'):
+ return self.showCalendar(events, start, end, d)
+ elif (action == 'get'):
+ return self.getCalendar(events)
+
else:
return self.not_found()
else:
return self.not_found()
- def showCalendar(self, unit, start):
- if (not unit or not start):
- unit = 'monthly'
- d = datetime.now()
- start = d.strftime('%Y-%m')
-
- return self.redirect("/calendar/show/%(unit)s/%(start)s" % {'unit': 'monthly',
- 'start': start})
- elif (unit == 'monthly'):
- d = datetime.strptime(start, '%Y-%m')
- end = (d + timedelta(days = 32)).strftime('%Y-%m')
-
- self.template_data['calendar'] = {}
- self.template_data['calendar']['events'] = self.getEvents(start, end)
- self.template_data['calendar']['next_month'] = end
- self.template_data['calendar']['prev_month'] = (d + timedelta(days = -1)).strftime('%Y-%m')
- self.template_data['calendar']['is_active_month'] = self.isActiveMonth(d)
-
- return self.render('calendar')
- else:
- return self.not_found()
+ def showCalendar(self, events, start, end, d):
+ self.template_data['calendar'] = {}
+ self.template_data['calendar']['events'] = events
+ self.template_data['calendar']['next_month'] = end
+ self.template_data['calendar']['prev_month'] = (d + timedelta(days = -1)).strftime('%Y-%m')
+ self.template_data['calendar']['is_active_month'] = self.isActiveMonth(d)
- def getCalendar(self, unit, start):
- if (unit == 'monthly'):
- return start
- else:
- return self.not_found()
-
+ return self.render('calendar')
+
+ def getCalendar(self, year, month):
+ return self.json({'events': events})
def getEvents(self, start, end):
events = self.orm.query(models.Event).filter(and_(models.Event.start_datetime > start,
models.Event.start_datetime < end))
return events
+ def getCurrentYearMonth(self):
+ now = datetime.now()
+ year = now.year
+ month = now.strftime('%m')
+
+ return (year, month)
+
def isActiveMonth(self, d):
now = datetime.now()
4 templates/calendar.html
View
@@ -19,10 +19,10 @@
<!-- carousel controls -->
<div class="pagination-controls calendar clearfix">
<span class="control">
- <a class="prev calendar-carousel-prev" href="/calendar/show/monthly/{{ d.template_data.calendar.prev_month }}">
+ <a class="prev calendar-carousel-prev" href="/calendar/show/{{ d.template_data.calendar.prev_month|replace('-', '/') }}">
<span class="sm-arrow-back light"></span><span>Previous</span>
</a>
- <a class="next calendar-carousel-next" href="/calendar/show/monthly/{{ d.template_data.calendar.next_month }}">
+ <a class="next calendar-carousel-next" href="/calendar/show/{{ d.template_data.calendar.next_month|replace('-', '/') }}">
<span>Next</span><span class="sm-arrow-forward light"></span>
</a>
</span>
Please sign in to comment.
Something went wrong with that request. Please try again.