Cleanup some timesheet display logic

Also make sure to force current user unless they have permission to view
all time sheets.
This commit is contained in:
Lance Edgar 2016-06-14 22:19:37 -05:00
parent d94372ee41
commit 68ca5766d1
2 changed files with 11 additions and 18 deletions

View file

@ -30,7 +30,7 @@ import datetime
from rattail import enum from rattail import enum
from rattail.db import model, api from rattail.db import model, api
from rattail.time import localtime, get_sunday from rattail.time import localtime, make_utc, get_sunday
import formencode as fe import formencode as fe
from pyramid_simpleform import Form from pyramid_simpleform import Form
@ -167,6 +167,11 @@ class TimeSheetView(View):
except ValueError: except ValueError:
pass pass
# default to current user; force unless allowed to view all data
if not employee or not self.request.has_perm('{}.viewall'.format(self.key)):
employee = self.request.user.employee
assert employee
if not date: if not date:
date = localtime(self.rattail_config).date() date = localtime(self.rattail_config).date()
return self.render_single(date, employee, form=form) return self.render_single(date, employee, form=form)
@ -286,8 +291,7 @@ class TimeSheetView(View):
else: else:
week_of = '{} - {}'.format(sunday.strftime('%a %b %d, %Y'), saturday.strftime('%a %b %d, %Y')) week_of = '{} - {}'.format(sunday.strftime('%a %b %d, %Y'), saturday.strftime('%a %b %d, %Y'))
if employee: self.modify_employees([employee], weekdays)
self.modify_employees([employee], weekdays)
return { return {
'page_title': "Employee {}".format(self.get_title()), 'page_title': "Employee {}".format(self.get_title()),
@ -307,8 +311,8 @@ class TimeSheetView(View):
max_time = localtime(self.rattail_config, datetime.datetime.combine(weekdays[-1] + datetime.timedelta(days=1), datetime.time(0))) max_time = localtime(self.rattail_config, datetime.datetime.combine(weekdays[-1] + datetime.timedelta(days=1), datetime.time(0)))
shifts = Session.query(self.model_class)\ shifts = Session.query(self.model_class)\
.filter(self.model_class.employee_uuid.in_([e.uuid for e in employees]))\ .filter(self.model_class.employee_uuid.in_([e.uuid for e in employees]))\
.filter(self.model_class.start_time >= min_time)\ .filter(self.model_class.start_time >= make_utc(min_time))\
.filter(self.model_class.start_time < max_time)\ .filter(self.model_class.start_time < make_utc(max_time))\
.all() .all()
for employee in employees: for employee in employees:

View file

@ -28,10 +28,10 @@ from __future__ import unicode_literals, absolute_import
from rattail.db import model from rattail.db import model
from tailbone.views.shifts.lib import TimeSheetView from tailbone.views.shifts.lib import TimeSheetView as BaseTimeSheetView
class TimeSheetView(TimeSheetView): class TimeSheetView(BaseTimeSheetView):
""" """
Simple view for current user's time sheet. Simple view for current user's time sheet.
""" """
@ -39,17 +39,6 @@ class TimeSheetView(TimeSheetView):
title = "Time Sheet" title = "Time Sheet"
model_class = model.WorkedShift model_class = model.WorkedShift
# def __call__(self):
# date = self.get_date()
# employee = self.request.user.employee
# assert employee
# return self.render(date, [employee])
def includeme(config): def includeme(config):
TimeSheetView.defaults(config) TimeSheetView.defaults(config)
# current user's time sheet
# config.add_route('timesheet', '/timesheet/')
# config.add_view(TimeSheetView, route_name='timesheet',
# renderer='/shifts/timesheet.mako', permission='timesheet.view')