From 273f56ec8380bf288353e640def5fb7df027ad03 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Sat, 4 Feb 2017 12:32:21 -0600 Subject: [PATCH] Improve the grid for WorkedShift model a bit --- tailbone/views/shifts/core.py | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/tailbone/views/shifts/core.py b/tailbone/views/shifts/core.py index 4335c42e..f797306b 100644 --- a/tailbone/views/shifts/core.py +++ b/tailbone/views/shifts/core.py @@ -31,9 +31,11 @@ import datetime import humanize from rattail.db import model +from rattail.time import localtime import formalchemy +from tailbone import forms from tailbone.views import MasterView @@ -96,13 +98,28 @@ class WorkedShiftsView(MasterView): model_class = model.WorkedShift url_prefix = '/shifts/worked' - def configure_grid(self, g): + def _preconfigure_grid(self, g): + g.joiners['employee'] = lambda q: q.join(model.Employee).join(model.Person) + g.filters['employee'] = g.make_filter('employee', model.Person.display_name, + label="Employee Name") + g.sorters['employee'] = g.make_sorter(model.Person.display_name) + + g.joiners['store'] = lambda q: q.join(model.Store) + g.filters['store'] = g.make_filter('store', model.Store.name, label="Store Name") + g.sorters['store'] = g.make_sorter(model.Store.name) + + g.filters['punch_in'].label = "Start Time" + g.filters['punch_out'].label = "End Time" + # TODO: these sorters should be automatic once we fix the schema g.sorters['start_time'] = g.make_sorter(model.WorkedShift.punch_in) g.sorters['end_time'] = g.make_sorter(model.WorkedShift.punch_out) g.default_sortkey = 'start_time' g.default_sortdir = 'desc' + g.append(ShiftLengthField('length')) + + def configure_grid(self, g): g.configure( include=[ g.employee, @@ -113,8 +130,16 @@ class WorkedShiftsView(MasterView): ], readonly=True) - def configure_fieldset(self, fs): + def get_instance_title(self, shift): + time = shift.start_time or shift.end_time + date = localtime(self.rattail_config, time).date() + return "WorkedShift: {}, {}".format(shift.employee, date) + + def _preconfigure_fieldset(self, fs): fs.append(ShiftLengthField('length')) + fs.employee.set(readonly=True, renderer=forms.renderers.EmployeeFieldRenderer) + + def configure_fieldset(self, fs): fs.configure( include=[ fs.employee, @@ -123,6 +148,8 @@ class WorkedShiftsView(MasterView): fs.end_time, fs.length, ]) + if self.editing: + del fs.length def includeme(config):