diff --git a/tailbone/templates/newbatch/view.mako b/tailbone/templates/newbatch/view.mako index 20d12dd8..d702ced3 100644 --- a/tailbone/templates/newbatch/view.mako +++ b/tailbone/templates/newbatch/view.mako @@ -33,6 +33,9 @@ % if master.rows_downloadable and request.has_perm('{}.csv'.format(permission_prefix)):
  • ${h.link_to("Download row data as CSV", url('{}.csv'.format(route_prefix), uuid=batch.uuid))}
  • % endif + % if master.cloneable and request.has_perm('{}.clone'.format(permission_prefix)): +
  • ${h.link_to("Clone as new batch", url('{}.clone'.format(route_prefix), uuid=batch.uuid))}
  • + % endif <%def name="buttons()"> diff --git a/tailbone/views/batch/core.py b/tailbone/views/batch/core.py index 3ac8c24e..de95c068 100644 --- a/tailbone/views/batch/core.py +++ b/tailbone/views/batch/core.py @@ -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): """ diff --git a/tailbone/views/labels/batch.py b/tailbone/views/labels/batch.py index 8c3f06d2..10fbbf41 100644 --- a/tailbone/views/labels/batch.py +++ b/tailbone/views/labels/batch.py @@ -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)