Add autocomplete view for current employees.
This commit is contained in:
parent
0c4ceefa2c
commit
6db88edb68
|
@ -1,9 +1,8 @@
|
||||||
#!/usr/bin/env python
|
# -*- coding: utf-8 -*-
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
################################################################################
|
################################################################################
|
||||||
#
|
#
|
||||||
# Rattail -- Retail Software Framework
|
# Rattail -- Retail Software Framework
|
||||||
# Copyright © 2010-2012 Lance Edgar
|
# Copyright © 2010-2015 Lance Edgar
|
||||||
#
|
#
|
||||||
# This file is part of Rattail.
|
# This file is part of Rattail.
|
||||||
#
|
#
|
||||||
|
@ -21,13 +20,19 @@
|
||||||
# along with Rattail. If not, see <http://www.gnu.org/licenses/>.
|
# along with Rattail. If not, see <http://www.gnu.org/licenses/>.
|
||||||
#
|
#
|
||||||
################################################################################
|
################################################################################
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Employee Views
|
Employee Views
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from sqlalchemy import and_
|
from sqlalchemy import and_
|
||||||
|
|
||||||
|
from rattail.db import model
|
||||||
|
from rattail import enum
|
||||||
|
|
||||||
|
from tailbone.views import AutocompleteView
|
||||||
|
|
||||||
from . import SearchableAlchemyGridView, CrudView
|
from . import SearchableAlchemyGridView, CrudView
|
||||||
from ..grids.search import EnumSearchFilter
|
from ..grids.search import EnumSearchFilter
|
||||||
from ..forms import AssociationProxyField, EnumFieldRenderer
|
from ..forms import AssociationProxyField, EnumFieldRenderer
|
||||||
|
@ -36,6 +41,7 @@ from rattail.db.model import (
|
||||||
from rattail.enum import EMPLOYEE_STATUS, EMPLOYEE_STATUS_CURRENT
|
from rattail.enum import EMPLOYEE_STATUS, EMPLOYEE_STATUS_CURRENT
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class EmployeesGrid(SearchableAlchemyGridView):
|
class EmployeesGrid(SearchableAlchemyGridView):
|
||||||
|
|
||||||
mapped_class = Employee
|
mapped_class = Employee
|
||||||
|
@ -151,12 +157,29 @@ class EmployeeCrud(CrudView):
|
||||||
return fs
|
return fs
|
||||||
|
|
||||||
|
|
||||||
|
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 == enum.EMPLOYEE_STATUS_CURRENT)
|
||||||
|
|
||||||
|
def value(self, person):
|
||||||
|
return person.employee.uuid
|
||||||
|
|
||||||
|
|
||||||
def add_routes(config):
|
def add_routes(config):
|
||||||
config.add_route('employees', '/employees')
|
config.add_route('employees', '/employees')
|
||||||
config.add_route('employee.create', '/employees/new')
|
config.add_route('employee.create', '/employees/new')
|
||||||
config.add_route('employee.read', '/employees/{uuid}')
|
config.add_route('employees.autocomplete', '/employees/autocomplete')
|
||||||
config.add_route('employee.update', '/employees/{uuid}/edit')
|
config.add_route('employee.read', '/employees/{uuid}')
|
||||||
config.add_route('employee.delete', '/employees/{uuid}/delete')
|
config.add_route('employee.update', '/employees/{uuid}/edit')
|
||||||
|
config.add_route('employee.delete', '/employees/{uuid}/delete')
|
||||||
|
|
||||||
|
|
||||||
def includeme(config):
|
def includeme(config):
|
||||||
|
@ -176,3 +199,7 @@ def includeme(config):
|
||||||
permission='employees.update')
|
permission='employees.update')
|
||||||
config.add_view(EmployeeCrud, attr='delete', route_name='employee.delete',
|
config.add_view(EmployeeCrud, attr='delete', route_name='employee.delete',
|
||||||
permission='employees.delete')
|
permission='employees.delete')
|
||||||
|
|
||||||
|
# autocomplete
|
||||||
|
config.add_view(EmployeesAutocomplete, route_name='employees.autocomplete',
|
||||||
|
renderer='json', permission='employees.list')
|
||||||
|
|
Loading…
Reference in a new issue