Add employee/department relationships to employee and department views.

This commit is contained in:
Lance Edgar 2016-01-17 19:45:42 -06:00
parent aafaf64640
commit 973b9903ae
4 changed files with 75 additions and 3 deletions

View file

@ -0,0 +1,13 @@
## -*- coding: utf-8 -*-
<%inherit file="/master/view.mako" />
${parent.body()}
<h2>Employees</h2>
% if employees:
<p>The following employees are assigned to this department:</p>
${employees.render_grid()|n}
% else:
<p>No employees are assigned to this department.</p>
% endif

View file

@ -0,0 +1,13 @@
## -*- coding: utf-8 -*-
<%inherit file="/master/view.mako" />
${parent.body()}
<h2>Departments</h2>
% if departments:
<p>This employee is assigned to the following departments:</p>
${departments.render_grid()|n}
% else:
<p>This employee is not assigned to any departments.</p>
% endif

View file

@ -2,7 +2,7 @@
################################################################################ ################################################################################
# #
# Rattail -- Retail Software Framework # Rattail -- Retail Software Framework
# Copyright © 2010-2015 Lance Edgar # Copyright © 2010-2016 Lance Edgar
# #
# This file is part of Rattail. # This file is part of Rattail.
# #
@ -24,12 +24,13 @@
Department Views Department Views
""" """
from __future__ import unicode_literals from __future__ import unicode_literals, absolute_import
from rattail.db import model from rattail.db import model
from tailbone.views import MasterView, AutocompleteView, AlchemyGridView from tailbone.views import MasterView, AutocompleteView, AlchemyGridView
from tailbone.views.continuum import VersionView, version_defaults from tailbone.views.continuum import VersionView, version_defaults
from tailbone.newgrids import AlchemyGrid, GridAction
class DepartmentsView(MasterView): class DepartmentsView(MasterView):
@ -57,6 +58,28 @@ class DepartmentsView(MasterView):
]) ])
return fs 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): class DepartmentVersionView(VersionView):
""" """

View file

@ -2,7 +2,7 @@
################################################################################ ################################################################################
# #
# Rattail -- Retail Software Framework # Rattail -- Retail Software Framework
# Copyright © 2010-2015 Lance Edgar # Copyright © 2010-2016 Lance Edgar
# #
# This file is part of Rattail. # This file is part of Rattail.
# #
@ -33,6 +33,7 @@ from rattail.db import model
from tailbone import forms from tailbone import forms
from tailbone.views import MasterView, AutocompleteView from tailbone.views import MasterView, AutocompleteView
from tailbone.newgrids import AlchemyGrid, GridAction
from tailbone.newgrids.filters import EnumValueRenderer from tailbone.newgrids.filters import EnumValueRenderer
@ -122,6 +123,28 @@ class EmployeesView(MasterView):
fs.status.with_renderer(forms.EnumFieldRenderer(enum.EMPLOYEE_STATUS)), 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): class EmployeesAutocomplete(AutocompleteView):
""" """