Filter by person instead of user, for Generated Reports "Created by"

This commit is contained in:
Lance Edgar 2022-12-25 12:45:23 -06:00
parent b04c1054fc
commit cd466a64e5

View file

@ -31,12 +31,9 @@ import shutil
import six import six
from rattail.db import model
from pyramid.response import FileResponse from pyramid.response import FileResponse
from webhelpers2.html import HTML, tags from webhelpers2.html import tags
from tailbone import forms
from tailbone.views import MasterView from tailbone.views import MasterView
@ -49,6 +46,11 @@ class ExportMasterView(MasterView):
downloadable = False downloadable = False
delete_export_files = False delete_export_files = False
labels = {
'id': "ID",
'created_by': "Created by",
}
grid_columns = [ grid_columns = [
'id', 'id',
'created', 'created',
@ -82,19 +84,23 @@ class ExportMasterView(MasterView):
def configure_grid(self, g): def configure_grid(self, g):
super(ExportMasterView, self).configure_grid(g) super(ExportMasterView, self).configure_grid(g)
model = self.model
g.joiners['created_by'] = lambda q: q.join(model.User) # id
g.sorters['created_by'] = g.make_sorter(model.User.username) g.set_renderer('id', self.render_id)
g.filters['created_by'] = g.make_filter('created_by', model.User.username) g.set_link('id')
# filename
g.set_link('filename')
# created
g.set_sort_defaults('created', 'desc') g.set_sort_defaults('created', 'desc')
g.set_renderer('id', self.render_id) # created_by
g.set_joiner('created_by',
g.set_label('id', "ID") lambda q: q.join(model.User).outerjoin(model.Person))
g.set_label('created_by', "Created by") g.set_sorter('created_by', model.Person.display_name)
g.set_filter('created_by', model.Person.display_name)
g.set_link('id')
g.set_link('filename')
def render_id(self, export, field): def render_id(self, export, field):
return export.id_str return export.id_str