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
|
@ -51,7 +51,7 @@ from webhelpers2.html import tags, HTML
|
|||
|
||||
from tailbone import forms, grids
|
||||
from tailbone.db import Session
|
||||
from tailbone.views import MasterView, AutocompleteView
|
||||
from tailbone.views import MasterView
|
||||
from tailbone.util import raw_datetime
|
||||
|
||||
|
||||
|
@ -84,6 +84,7 @@ class ProductView(MasterView):
|
|||
model_class = model.Product
|
||||
has_versions = True
|
||||
results_downloadable_xlsx = True
|
||||
supports_autocomplete = True
|
||||
|
||||
labels = {
|
||||
'item_id': "Item ID",
|
||||
|
@ -1886,31 +1887,6 @@ class ProductView(MasterView):
|
|||
renderer='json',
|
||||
permission='{}.versions'.format(permission_prefix))
|
||||
|
||||
# TODO: deprecate / remove this
|
||||
ProductsView = ProductView
|
||||
|
||||
|
||||
class ProductsAutocomplete(AutocompleteView):
|
||||
"""
|
||||
Autocomplete view for products.
|
||||
"""
|
||||
mapped_class = model.Product
|
||||
fieldname = 'description'
|
||||
|
||||
def query(self, term):
|
||||
q = Session.query(model.Product).outerjoin(model.Brand)
|
||||
q = q.filter(sa.or_(
|
||||
model.Brand.name.ilike('%{}%'.format(term)),
|
||||
model.Product.description.ilike('%{}%'.format(term))))
|
||||
if not self.request.has_perm('products.view_deleted'):
|
||||
q = q.filter(model.Product.deleted == False)
|
||||
q = q.order_by(model.Brand.name, model.Product.description)
|
||||
q = q.options(orm.joinedload(model.Product.brand))
|
||||
return q
|
||||
|
||||
def display(self, product):
|
||||
return product.full_description
|
||||
|
||||
|
||||
def print_labels(request):
|
||||
profile = request.params.get('profile')
|
||||
|
@ -1942,10 +1918,6 @@ def print_labels(request):
|
|||
|
||||
def includeme(config):
|
||||
|
||||
config.add_route('products.autocomplete', '/products/autocomplete')
|
||||
config.add_view(ProductsAutocomplete, route_name='products.autocomplete',
|
||||
renderer='json', permission='products.list')
|
||||
|
||||
config.add_route('products.print_labels', '/products/labels')
|
||||
config.add_view(print_labels, route_name='products.print_labels',
|
||||
renderer='json', permission='products.print_labels')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue