From 2626ff4fdfa7bfc3d2d96cfda71325c943aba071 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Sat, 19 Jul 2014 18:49:00 -0700 Subject: [PATCH] Add Person autocomplete view which restricts to employees only. --- tailbone/views/people.py | 21 +++++++++++++++++++++ tailbone/views/users.py | 21 ++++++++++++--------- 2 files changed, 33 insertions(+), 9 deletions(-) diff --git a/tailbone/views/people.py b/tailbone/views/people.py index 5f9246e2..32a32e87 100644 --- a/tailbone/views/people.py +++ b/tailbone/views/people.py @@ -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') diff --git a/tailbone/views/users.py b/tailbone/views/users.py index a2f8d847..2f1cbf4f 100644 --- a/tailbone/views/users.py +++ b/tailbone/views/users.py @@ -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')