Add basic support for cloning batches
For now only label batches support this by default
This commit is contained in:
parent
b14feae0c1
commit
c2a189cb40
|
@ -33,6 +33,9 @@
|
||||||
% if master.rows_downloadable and request.has_perm('{}.csv'.format(permission_prefix)):
|
% 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>
|
<li>${h.link_to("Download row data as CSV", url('{}.csv'.format(route_prefix), uuid=batch.uuid))}</li>
|
||||||
% endif
|
% 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>
|
||||||
|
|
||||||
<%def name="buttons()">
|
<%def name="buttons()">
|
||||||
|
|
|
@ -70,6 +70,7 @@ class BatchMasterView(MasterView):
|
||||||
refreshable = True
|
refreshable = True
|
||||||
refresh_after_create = False
|
refresh_after_create = False
|
||||||
edit_with_rows = False
|
edit_with_rows = False
|
||||||
|
cloneable = False
|
||||||
|
|
||||||
def __init__(self, request):
|
def __init__(self, request):
|
||||||
super(BatchMasterView, self).__init__(request)
|
super(BatchMasterView, self).__init__(request)
|
||||||
|
@ -825,6 +826,14 @@ class BatchMasterView(MasterView):
|
||||||
csvrow[field] = '' if value is None else unicode(value)
|
csvrow[field] = '' if value is None else unicode(value)
|
||||||
return csvrow
|
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
|
@classmethod
|
||||||
def defaults(cls, config):
|
def defaults(cls, config):
|
||||||
cls._batch_defaults(config)
|
cls._batch_defaults(config)
|
||||||
|
@ -876,6 +885,14 @@ class BatchMasterView(MasterView):
|
||||||
config.add_tailbone_permission(permission_prefix, '{}.csv'.format(permission_prefix),
|
config.add_tailbone_permission(permission_prefix, '{}.csv'.format(permission_prefix),
|
||||||
"Download {} rows as CSV".format(model_title))
|
"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):
|
class FileBatchMasterView(BatchMasterView):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -45,6 +45,7 @@ class LabelBatchView(BatchMasterView):
|
||||||
creatable = False
|
creatable = False
|
||||||
editable = False
|
editable = False
|
||||||
rows_editable = True
|
rows_editable = True
|
||||||
|
cloneable = True
|
||||||
|
|
||||||
def _preconfigure_fieldset(self, fs):
|
def _preconfigure_fieldset(self, fs):
|
||||||
super(LabelBatchView, self)._preconfigure_fieldset(fs)
|
super(LabelBatchView, self)._preconfigure_fieldset(fs)
|
||||||
|
|
Loading…
Reference in a new issue