diff --git a/rattail/pyramid/templates/employees/base.mako b/rattail/pyramid/templates/employees/base.mako new file mode 100644 index 00000000..27f7dd90 --- /dev/null +++ b/rattail/pyramid/templates/employees/base.mako @@ -0,0 +1,2 @@ +<%inherit file="/base.mako" /> +${parent.body()} diff --git a/rattail/pyramid/templates/employees/crud.mako b/rattail/pyramid/templates/employees/crud.mako new file mode 100644 index 00000000..71b2e0b4 --- /dev/null +++ b/rattail/pyramid/templates/employees/crud.mako @@ -0,0 +1,8 @@ +<%inherit file="/employees/base.mako" /> +<%inherit file="/crud.mako" /> + +<%def name="menu()"> +

${h.link_to("Back to Employees", url('employees.list'))}

+ + +${parent.body()} diff --git a/rattail/pyramid/templates/employees/edit.mako b/rattail/pyramid/templates/employees/edit.mako new file mode 100644 index 00000000..47d8b103 --- /dev/null +++ b/rattail/pyramid/templates/employees/edit.mako @@ -0,0 +1,2 @@ +<%inherit file="/employees/crud.mako" /> +${parent.body()} diff --git a/rattail/pyramid/templates/employees/index.mako b/rattail/pyramid/templates/employees/index.mako new file mode 100644 index 00000000..9595775f --- /dev/null +++ b/rattail/pyramid/templates/employees/index.mako @@ -0,0 +1,12 @@ +<%inherit file="/employees/base.mako" /> +<%inherit file="/index.mako" /> + +<%def name="title()">Employees + +<%def name="menu()"> + % if request.has_perm('employees.create'): +

${h.link_to("Create a new Employee", url('employees.new'))}

+ % endif + + +${parent.body()} diff --git a/rattail/pyramid/templates/employees/new.mako b/rattail/pyramid/templates/employees/new.mako new file mode 100644 index 00000000..47d8b103 --- /dev/null +++ b/rattail/pyramid/templates/employees/new.mako @@ -0,0 +1,2 @@ +<%inherit file="/employees/crud.mako" /> +${parent.body()} diff --git a/rattail/pyramid/views/__init__.py b/rattail/pyramid/views/__init__.py index 1b36d5cb..dcdd7996 100644 --- a/rattail/pyramid/views/__init__.py +++ b/rattail/pyramid/views/__init__.py @@ -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') diff --git a/rattail/pyramid/views/employees.py b/rattail/pyramid/views/employees.py new file mode 100644 index 00000000..cf967b30 --- /dev/null +++ b/rattail/pyramid/views/employees.py @@ -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 . +# +################################################################################ + +""" +``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)