Add Person autocomplete view which restricts to employees only.

This commit is contained in:
Lance Edgar 2014-07-19 18:49:00 -07:00
parent 9c294f2e4d
commit 2626ff4fdf
2 changed files with 33 additions and 9 deletions

View file

@ -31,6 +31,8 @@ from sqlalchemy import and_
from . import SearchableAlchemyGridView, CrudView, AutocompleteView
from ..db import Session
from rattail.db import model
from rattail.db.model import (Person, PersonEmailAddress, PersonPhoneNumber,
VendorContact)
@ -132,9 +134,20 @@ class PeopleAutocomplete(AutocompleteView):
fieldname = 'display_name'
class PeopleEmployeesAutocomplete(PeopleAutocomplete):
"""
Autocomplete view for the Person model, but restricted to return only
results for people who are employees.
"""
def filter_query(self, q):
return q.join(model.Employee)
def add_routes(config):
config.add_route('people', '/people')
config.add_route('people.autocomplete', '/people/autocomplete')
config.add_route(u'people.autocomplete.employees', u'/people/autocomplete/employees')
config.add_route('person.read', '/people/{uuid}')
config.add_route('person.update', '/people/{uuid}/edit')
@ -142,15 +155,23 @@ def add_routes(config):
def includeme(config):
add_routes(config)
# List
config.add_view(PeopleGrid, route_name='people',
renderer='/people/index.mako',
permission='people.list')
# CRUD
config.add_view(PersonCrud, attr='read', route_name='person.read',
renderer='/people/crud.mako',
permission='people.read')
config.add_view(PersonCrud, attr='update', route_name='person.update',
renderer='/people/crud.mako',
permission='people.update')
# Autocomplete
config.add_view(PeopleAutocomplete, route_name='people.autocomplete',
renderer='json',
permission='people.list')
config.add_view(PeopleEmployeesAutocomplete, route_name=u'people.autocomplete.employees',
renderer=u'json',
permission=u'people.list')

View file

@ -167,28 +167,31 @@ class UserCrud(CrudView):
return fs
def includeme(config):
def add_routes(config):
config.add_route(u'users', u'/users')
config.add_route(u'user.create', u'/users/new')
config.add_route(u'user.read', u'/users/{uuid}')
config.add_route(u'user.update', u'/users/{uuid}/edit')
config.add_route(u'user.delete', u'/users/{uuid}/delete')
config.add_route('users', '/users')
def includeme(config):
add_routes(config)
# List
config.add_view(UsersGrid, route_name='users',
renderer='/users/index.mako',
permission='users.list')
config.add_route('user.create', '/users/new')
# CRUD
config.add_view(UserCrud, attr='create', route_name='user.create',
renderer='/users/crud.mako',
permission='users.create')
config.add_route('user.read', '/users/{uuid}')
config.add_view(UserCrud, attr='read', route_name='user.read',
renderer='/users/crud.mako',
permission='users.read')
config.add_route('user.update', '/users/{uuid}/edit')
config.add_view(UserCrud, attr='update', route_name='user.update',
renderer='/users/crud.mako',
permission='users.update')
config.add_route('user.delete', '/users/{uuid}/delete')
config.add_view(UserCrud, attr='delete', route_name='user.delete',
permission='users.delete')