Fix default (status) filter for Employees grid
This commit is contained in:
parent
06b5f6c97c
commit
db0eee707a
|
@ -35,7 +35,6 @@ import colander
|
||||||
from deform import widget as dfwidget
|
from deform import widget as dfwidget
|
||||||
from webhelpers2.html import tags, HTML
|
from webhelpers2.html import tags, HTML
|
||||||
|
|
||||||
from tailbone import grids
|
|
||||||
from tailbone.db import Session
|
from tailbone.db import Session
|
||||||
from tailbone.views import MasterView, AutocompleteView
|
from tailbone.views import MasterView, AutocompleteView
|
||||||
|
|
||||||
|
@ -47,6 +46,10 @@ class EmployeesView(MasterView):
|
||||||
model_class = model.Employee
|
model_class = model.Employee
|
||||||
has_versions = True
|
has_versions = True
|
||||||
|
|
||||||
|
labels = {
|
||||||
|
'id': "ID",
|
||||||
|
}
|
||||||
|
|
||||||
grid_columns = [
|
grid_columns = [
|
||||||
'id',
|
'id',
|
||||||
'first_name',
|
'first_name',
|
||||||
|
@ -73,6 +76,7 @@ class EmployeesView(MasterView):
|
||||||
|
|
||||||
def configure_grid(self, g):
|
def configure_grid(self, g):
|
||||||
super(EmployeesView, self).configure_grid(g)
|
super(EmployeesView, self).configure_grid(g)
|
||||||
|
route_prefix = self.get_route_prefix()
|
||||||
|
|
||||||
g.joiners['phone'] = lambda q: q.outerjoin(model.EmployeePhoneNumber, sa.and_(
|
g.joiners['phone'] = lambda q: q.outerjoin(model.EmployeePhoneNumber, sa.and_(
|
||||||
model.EmployeePhoneNumber.parent_uuid == model.Employee.uuid,
|
model.EmployeePhoneNumber.parent_uuid == model.Employee.uuid,
|
||||||
|
@ -89,13 +93,22 @@ class EmployeesView(MasterView):
|
||||||
g.filters['phone'] = g.make_filter('phone', model.EmployeePhoneNumber.number,
|
g.filters['phone'] = g.make_filter('phone', model.EmployeePhoneNumber.number,
|
||||||
label="Phone Number")
|
label="Phone Number")
|
||||||
|
|
||||||
if self.request.has_perm('employees.edit'):
|
# id
|
||||||
|
if self.request.has_perm('{}.edit'.format(route_prefix)):
|
||||||
|
g.set_link('id')
|
||||||
|
else:
|
||||||
|
g.hide_column('id')
|
||||||
|
del g.filters['id']
|
||||||
|
|
||||||
|
# status
|
||||||
|
if self.request.has_perm('{}.edit'.format(route_prefix)):
|
||||||
|
g.set_enum('status', self.enum.EMPLOYEE_STATUS)
|
||||||
g.filters['status'].default_active = True
|
g.filters['status'].default_active = True
|
||||||
g.filters['status'].default_verb = 'equal'
|
g.filters['status'].default_verb = 'equal'
|
||||||
g.filters['status'].default_value = self.enum.EMPLOYEE_STATUS_CURRENT
|
# TODO: why must we set unicode string value here?
|
||||||
g.filters['status'].set_value_renderer(grids.filters.EnumValueRenderer(self.enum.EMPLOYEE_STATUS))
|
g.filters['status'].default_value = six.text_type(self.enum.EMPLOYEE_STATUS_CURRENT)
|
||||||
else:
|
else:
|
||||||
del g.filters['id']
|
g.hide_column('status')
|
||||||
del g.filters['status']
|
del g.filters['status']
|
||||||
|
|
||||||
g.filters['first_name'].default_active = True
|
g.filters['first_name'].default_active = True
|
||||||
|
@ -112,20 +125,12 @@ class EmployeesView(MasterView):
|
||||||
|
|
||||||
g.set_sort_defaults('first_name')
|
g.set_sort_defaults('first_name')
|
||||||
|
|
||||||
g.set_enum('status', self.enum.EMPLOYEE_STATUS)
|
|
||||||
|
|
||||||
g.set_label('id', "ID")
|
|
||||||
g.set_label('phone', "Phone Number")
|
g.set_label('phone', "Phone Number")
|
||||||
g.set_label('email', "Email Address")
|
g.set_label('email', "Email Address")
|
||||||
|
|
||||||
g.set_link('id')
|
|
||||||
g.set_link('first_name')
|
g.set_link('first_name')
|
||||||
g.set_link('last_name')
|
g.set_link('last_name')
|
||||||
|
|
||||||
if not self.request.has_perm('employees.edit'):
|
|
||||||
g.hide_column('id')
|
|
||||||
g.hide_column('status')
|
|
||||||
|
|
||||||
def query(self, session):
|
def query(self, session):
|
||||||
q = session.query(model.Employee).join(model.Person)
|
q = session.query(model.Employee).join(model.Person)
|
||||||
if not self.request.has_perm('employees.edit'):
|
if not self.request.has_perm('employees.edit'):
|
||||||
|
@ -186,7 +191,6 @@ class EmployeesView(MasterView):
|
||||||
f.set_label('display_name', "Short Name")
|
f.set_label('display_name', "Short Name")
|
||||||
f.set_label('phone', "Phone Number")
|
f.set_label('phone', "Phone Number")
|
||||||
f.set_label('email', "Email Address")
|
f.set_label('email', "Email Address")
|
||||||
f.set_label('id', "ID")
|
|
||||||
|
|
||||||
if not self.viewing:
|
if not self.viewing:
|
||||||
f.remove_fields('first_name', 'last_name')
|
f.remove_fields('first_name', 'last_name')
|
||||||
|
|
Loading…
Reference in a new issue