misc: keep track of oldest formdata when running a mass action (#47878)
This commit is contained in:
parent
ef03231782
commit
20159ae39b
|
@ -144,7 +144,7 @@ def create_environment(pub, set_receiver=True):
|
|||
for i in range(50):
|
||||
formdata = formdef.data_class()()
|
||||
formdata.just_created()
|
||||
formdata.receipt_time = datetime.datetime(2015, 1, 1).timetuple()
|
||||
formdata.receipt_time = datetime.datetime(2015, 1, 1, 0, i).timetuple()
|
||||
formdata.data = {'1': 'FOO BAR %d' % i}
|
||||
if i%4 == 0:
|
||||
formdata.data['2'] = 'foo'
|
||||
|
@ -1553,6 +1553,62 @@ def test_backoffice_multi_actions_jump(pub):
|
|||
assert formdef.data_class().get(id).status == 'wf-accepted'
|
||||
|
||||
|
||||
def test_backoffice_multi_actions_oldest_form(pub):
|
||||
create_superuser(pub)
|
||||
create_environment(pub)
|
||||
formdef = FormDef.get_by_urlname('form-title')
|
||||
|
||||
app = login(get_app(pub))
|
||||
resp = app.get('/backoffice/management/form-title/')
|
||||
assert 'id="multi-actions"' in resp.text # always there
|
||||
|
||||
workflow = Workflow.get_default_workflow()
|
||||
workflow.id = '2'
|
||||
action = workflow.add_global_action('Mark as duplicates')
|
||||
jump = action.append_item('jump')
|
||||
jump.condition = {'type': 'django', 'value': "mass_action_index != 0"}
|
||||
jump.status = 'rejected'
|
||||
|
||||
jump2 = action.append_item('jump')
|
||||
jump2.condition = {'type': 'django', 'value': "mass_action_index == 0"}
|
||||
jump2.status = 'accepted'
|
||||
|
||||
register_comment = RegisterCommenterWorkflowStatusItem()
|
||||
register_comment.id = '_comment'
|
||||
register_comment.comment = '<p>Original form: {{ oldest_form_number }}.</p>'
|
||||
assert workflow.possible_status[2].id == 'rejected'
|
||||
workflow.possible_status[2].items.append(register_comment)
|
||||
register_comment.parent = workflow.possible_status[2]
|
||||
|
||||
trigger = action.triggers[0]
|
||||
trigger.roles = [x.id for x in Role.select() if x.name == 'foobar']
|
||||
|
||||
workflow.store()
|
||||
formdef.workflow_id = workflow.id
|
||||
formdef.store()
|
||||
|
||||
resp = app.get('/backoffice/management/form-title/')
|
||||
assert 'id="multi-actions"' in resp.text
|
||||
ids = []
|
||||
for checkbox in resp.forms[0].fields['select[]'][1:6]:
|
||||
ids.append(checkbox._value)
|
||||
checkbox.checked = True
|
||||
resp = resp.forms[0].submit('button-action-1')
|
||||
assert '?job=' in resp.location
|
||||
resp = resp.follow()
|
||||
assert 'Executing task "Mark as duplicates" on forms' in resp.text
|
||||
assert '>completed<' in resp.text
|
||||
oldest_formdata = None
|
||||
for i, id in enumerate(sorted(ids, key=lambda x: int(x))):
|
||||
if i == 0:
|
||||
oldest_formdata = formdef.data_class().get(id)
|
||||
assert formdef.data_class().get(id).status == 'wf-accepted'
|
||||
else:
|
||||
assert formdef.data_class().get(id).status == 'wf-rejected'
|
||||
assert (formdef.data_class().get(id).evolution[-1].parts[0].content ==
|
||||
'<p>Original form: %s.</p>' % oldest_formdata.get_display_id())
|
||||
|
||||
|
||||
def test_backoffice_statistics_with_no_formdefs(pub):
|
||||
create_user(pub)
|
||||
create_environment(pub)
|
||||
|
|
|
@ -1956,15 +1956,25 @@ class FormPage(Directory):
|
|||
self.user = get_request().user
|
||||
|
||||
def execute(self, job=None):
|
||||
formdatas = self.formdef.data_class().get_ids(self.item_ids)
|
||||
# sort formdatas so we know for sure the processing order
|
||||
formdatas = self.formdef.data_class().get_ids(
|
||||
item_ids,
|
||||
order_by='receipt_time')
|
||||
job.completion_status = '{}/{}'.format(0, len(formdatas))
|
||||
job.store()
|
||||
publisher = get_publisher()
|
||||
if formdatas:
|
||||
oldest_lazy_form = formdatas[0].get_as_lazy()
|
||||
for i, formdata in enumerate(formdatas):
|
||||
publisher.substitutions.reset()
|
||||
publisher.substitutions.feed(publisher)
|
||||
publisher.substitutions.feed(self.formdef)
|
||||
publisher.substitutions.feed(formdata)
|
||||
publisher.substitutions.feed({
|
||||
'oldest_form': oldest_lazy_form,
|
||||
'mass_action_index': i,
|
||||
'mass_action_length': len(formdatas),
|
||||
})
|
||||
if getattr(self.action['action'], 'status_action', False):
|
||||
# manual jump action
|
||||
from wcs.wf.jump import jump_and_perform
|
||||
|
|
|
@ -841,12 +841,15 @@ class FormData(StorableObject):
|
|||
|
||||
return d
|
||||
|
||||
def get_as_lazy(self):
|
||||
from wcs.variables import LazyFormData
|
||||
return LazyFormData(self)
|
||||
|
||||
def get_substitution_variables(self, minimal=False):
|
||||
from .qommon.substitution import CompatibilityNamesDict
|
||||
from wcs.variables import LazyFormData
|
||||
from wcs.workflows import AttachmentsSubstitutionProxy
|
||||
variables = CompatibilityNamesDict({
|
||||
'form': LazyFormData(self),
|
||||
'form': self.get_as_lazy(),
|
||||
'attachments': AttachmentsSubstitutionProxy(self),
|
||||
})
|
||||
if self.formdef.category:
|
||||
|
|
|
@ -119,6 +119,9 @@ class Substitutions(object):
|
|||
return d
|
||||
d = CompatibilityNamesDict()
|
||||
for source in self.sources:
|
||||
if isinstance(source, dict):
|
||||
d.update(source)
|
||||
continue
|
||||
d.update(source.get_substitution_variables())
|
||||
if not lazy and hasattr(source, 'get_static_substitution_variables'):
|
||||
d.update(source.get_static_substitution_variables())
|
||||
|
|
Loading…
Reference in New Issue