Added id
and .status
fields to Employee grid view.
This commit is contained in:
parent
06429a4d05
commit
c6f5df7721
3 changed files with 91 additions and 3 deletions
|
@ -29,10 +29,11 @@
|
|||
from sqlalchemy import and_
|
||||
|
||||
import edbob
|
||||
from edbob.pyramid.forms import AssociationProxyField
|
||||
from edbob.pyramid.forms import AssociationProxyField, EnumFieldRenderer
|
||||
from edbob.pyramid.views import SearchableAlchemyGridView
|
||||
|
||||
import rattail
|
||||
from rattail.pyramid.grids import EnumSearchFilter
|
||||
|
||||
|
||||
class EmployeesGrid(SearchableAlchemyGridView):
|
||||
|
@ -50,18 +51,30 @@ class EmployeesGrid(SearchableAlchemyGridView):
|
|||
}
|
||||
|
||||
def filter_map(self):
|
||||
return self.make_filter_map(
|
||||
kwargs = dict(
|
||||
first_name=self.filter_ilike(edbob.Person.first_name),
|
||||
last_name=self.filter_ilike(edbob.Person.last_name),
|
||||
phone=self.filter_ilike(rattail.EmployeePhoneNumber.number))
|
||||
if self.request.has_perm('employees.edit'):
|
||||
kwargs.update(dict(
|
||||
exact=['id', 'status']))
|
||||
return self.make_filter_map(**kwargs)
|
||||
|
||||
def filter_config(self):
|
||||
return self.make_filter_config(
|
||||
kwargs = dict(
|
||||
include_filter_first_name=True,
|
||||
filter_type_first_name='lk',
|
||||
include_filter_last_name=True,
|
||||
filter_type_last_name='lk',
|
||||
filter_label_phone="Phone Number")
|
||||
if self.request.has_perm('employees.edit'):
|
||||
kwargs.update(dict(
|
||||
filter_label_id="ID",
|
||||
include_filter_status=True,
|
||||
filter_type_status='is',
|
||||
filter_factory_status=EnumSearchFilter(rattail.EMPLOYEE_STATUS),
|
||||
status=rattail.EMPLOYEE_STATUS_CURRENT))
|
||||
return self.make_filter_config(**kwargs)
|
||||
|
||||
def sort_map(self):
|
||||
return self.make_sort_map(
|
||||
|
@ -82,11 +95,16 @@ class EmployeesGrid(SearchableAlchemyGridView):
|
|||
g.append(AssociationProxyField('last_name'))
|
||||
g.configure(
|
||||
include=[
|
||||
g.id.label("ID"),
|
||||
g.first_name,
|
||||
g.last_name,
|
||||
g.phone.label("Phone Number"),
|
||||
g.status.with_renderer(EnumFieldRenderer(rattail.EMPLOYEE_STATUS)),
|
||||
],
|
||||
readonly=True)
|
||||
if not self.request.has_perm('employees.edit'):
|
||||
del g.id
|
||||
del g.status
|
||||
return g
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue