add employee views
This commit is contained in:
parent
5deb198846
commit
6ba157ccb2
2
rattail/pyramid/templates/employees/base.mako
Normal file
2
rattail/pyramid/templates/employees/base.mako
Normal file
|
@ -0,0 +1,2 @@
|
|||
<%inherit file="/base.mako" />
|
||||
${parent.body()}
|
8
rattail/pyramid/templates/employees/crud.mako
Normal file
8
rattail/pyramid/templates/employees/crud.mako
Normal file
|
@ -0,0 +1,8 @@
|
|||
<%inherit file="/employees/base.mako" />
|
||||
<%inherit file="/crud.mako" />
|
||||
|
||||
<%def name="menu()">
|
||||
<p>${h.link_to("Back to Employees", url('employees.list'))}</p>
|
||||
</%def>
|
||||
|
||||
${parent.body()}
|
2
rattail/pyramid/templates/employees/edit.mako
Normal file
2
rattail/pyramid/templates/employees/edit.mako
Normal file
|
@ -0,0 +1,2 @@
|
|||
<%inherit file="/employees/crud.mako" />
|
||||
${parent.body()}
|
12
rattail/pyramid/templates/employees/index.mako
Normal file
12
rattail/pyramid/templates/employees/index.mako
Normal file
|
@ -0,0 +1,12 @@
|
|||
<%inherit file="/employees/base.mako" />
|
||||
<%inherit file="/index.mako" />
|
||||
|
||||
<%def name="title()">Employees</%def>
|
||||
|
||||
<%def name="menu()">
|
||||
% if request.has_perm('employees.create'):
|
||||
<p>${h.link_to("Create a new Employee", url('employees.new'))}</p>
|
||||
% endif
|
||||
</%def>
|
||||
|
||||
${parent.body()}
|
2
rattail/pyramid/templates/employees/new.mako
Normal file
2
rattail/pyramid/templates/employees/new.mako
Normal file
|
@ -0,0 +1,2 @@
|
|||
<%inherit file="/employees/crud.mako" />
|
||||
${parent.body()}
|
|
@ -32,3 +32,4 @@ def includeme(config):
|
|||
config.include('rattail.pyramid.views.departments')
|
||||
config.include('rattail.pyramid.views.categories')
|
||||
config.include('rattail.pyramid.views.products')
|
||||
config.include('rattail.pyramid.views.employees')
|
||||
|
|
108
rattail/pyramid/views/employees.py
Normal file
108
rattail/pyramid/views/employees.py
Normal file
|
@ -0,0 +1,108 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
################################################################################
|
||||
#
|
||||
# Rattail -- Retail Software Framework
|
||||
# Copyright © 2010-2012 Lance Edgar
|
||||
#
|
||||
# This file is part of Rattail.
|
||||
#
|
||||
# Rattail is free software: you can redistribute it and/or modify it under the
|
||||
# terms of the GNU Affero General Public License as published by the Free
|
||||
# Software Foundation, either version 3 of the License, or (at your option)
|
||||
# any later version.
|
||||
#
|
||||
# Rattail is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
# FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
|
||||
# more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with Rattail. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
################################################################################
|
||||
|
||||
"""
|
||||
``rattail.pyramid.views.employees`` -- Employee Views
|
||||
"""
|
||||
|
||||
import edbob
|
||||
from edbob.pyramid.filters import filter_ilike
|
||||
from edbob.pyramid.forms import AssociationProxyField
|
||||
from edbob.pyramid.grids import sorter
|
||||
from edbob.pyramid.views import GridView
|
||||
from edbob.pyramid.views.crud import Crud
|
||||
|
||||
import rattail
|
||||
|
||||
|
||||
class EmployeeGrid(GridView):
|
||||
|
||||
mapped_class = rattail.Employee
|
||||
route_name = 'employees.list'
|
||||
route_prefix = 'employee'
|
||||
|
||||
def filter_map(self):
|
||||
return self.make_filter_map(
|
||||
first_name=filter_ilike(edbob.Person.first_name),
|
||||
last_name=filter_ilike(edbob.Person.last_name))
|
||||
|
||||
def search_config(self, fmap):
|
||||
return self.make_search_config(
|
||||
fmap,
|
||||
include_filter_first_name=True,
|
||||
filter_type_first_name='lk',
|
||||
include_filter_last_name=True,
|
||||
filter_type_last_name='lk')
|
||||
|
||||
def grid_config(self, search, fmap):
|
||||
kwargs = {}
|
||||
if self.request.has_perm('employees.delete'):
|
||||
kwargs['deletable'] = True
|
||||
return self.make_grid_config(
|
||||
search, fmap,
|
||||
sort='first_name', **kwargs)
|
||||
|
||||
def sort_map(self):
|
||||
return self.make_sort_map(
|
||||
first_name=sorter(edbob.Person.first_name),
|
||||
last_name=sorter(edbob.Person.last_name))
|
||||
|
||||
def query(self, config):
|
||||
q = self.make_query(config)
|
||||
q = q.join(edbob.Person)
|
||||
if not self.request.has_perm('employees.edit'):
|
||||
q = q.filter(rattail.Employee.status == rattail.EMPLOYEE_STATUS_CURRENT)
|
||||
return q
|
||||
|
||||
def grid(self, data, config):
|
||||
g = self.make_grid(data, config)
|
||||
g.append(AssociationProxyField('first_name'))
|
||||
g.append(AssociationProxyField('last_name'))
|
||||
g.configure(
|
||||
include=[
|
||||
g.first_name,
|
||||
g.last_name,
|
||||
# g.status,
|
||||
],
|
||||
readonly=True)
|
||||
return g
|
||||
|
||||
|
||||
class EmployeeCrud(Crud):
|
||||
|
||||
mapped_class = rattail.Employee
|
||||
home_route = 'employees.list'
|
||||
|
||||
def fieldset(self, obj):
|
||||
fs = self.make_fieldset(obj)
|
||||
fs.configure(
|
||||
include=[
|
||||
fs.person,
|
||||
])
|
||||
return fs
|
||||
|
||||
|
||||
def includeme(config):
|
||||
EmployeeGrid.add_route(config, 'employees.list', '/employees')
|
||||
EmployeeCrud.add_routes(config)
|
Loading…
Reference in a new issue