Refactor away the row_route_prefix concept

This commit is contained in:
Lance Edgar 2018-01-06 20:25:55 -06:00
parent 22b8643def
commit 85e6e7e08a
3 changed files with 22 additions and 28 deletions

View file

@ -8,5 +8,5 @@
${parent.body()}
% if master.mobile_rows_editable and instance_editable and request.has_perm('{}.edit_row'.format(permission_prefix)):
${h.link_to("Edit", url('mobile.{}.edit'.format(row_route_prefix), uuid=instance.uuid), class_='ui-btn')}
${h.link_to("Edit", url('mobile.{}.edit_row'.format(route_prefix), uuid=instance.uuid), class_='ui-btn')}
% endif

View file

@ -618,7 +618,7 @@ class MasterView(View):
renderer=self.mobile_row_listitem_renderer())
def mobile_row_route_url(self, route_name, **kwargs):
route_name = 'mobile.{}.{}'.format(self.get_row_route_prefix(), route_name)
route_name = 'mobile.{}.{}_row'.format(self.get_route_prefix(), route_name)
return self.request.route_url(route_name, **kwargs)
def mobile_view_row(self):
@ -679,14 +679,6 @@ class MasterView(View):
grid = self.make_row_grid(session=session, **kwargs)
return grid.make_visible_data()
@classmethod
def get_row_route_prefix(cls):
"""
Route prefix specific to the row-level views for a batch, e.g.
``'vendorcatalogs.rows'``.
"""
return "{}.rows".format(cls.get_route_prefix())
@classmethod
def get_row_url_prefix(cls):
"""
@ -1221,7 +1213,6 @@ class MasterView(View):
context['grid_count'] = self.grid_count
if self.has_rows:
context['row_route_prefix'] = self.get_row_route_prefix()
context['row_permission_prefix'] = self.get_row_permission_prefix()
context['row_model_title'] = self.get_row_model_title()
context['row_model_title_plural'] = self.get_row_model_title_plural()
@ -1842,7 +1833,7 @@ class MasterView(View):
"""
"Delete" a sub-row from the parent.
"""
row = self.Session.query(self.model_row_class).get(self.request.matchdict['uuid'])
row = self.Session.query(self.model_row_class).get(self.request.matchdict['row_uuid'])
if not row:
raise httpexceptions.HTTPNotFound()
self.Session.delete(row)
@ -1855,7 +1846,9 @@ class MasterView(View):
return self.get_row_model_title()
def get_row_instance(self):
key = self.request.matchdict[self.get_model_key()]
# TODO: is this right..?
# key = self.request.matchdict[self.get_model_key()]
key = self.request.matchdict['row_uuid']
instance = self.Session.query(self.model_row_class).get(key)
if not instance:
raise httpexceptions.HTTPNotFound()
@ -1897,7 +1890,7 @@ class MasterView(View):
"""
Generate a URL for the given action on the given row.
"""
route_name = '{}.{}'.format(self.get_row_route_prefix(), action)
route_name = '{}.{}_row'.format(self.get_route_prefix(), action)
if mobile:
route_name = 'mobile.{}'.format(route_name)
return self.request.route_url(route_name, **self.get_row_action_route_kwargs(row))
@ -1907,7 +1900,11 @@ class MasterView(View):
Hopefully generic kwarg generator for basic action routes.
"""
# TODO: make this smarter?
return {'uuid': row.uuid}
parent = self.get_parent(row)
return {
'uuid': parent.uuid,
'row_uuid': row.uuid,
}
def make_diff(self, old_data, new_data, **kwargs):
return diffs.Diff(old_data, new_data, **kwargs)
@ -1936,8 +1933,6 @@ class MasterView(View):
model_title = cls.get_model_title()
model_title_plural = cls.get_model_title_plural()
if cls.has_rows:
row_route_prefix = cls.get_row_route_prefix()
row_url_prefix = cls.get_row_url_prefix()
row_model_title = cls.get_row_model_title()
config.add_tailbone_permission_group(permission_prefix, model_title_plural, overwrite=False)
@ -2097,12 +2092,12 @@ class MasterView(View):
# view row
if cls.has_rows:
if cls.rows_viewable:
config.add_route('{}.view'.format(row_route_prefix), '{}/{{uuid}}'.format(row_url_prefix))
config.add_view(cls, attr='view_row', route_name='{}.view'.format(row_route_prefix),
config.add_route('{}.view_row'.format(route_prefix), '{}/{{uuid}}/rows/{{row_uuid}}'.format(url_prefix))
config.add_view(cls, attr='view_row', route_name='{}.view_row'.format(route_prefix),
permission='{}.view'.format(permission_prefix))
if cls.mobile_rows_viewable:
config.add_route('mobile.{}.view'.format(row_route_prefix), '/mobile{}/{{uuid}}'.format(row_url_prefix))
config.add_view(cls, attr='mobile_view_row', route_name='mobile.{}.view'.format(row_route_prefix),
config.add_route('mobile.{}.view_row'.format(route_prefix), '/mobile{}/{{uuid}}/rows/{{row_uuid}}'.format(url_prefix))
config.add_view(cls, attr='mobile_view_row', route_name='mobile.{}.view_row'.format(route_prefix),
permission='{}.view'.format(permission_prefix))
# edit row
@ -2111,18 +2106,18 @@ class MasterView(View):
config.add_tailbone_permission(permission_prefix, '{}.edit_row'.format(permission_prefix),
"Edit individual {} rows".format(model_title))
if cls.rows_editable:
config.add_route('{}.edit'.format(row_route_prefix), '{}/{{uuid}}/edit'.format(row_url_prefix))
config.add_view(cls, attr='edit_row', route_name='{}.edit'.format(row_route_prefix),
config.add_route('{}.edit_row'.format(route_prefix), '{}/{{uuid}}/rows/{{row_uuid}}/edit'.format(url_prefix))
config.add_view(cls, attr='edit_row', route_name='{}.edit_row'.format(route_prefix),
permission='{}.edit_row'.format(permission_prefix))
if cls.mobile_rows_editable:
config.add_route('mobile.{}.edit'.format(row_route_prefix), '/mobile{}/{{uuid}}/edit'.format(row_url_prefix))
config.add_view(cls, attr='mobile_edit_row', route_name='mobile.{}.edit'.format(row_route_prefix),
config.add_route('mobile.{}.edit_row'.format(route_prefix), '/mobile{}/{{uuid}}/rows/{{row_uuid}}/edit'.format(url_prefix))
config.add_view(cls, attr='mobile_edit_row', route_name='mobile.{}.edit_row'.format(route_prefix),
permission='{}.edit_row'.format(permission_prefix))
# delete row
if cls.has_rows and cls.rows_deletable:
config.add_route('{}.delete'.format(row_route_prefix), '{}/{{uuid}}/delete'.format(row_url_prefix))
config.add_view(cls, attr='delete_row', route_name='{}.delete'.format(row_route_prefix),
config.add_route('{}.delete_row'.format(route_prefix), '{}/{{uuid}}/rows/{{row_uuid}}/delete'.format(url_prefix))
config.add_view(cls, attr='delete_row', route_name='{}.delete_row'.format(route_prefix),
permission='{}.delete_row'.format(permission_prefix))
config.add_tailbone_permission(permission_prefix, '{}.delete_row'.format(permission_prefix),
"Delete individual {} rows".format(model_title))

View file

@ -271,7 +271,6 @@ class MasterView2(MasterView):
"""
Return a dict of kwargs to be used when constructing a new rows grid.
"""
route_prefix = self.get_row_route_prefix()
permission_prefix = self.get_permission_prefix()
defaults = {