Add week navigation to time sheet view

This commit is contained in:
Lance Edgar 2016-05-02 19:15:51 -05:00
parent 7e0e1f6659
commit 25ec005764
2 changed files with 68 additions and 16 deletions

View file

@ -41,10 +41,20 @@ class TimeSheetView(View):
"""
def __call__(self):
date = None
if 'date' in self.request.GET:
try:
date = datetime.datetime.strptime(self.request.GET['date'], '%Y-%m-%d').date()
except ValueError:
self.request.session.flash("The specified date is not valid: {}".format(self.request.GET['date']), 'error')
if not date:
date = localtime(self.rattail_config).date()
return self.render(date)
def render(self, date):
employee = self.request.user.employee
assert employee
today = localtime(self.rattail_config).date()
sunday = get_sunday(today)
sunday = get_sunday(date)
weekdays = [sunday]
for i in range(1, 7):
@ -103,9 +113,9 @@ class TimeSheetView(View):
def includeme(config):
config.add_tailbone_permission('timesheet', 'timesheet.view', "View Time Sheet")
# current user's time sheet
config.add_route('timesheet', '/timesheet/')
config.add_view(TimeSheetView, route_name='timesheet',
renderer='/timesheet/index.mako',
permission='timesheet.view')
config.add_tailbone_permission('timesheet', 'timesheet.view', "View Time Sheet")
renderer='/timesheet/index.mako', permission='timesheet.view')