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:
parent
d94372ee41
commit
68ca5766d1
|
@ -30,7 +30,7 @@ import datetime
|
|||
|
||||
from rattail import enum
|
||||
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
|
||||
from pyramid_simpleform import Form
|
||||
|
@ -167,6 +167,11 @@ class TimeSheetView(View):
|
|||
except ValueError:
|
||||
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:
|
||||
date = localtime(self.rattail_config).date()
|
||||
return self.render_single(date, employee, form=form)
|
||||
|
@ -286,8 +291,7 @@ class TimeSheetView(View):
|
|||
else:
|
||||
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 {
|
||||
'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)))
|
||||
shifts = Session.query(self.model_class)\
|
||||
.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 < max_time)\
|
||||
.filter(self.model_class.start_time >= make_utc(min_time))\
|
||||
.filter(self.model_class.start_time < make_utc(max_time))\
|
||||
.all()
|
||||
|
||||
for employee in employees:
|
||||
|
|
|
@ -28,10 +28,10 @@ from __future__ import unicode_literals, absolute_import
|
|||
|
||||
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.
|
||||
"""
|
||||
|
@ -39,17 +39,6 @@ class TimeSheetView(TimeSheetView):
|
|||
title = "Time Sheet"
|
||||
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):
|
||||
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')
|
||||
|
|
Loading…
Reference in a new issue