Refactor autocomplete view logic to leverage new "autocompleters"
finally! this cleans up some view config and AFAIK there is no loss in functionality etc.
This commit is contained in:
parent
e0dff55ffa
commit
a7f4b2e6ef
12 changed files with 65 additions and 375 deletions
|
@ -36,8 +36,7 @@ from deform import widget as dfwidget
|
|||
from webhelpers2.html import tags, HTML
|
||||
|
||||
from tailbone import grids
|
||||
from tailbone.db import Session
|
||||
from tailbone.views import MasterView, AutocompleteView
|
||||
from tailbone.views import MasterView
|
||||
|
||||
|
||||
class EmployeeView(MasterView):
|
||||
|
@ -47,6 +46,7 @@ class EmployeeView(MasterView):
|
|||
model_class = model.Employee
|
||||
has_versions = True
|
||||
touchable = True
|
||||
supports_autocomplete = True
|
||||
|
||||
labels = {
|
||||
'id': "ID",
|
||||
|
@ -310,31 +310,6 @@ class EmployeeView(MasterView):
|
|||
(model.EmployeeDepartment, 'employee_uuid'),
|
||||
]
|
||||
|
||||
# TODO: deprecate / remove this
|
||||
EmployeesView = EmployeeView
|
||||
|
||||
|
||||
class EmployeesAutocomplete(AutocompleteView):
|
||||
"""
|
||||
Autocomplete view for the Employee model, but restricted to return only
|
||||
results for current employees.
|
||||
"""
|
||||
mapped_class = model.Person
|
||||
fieldname = 'display_name'
|
||||
|
||||
def filter_query(self, q):
|
||||
return q.join(model.Employee)\
|
||||
.filter(model.Employee.status == self.enum.EMPLOYEE_STATUS_CURRENT)
|
||||
|
||||
def value(self, person):
|
||||
return person.employee.uuid
|
||||
|
||||
|
||||
def includeme(config):
|
||||
|
||||
# autocomplete
|
||||
config.add_route('employees.autocomplete', '/employees/autocomplete')
|
||||
config.add_view(EmployeesAutocomplete, route_name='employees.autocomplete',
|
||||
renderer='json', permission='employees.list')
|
||||
|
||||
EmployeeView.defaults(config)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue