Improve the grid for WorkedShift model a bit
This commit is contained in:
parent
8b02fd3d38
commit
273f56ec83
|
@ -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):
|
||||
|
|
Loading…
Reference in a new issue