Add basic support for cloning batches

For now only label batches support this by default
This commit is contained in:
Lance Edgar 2017-01-24 21:36:58 -06:00
parent b14feae0c1
commit c2a189cb40
3 changed files with 21 additions and 0 deletions

View file

@ -33,6 +33,9 @@
% if master.rows_downloadable and request.has_perm('{}.csv'.format(permission_prefix)):
<li>${h.link_to("Download row data as CSV", url('{}.csv'.format(route_prefix), uuid=batch.uuid))}</li>
% endif
% if master.cloneable and request.has_perm('{}.clone'.format(permission_prefix)):
<li>${h.link_to("Clone as new batch", url('{}.clone'.format(route_prefix), uuid=batch.uuid))}</li>
% endif
</%def>
<%def name="buttons()">

View file

@ -70,6 +70,7 @@ class BatchMasterView(MasterView):
refreshable = True
refresh_after_create = False
edit_with_rows = False
cloneable = False
def __init__(self, request):
super(BatchMasterView, self).__init__(request)
@ -825,6 +826,14 @@ class BatchMasterView(MasterView):
csvrow[field] = '' if value is None else unicode(value)
return csvrow
def clone(self):
"""
Clone current batch as new batch
"""
batch = self.get_instance()
batch = self.handler.clone(batch, created_by=self.request.user)
return self.redirect(self.get_action_url('view', batch))
@classmethod
def defaults(cls, config):
cls._batch_defaults(config)
@ -876,6 +885,14 @@ class BatchMasterView(MasterView):
config.add_tailbone_permission(permission_prefix, '{}.csv'.format(permission_prefix),
"Download {} rows as CSV".format(model_title))
# clone as new batch
if cls.cloneable:
config.add_route('{}.clone'.format(route_prefix), '{}/{{uuid}}/clone'.format(url_prefix))
config.add_view(cls, attr='clone', route_name='{}.clone'.format(route_prefix),
permission='{}.clone'.format(permission_prefix))
config.add_tailbone_permission(permission_prefix, '{}.clone'.format(permission_prefix),
"Clone {} as new batch".format(model_title))
class FileBatchMasterView(BatchMasterView):
"""

View file

@ -45,6 +45,7 @@ class LabelBatchView(BatchMasterView):
creatable = False
editable = False
rows_editable = True
cloneable = True
def _preconfigure_fieldset(self, fs):
super(LabelBatchView, self)._preconfigure_fieldset(fs)