diff --git a/tailbone/templates/departments/view.mako b/tailbone/templates/departments/view.mako new file mode 100644 index 00000000..573e0212 --- /dev/null +++ b/tailbone/templates/departments/view.mako @@ -0,0 +1,13 @@ +## -*- coding: utf-8 -*- +<%inherit file="/master/view.mako" /> + +${parent.body()} + +
The following employees are assigned to this department:
+ ${employees.render_grid()|n} +% else: +No employees are assigned to this department.
+% endif diff --git a/tailbone/templates/employees/view.mako b/tailbone/templates/employees/view.mako new file mode 100644 index 00000000..b02aaae7 --- /dev/null +++ b/tailbone/templates/employees/view.mako @@ -0,0 +1,13 @@ +## -*- coding: utf-8 -*- +<%inherit file="/master/view.mako" /> + +${parent.body()} + +This employee is assigned to the following departments:
+ ${departments.render_grid()|n} +% else: +This employee is not assigned to any departments.
+% endif diff --git a/tailbone/views/departments.py b/tailbone/views/departments.py index c636dbc4..42913266 100644 --- a/tailbone/views/departments.py +++ b/tailbone/views/departments.py @@ -2,7 +2,7 @@ ################################################################################ # # Rattail -- Retail Software Framework -# Copyright © 2010-2015 Lance Edgar +# Copyright © 2010-2016 Lance Edgar # # This file is part of Rattail. # @@ -24,12 +24,13 @@ Department Views """ -from __future__ import unicode_literals +from __future__ import unicode_literals, absolute_import from rattail.db import model from tailbone.views import MasterView, AutocompleteView, AlchemyGridView from tailbone.views.continuum import VersionView, version_defaults +from tailbone.newgrids import AlchemyGrid, GridAction class DepartmentsView(MasterView): @@ -57,6 +58,28 @@ class DepartmentsView(MasterView): ]) return fs + def template_kwargs_view(self, **kwargs): + department = kwargs['instance'] + if department.employees: + + # TODO: This is the second attempt (after role.users) at using a + # new grid outside of the context of a primary master grid. The + # API here is really much hairier than I'd like... Looks like we + # shouldn't need a key for this one, for instance (no settings + # required), but there is plenty of room for improvement here. + employees = sorted(department.employees, key=unicode) + employees = AlchemyGrid('departments.employees', self.request, data=employees, model_class=model.Employee, + main_actions=[ + GridAction('view', icon='zoomin', + url=lambda x: self.request.route_url('employees.view', uuid=x.uuid)), + ]) + employees.configure(include=[employees.display_name], readonly=True) + kwargs['employees'] = employees + + else: + kwargs['employees'] = None + return kwargs + class DepartmentVersionView(VersionView): """ diff --git a/tailbone/views/employees.py b/tailbone/views/employees.py index 65c40121..3ac6f6d1 100644 --- a/tailbone/views/employees.py +++ b/tailbone/views/employees.py @@ -2,7 +2,7 @@ ################################################################################ # # Rattail -- Retail Software Framework -# Copyright © 2010-2015 Lance Edgar +# Copyright © 2010-2016 Lance Edgar # # This file is part of Rattail. # @@ -33,6 +33,7 @@ from rattail.db import model from tailbone import forms from tailbone.views import MasterView, AutocompleteView +from tailbone.newgrids import AlchemyGrid, GridAction from tailbone.newgrids.filters import EnumValueRenderer @@ -122,6 +123,28 @@ class EmployeesView(MasterView): fs.status.with_renderer(forms.EnumFieldRenderer(enum.EMPLOYEE_STATUS)), ]) + def template_kwargs_view(self, **kwargs): + employee = kwargs['instance'] + if employee.departments: + + # TODO: This is the second attempt (after role.users) at using a + # new grid outside of the context of a primary master grid. The + # API here is really much hairier than I'd like... Looks like we + # shouldn't need a key for this one, for instance (no settings + # required), but there is plenty of room for improvement here. + departments = sorted(employee.departments, key=unicode) + departments = AlchemyGrid('employees.departments', self.request, data=departments, model_class=model.Department, + main_actions=[ + GridAction('view', icon='zoomin', + url=lambda d: self.request.route_url('departments.view', uuid=d.uuid)), + ]) + departments.configure(include=[departments.name], readonly=True) + kwargs['departments'] = departments + + else: + kwargs['departments'] = None + return kwargs + class EmployeesAutocomplete(AutocompleteView): """