update grids per edbob changes, add order worksheet report

This commit is contained in:
Lance Edgar 2012-08-06 15:05:09 -07:00
parent 84b1eec937
commit a4f2b6d5c2
10 changed files with 446 additions and 156 deletions

View file

@ -26,64 +26,64 @@
``rattail.pyramid.views.employees`` -- Employee Views
"""
from sqlalchemy import and_
import edbob
from edbob.pyramid.filters import filter_ilike
from edbob.pyramid import grids
from edbob.pyramid.forms import AssociationProxyField
from edbob.pyramid.grids import sorter
from edbob.pyramid.views import GridView
from edbob.pyramid.views import SearchableAlchemyGridView
from edbob.pyramid.views.crud import Crud
import rattail
class EmployeeGrid(GridView):
class EmployeesGrid(SearchableAlchemyGridView):
mapped_class = rattail.Employee
route_name = 'employees.list'
route_prefix = 'employee'
route_name = 'employees'
route_url = '/employees'
renderer = '/employees/index.mako'
sort = 'first_name'
def filter_map(self):
return self.make_filter_map(
first_name=filter_ilike(edbob.Person.first_name),
last_name=filter_ilike(edbob.Person.last_name))
first_name=grids.search.filter_ilike(edbob.Person.first_name),
last_name=grids.search.filter_ilike(edbob.Person.last_name),
phone=grids.search.filter_ilike(edbob.PersonPhone.number))
def search_config(self, fmap):
return self.make_search_config(
fmap,
def filter_config(self):
return self.make_filter_config(
include_filter_first_name=True,
filter_type_first_name='lk',
include_filter_last_name=True,
filter_type_last_name='lk')
def grid_config(self, search, fmap):
kwargs = {}
if self.request.has_perm('employees.delete'):
kwargs['deletable'] = True
return self.make_grid_config(
search, fmap,
sort='first_name', **kwargs)
filter_type_last_name='lk',
filter_label_phone="Phone Number")
def sort_map(self):
return self.make_sort_map(
first_name=sorter(edbob.Person.first_name),
last_name=sorter(edbob.Person.last_name))
first_name=grids.util.sorter(edbob.Person.first_name),
last_name=grids.util.sorter(edbob.Person.last_name),
phone=grids.util.sorter(edbob.PersonPhone.number))
def query(self, config):
q = self.make_query(config)
def query(self):
q = self.make_query()
q = q.join(edbob.Person)
q = q.outerjoin(edbob.PersonPhone, and_(
edbob.PersonPhone.parent_uuid == rattail.Employee.person_uuid,
edbob.PersonPhone.preference == 1))
if not self.request.has_perm('employees.edit'):
q = q.filter(rattail.Employee.status == rattail.EMPLOYEE_STATUS_CURRENT)
return q
def grid(self, data, config):
g = self.make_grid(data, config)
def grid(self):
g = self.make_grid()
g.append(AssociationProxyField('first_name'))
g.append(AssociationProxyField('last_name'))
g.configure(
include=[
g.first_name,
g.last_name,
# g.status,
g.phone.label("Phone Number"),
],
readonly=True)
return g
@ -104,5 +104,5 @@ class EmployeeCrud(Crud):
def includeme(config):
EmployeeGrid.add_route(config, 'employees.list', '/employees')
EmployeesGrid.add_route(config)
EmployeeCrud.add_routes(config)