Add Excel results download for categories, report codes

also fix department field widget for categories
This commit is contained in:
Lance Edgar 2018-06-13 21:00:33 -05:00
parent b1b4e7e4ef
commit 7c46f10dd1
2 changed files with 42 additions and 3 deletions

View file

@ -28,6 +28,7 @@ from __future__ import unicode_literals, absolute_import
from rattail.db import model from rattail.db import model
from tailbone import forms
from tailbone.views import MasterView from tailbone.views import MasterView
@ -39,17 +40,16 @@ class CategoriesView(MasterView):
model_title_plural = "Categories" model_title_plural = "Categories"
route_prefix = 'categories' route_prefix = 'categories'
has_versions = True has_versions = True
results_downloadable_xlsx = True
grid_columns = [ grid_columns = [
'code', 'code',
'number',
'name', 'name',
'department', 'department',
] ]
form_fields = [ form_fields = [
'code', 'code',
'number',
'name', 'name',
'department', 'department',
] ]
@ -65,9 +65,47 @@ class CategoriesView(MasterView):
g.set_sort_defaults('code') g.set_sort_defaults('code')
g.set_link('code') g.set_link('code')
g.set_link('number')
g.set_link('name') g.set_link('name')
def get_xlsx_fields(self):
fields = super(CategoriesView, self).get_xlsx_fields()
fields.extend([
'department_number',
'department_name',
])
return fields
def get_xlsx_row(self, category, fields):
row = super(CategoriesView, self).get_xlsx_row(category, fields)
dept = category.department
if dept:
row['department_number'] = dept.number
row['department_name'] = dept.name
else:
row['department_number'] = None
row['department_name'] = None
return row
def configure_form(self, f):
super(CategoriesView, self).configure_form(f)
# department
if self.creating or self.editing:
if 'department' in f:
f.replace('department', 'department_uuid')
f.set_label('department_uuid', "Department")
dept_values = self.get_department_values()
dept_values.insert(0, ('', "(none)"))
f.set_widget('department_uuid', forms.widgets.JQuerySelectWidget(values=dept_values))
else:
f.set_readonly('department')
def get_department_values(self):
departments = self.Session.query(model.Department)\
.order_by(model.Department.number)
return [(dept.uuid, "{} {}".format(dept.number, dept.name))
for dept in departments]
def includeme(config): def includeme(config):
CategoriesView.defaults(config) CategoriesView.defaults(config)

View file

@ -38,6 +38,7 @@ class ReportCodesView(MasterView):
model_class = model.ReportCode model_class = model.ReportCode
model_title = "Report Code" model_title = "Report Code"
has_versions = True has_versions = True
results_downloadable_xlsx = True
grid_columns = [ grid_columns = [
'code', 'code',