Add ability to view details (i.e. all fields) of a batch row.

This commit is contained in:
Lance Edgar 2015-03-19 01:25:38 -05:00
parent be41d0bb1e
commit 8285993fa6
4 changed files with 82 additions and 12 deletions

View file

@ -0,0 +1,10 @@
## -*- coding: utf-8 -*-
<%inherit file="/crud.mako" />
<%def name="title()">${batch_display} Row</%def>
<%def name="context_menu_items()">
<li>${h.link_to("Back to {0}".format(batch_display), url('{0}.view'.format(route_prefix), uuid=row.batch_uuid))}</li>
</%def>
${parent.body()}

View file

@ -0,0 +1,3 @@
## -*- coding: utf-8 -*-
<%inherit file="/batch/row.view.mako" />
${parent.body()}

View file

@ -147,10 +147,19 @@ class BatchGrid(BaseGrid):
def mapped_class(self): def mapped_class(self):
return self.batch_class return self.batch_class
@property
def batch_display(self):
"""
Singular display text for the batch type, e.g. "Vendor Invoice".
Override this as necessary.
"""
return self.batch_class.__name__
@property @property
def batch_display_plural(self): def batch_display_plural(self):
""" """
Plural display text for the batch type. Plural display text for the batch type, e.g. "Vendor Invoices".
Override this as necessary.
""" """
return "{0}s".format(self.batch_display) return "{0}s".format(self.batch_display)
@ -311,6 +320,13 @@ class BaseCrud(CrudView):
""" """
flash = {} flash = {}
@property
def home_route(self):
"""
The "home" route for the batch type, i.e. its grid view.
"""
return self.route_prefix
@property @property
def permission_prefix(self): def permission_prefix(self):
""" """
@ -362,13 +378,6 @@ class BatchCrud(BaseCrud):
""" """
return self.route_prefix return self.route_prefix
@property
def home_route(self):
"""
The "home" route for the batch type, i.e. its grid view.
"""
return self.route_prefix
@property @property
def batch_display_plural(self): def batch_display_plural(self):
""" """
@ -780,12 +789,26 @@ class BatchRowGrid(BaseGrid):
return '{0}.{1}'.format(self.mapped_class.__name__.lower(), return '{0}.{1}'.format(self.mapped_class.__name__.lower(),
self.request.matchdict['uuid']) self.request.matchdict['uuid'])
@property
def batch_class(self):
"""
Model class of the batch to which the rows belong.
"""
return self.row_class.__batch_class__
@property
def batch_display(self):
"""
Singular display text for the batch type, e.g. "Vendor Invoice".
Override this as necessary.
"""
return self.batch_class.__name__
def current_batch(self): def current_batch(self):
""" """
Return the current batch, based on the UUID within the URL. Return the current batch, based on the UUID within the URL.
""" """
batch_class = self.row_class.__batch_class__ return Session.query(self.batch_class).get(self.request.matchdict['uuid'])
return Session.query(batch_class).get(self.request.matchdict['uuid'])
def modify_query(self, q): def modify_query(self, q):
q = super(BatchRowGrid, self).modify_query(q) q = super(BatchRowGrid, self).modify_query(q)
@ -849,8 +872,8 @@ class BatchRowGrid(BaseGrid):
self.configure_grid(g) self.configure_grid(g)
batch = self.current_batch() batch = self.current_batch()
# g.viewable = True g.viewable = True
# g.view_route_name = '{0}.rows.view'.format(self.route_prefix) g.view_route_name = '{0}.row.view'.format(self.route_prefix)
# TODO: Fix this check for edit mode. # TODO: Fix this check for edit mode.
edit_mode = self.request.referrer.endswith('/edit') edit_mode = self.request.referrer.endswith('/edit')
if edit_mode and not batch.executed and self.request.has_perm('{0}.edit'.format(self.permission_prefix)): if edit_mode and not batch.executed and self.request.has_perm('{0}.edit'.format(self.permission_prefix)):
@ -922,6 +945,33 @@ class BatchRowCrud(BaseCrud):
def mapped_class(self): def mapped_class(self):
return self.row_class return self.row_class
@property
def batch_class(self):
"""
Model class of the batch to which the rows belong.
"""
return self.row_class.__batch_class__
@property
def batch_display(self):
"""
Singular display text for the batch type, e.g. "Vendor Invoice".
Override this as necessary.
"""
return self.batch_class.__name__
def template_kwargs(self, form):
"""
Add batch row instance etc. to template context.
"""
row = form.fieldset.model
return {
'row': row,
'batch_display': self.batch_display,
'route_prefix': self.route_prefix,
'permission_prefix': self.permission_prefix,
}
def delete(self): def delete(self):
""" """
"Delete" a row from the batch. This sets the ``removed`` flag on the "Delete" a row from the batch. This sets the ``removed`` flag on the
@ -1003,6 +1053,12 @@ def defaults(config, batch_grid, batch_crud, row_grid, row_crud, url_prefix,
renderer='/batch/rows.mako', renderer='/batch/rows.mako',
permission='{0}.view'.format(permission_prefix)) permission='{0}.view'.format(permission_prefix))
# view batch row
config.add_route('{0}.row.view'.format(route_prefix), '{0}row/{{uuid}}'.format(url_prefix))
config.add_view(row_crud, attr='read', route_name='{0}.row.view'.format(route_prefix),
renderer='{0}/row.view.mako'.format(template_prefix),
permission='{0}.view'.format(permission_prefix))
# Bulk delete batch rows # Bulk delete batch rows
config.add_route('{0}.rows.bulk_delete'.format(route_prefix), '{0}{{uuid}}/rows/delete'.format(url_prefix)) config.add_route('{0}.rows.bulk_delete'.format(route_prefix), '{0}{{uuid}}/rows/delete'.format(url_prefix))
config.add_view(row_grid, attr='bulk_delete', route_name='{0}.rows.bulk_delete'.format(route_prefix), config.add_view(row_grid, attr='bulk_delete', route_name='{0}.rows.bulk_delete'.format(route_prefix),

View file

@ -198,6 +198,7 @@ class VendorInvoiceRowGrid(BatchRowGrid):
class VendorInvoiceRowCrud(BatchRowCrud): class VendorInvoiceRowCrud(BatchRowCrud):
row_class = VendorInvoiceRow row_class = VendorInvoiceRow
route_prefix = 'vendors.invoices' route_prefix = 'vendors.invoices'
batch_display = "Vendor Invoice"
def includeme(config): def includeme(config):