Add "created by" and "executed by" grid filters for all batch views

This commit is contained in:
Lance Edgar 2019-04-18 17:51:22 -05:00
parent a66ea53743
commit 1016b46243

View file

@ -2,7 +2,7 @@
################################################################################
#
# Rattail -- Retail Software Framework
# Copyright © 2010-2018 Lance Edgar
# Copyright © 2010-2019 Lance Edgar
#
# This file is part of Rattail.
#
@ -192,37 +192,39 @@ class BatchMasterView(MasterView):
def configure_grid(self, g):
super(BatchMasterView, self).configure_grid(g)
g.joiners['created_by'] = lambda q: q.join(model.User, model.User.uuid == self.model_class.created_by_uuid)
g.joiners['executed_by'] = lambda q: q.outerjoin(model.User, model.User.uuid == self.model_class.executed_by_uuid)
# created_by
CreatedBy = orm.aliased(model.User)
g.set_joiner('created_by', lambda q: q.join(CreatedBy,
CreatedBy.uuid == self.model_class.created_by_uuid))
g.set_sorter('created_by', CreatedBy.username)
g.set_filter('created_by', CreatedBy.username)
g.set_label('created_by', "Created by")
# executed
g.filters['executed'].default_active = True
g.filters['executed'].default_verb = 'is_null'
# TODO: not sure this todo is still relevant?
# TODO: in some cases grid has no sorters yet..e.g. when building query for bulk-delete
# if hasattr(g, 'sorters'):
g.sorters['created_by'] = g.make_sorter(model.User.username)
g.sorters['executed_by'] = g.make_sorter(model.User.username)
# executed_by
ExecutedBy = orm.aliased(model.User)
g.set_joiner('executed_by', lambda q: q.outerjoin(ExecutedBy,
ExecutedBy.uuid == self.model_class.executed_by_uuid))
g.set_sorter('executed_by', ExecutedBy.username)
g.set_filter('executed_by', ExecutedBy.username)
g.set_label('executed_by', "Executed by")
g.set_sort_defaults('id', 'desc')
g.set_enum('status_code', self.model_class.STATUS)
g.set_type('created', 'datetime')
g.set_type('executed', 'datetime')
g.set_renderer('id', self.render_batch_id)
g.set_link('id')
g.set_link('description')
g.set_link('created')
g.set_link('executed')
g.set_label('id', "Batch ID")
g.set_label('created_by', "Created by")
g.set_label('rowcount', "Rows")
g.set_label('status_code', "Status")
g.set_label('executed_by', "Executed by")
def render_batch_id(self, batch, column):
return batch.id_str