Add more customization hooks for making grid actions in master view
This commit is contained in:
parent
dfeb14e7a8
commit
8ea379bbff
|
@ -1139,7 +1139,7 @@ class MasterView(View):
|
|||
self.request.session.flash("{} has been cloned: {}".format(
|
||||
self.get_model_title(), self.get_instance_title(instance)))
|
||||
self.request.session.flash("(NOTE, you are now viewing the clone!)")
|
||||
return self.redirect(self.get_action_url('view', cloned))
|
||||
return self.redirect_after_clone(cloned)
|
||||
return self.render_to_response('clone', {
|
||||
'instance': instance,
|
||||
'instance_title': self.get_instance_title(instance),
|
||||
|
@ -1167,6 +1167,9 @@ class MasterView(View):
|
|||
self.Session.flush()
|
||||
return cloned
|
||||
|
||||
def redirect_after_clone(self, instance, mobile=False):
|
||||
return self.redirect(self.get_action_url('view', instance, mobile=mobile))
|
||||
|
||||
def touch(self):
|
||||
"""
|
||||
View for "touching" an object so as to trigger datasync logic for it.
|
||||
|
@ -2522,12 +2525,15 @@ class MasterView(View):
|
|||
Return a list of 'main' actions for the grid.
|
||||
"""
|
||||
actions = []
|
||||
use_buefy = self.get_use_buefy()
|
||||
if self.viewable and self.has_perm('view'):
|
||||
actions.append(self.make_grid_action_view())
|
||||
return actions
|
||||
|
||||
def make_grid_action_view(self):
|
||||
use_buefy = self.get_use_buefy()
|
||||
url = self.get_view_index_url if self.use_index_links else None
|
||||
icon = 'eye' if use_buefy else 'zoomin'
|
||||
actions.append(self.make_action('view', icon=icon, url=url))
|
||||
return actions
|
||||
return self.make_action('view', icon=icon, url=url)
|
||||
|
||||
def get_view_index_url(self, row, i):
|
||||
route = '{}.view_index'.format(self.get_route_prefix())
|
||||
|
@ -2538,27 +2544,42 @@ class MasterView(View):
|
|||
Return a list of 'more' actions for the grid.
|
||||
"""
|
||||
actions = []
|
||||
use_buefy = self.get_use_buefy()
|
||||
|
||||
# Edit
|
||||
if self.editable and self.has_perm('edit'):
|
||||
icon = 'edit' if use_buefy else 'pencil'
|
||||
actions.append(self.make_action('edit', icon=icon, url=self.default_edit_url))
|
||||
actions.append(self.make_grid_action_edit())
|
||||
|
||||
# Delete
|
||||
if self.deletable and self.has_perm('delete'):
|
||||
actions.append(self.make_grid_action_delete())
|
||||
|
||||
return actions
|
||||
|
||||
def make_grid_action_edit(self):
|
||||
use_buefy = self.get_use_buefy()
|
||||
icon = 'edit' if use_buefy else 'pencil'
|
||||
return self.make_action('edit', icon=icon, url=self.default_edit_url)
|
||||
|
||||
def make_grid_action_clone(self):
|
||||
return self.make_action('clone', icon='object-ungroup',
|
||||
url=self.default_clone_url)
|
||||
|
||||
def make_grid_action_delete(self):
|
||||
use_buefy = self.get_use_buefy()
|
||||
kwargs = {}
|
||||
if use_buefy and self.delete_confirm == 'simple':
|
||||
kwargs['click_handler'] = 'deleteObject'
|
||||
actions.append(self.make_action('delete', icon='trash', url=self.default_delete_url, **kwargs))
|
||||
|
||||
return actions
|
||||
return self.make_action('delete', icon='trash', url=self.default_delete_url, **kwargs)
|
||||
|
||||
def default_edit_url(self, row, i=None):
|
||||
if self.editable_instance(row):
|
||||
return self.request.route_url('{}.edit'.format(self.get_route_prefix()),
|
||||
**self.get_action_route_kwargs(row))
|
||||
|
||||
def default_clone_url(self, row, i=None):
|
||||
return self.request.route_url('{}.clone'.format(self.get_route_prefix()),
|
||||
**self.get_action_route_kwargs(row))
|
||||
|
||||
def default_delete_url(self, row, i=None):
|
||||
if self.deletable_instance(row):
|
||||
return self.request.route_url('{}.delete'.format(self.get_route_prefix()),
|
||||
|
|
Loading…
Reference in a new issue