0002-misc-keep-track-of-first-formdata-when-running-a-mas.patch
tests/backoffice_pages/test_all.py | ||
---|---|---|
154 | 154 |
for i in range(50): |
155 | 155 |
formdata = formdef.data_class()() |
156 | 156 |
formdata.just_created() |
157 |
formdata.receipt_time = datetime.datetime(2015, 1, 1).timetuple() |
|
157 |
formdata.receipt_time = datetime.datetime(2015, 1, 1, 0, i).timetuple()
|
|
158 | 158 |
formdata.data = {'1': 'FOO BAR %d' % i} |
159 | 159 |
if i%4 == 0: |
160 | 160 |
formdata.data['2'] = 'foo' |
... | ... | |
1563 | 1563 |
assert formdef.data_class().get(id).status == 'wf-accepted' |
1564 | 1564 | |
1565 | 1565 | |
1566 |
def test_backoffice_multi_actions_first_form(pub): |
|
1567 |
create_superuser(pub) |
|
1568 |
create_environment(pub) |
|
1569 |
formdef = FormDef.get_by_urlname('form-title') |
|
1570 | ||
1571 |
app = login(get_app(pub)) |
|
1572 |
resp = app.get('/backoffice/management/form-title/') |
|
1573 |
assert 'id="multi-actions"' in resp.text # always there |
|
1574 | ||
1575 |
workflow = Workflow.get_default_workflow() |
|
1576 |
workflow.id = '2' |
|
1577 |
action = workflow.add_global_action('Mark as duplicates') |
|
1578 |
jump = action.append_item('jump') |
|
1579 |
jump.condition = {'type': 'django', 'value': "mass_action_index != 0"} |
|
1580 |
jump.status = 'rejected' |
|
1581 | ||
1582 |
jump2 = action.append_item('jump') |
|
1583 |
jump2.condition = {'type': 'django', 'value': "mass_action_index == 0"} |
|
1584 |
jump2.status = 'accepted' |
|
1585 | ||
1586 |
register_comment = RegisterCommenterWorkflowStatusItem() |
|
1587 |
register_comment.id = '_comment' |
|
1588 |
register_comment.comment = '<p>Original form: {{ first_form_number }}.</p>' |
|
1589 |
assert workflow.possible_status[2].id == 'rejected' |
|
1590 |
workflow.possible_status[2].items.append(register_comment) |
|
1591 |
register_comment.parent = workflow.possible_status[2] |
|
1592 | ||
1593 |
trigger = action.triggers[0] |
|
1594 |
trigger.roles = [x.id for x in Role.select() if x.name == 'foobar'] |
|
1595 | ||
1596 |
workflow.store() |
|
1597 |
formdef.workflow_id = workflow.id |
|
1598 |
formdef.store() |
|
1599 | ||
1600 |
resp = app.get('/backoffice/management/form-title/') |
|
1601 |
assert 'id="multi-actions"' in resp.text |
|
1602 |
ids = [] |
|
1603 |
for checkbox in resp.forms[0].fields['select[]'][1:6]: |
|
1604 |
ids.append(checkbox._value) |
|
1605 |
checkbox.checked = True |
|
1606 |
resp = resp.forms[0].submit('button-action-1') |
|
1607 |
assert '?job=' in resp.location |
|
1608 |
resp = resp.follow() |
|
1609 |
assert 'Executing task "Mark as duplicates" on forms' in resp.text |
|
1610 |
assert '>completed<' in resp.text |
|
1611 |
first_formdata = None |
|
1612 |
for i, id in enumerate(sorted(ids, key=lambda x: int(x))): |
|
1613 |
if i == 0: |
|
1614 |
first_formdata = formdef.data_class().get(id) |
|
1615 |
assert formdef.data_class().get(id).status == 'wf-accepted' |
|
1616 |
else: |
|
1617 |
assert formdef.data_class().get(id).status == 'wf-rejected' |
|
1618 |
assert (formdef.data_class().get(id).evolution[-1].parts[0].content == |
|
1619 |
'<p>Original form: %s.</p>' % first_formdata.get_display_id()) |
|
1620 | ||
1621 | ||
1566 | 1622 |
def test_backoffice_statistics_with_no_formdefs(pub): |
1567 | 1623 |
create_user(pub) |
1568 | 1624 |
create_environment(pub) |
wcs/backoffice/management.py | ||
---|---|---|
1959 | 1959 |
self.user = get_request().user |
1960 | 1960 | |
1961 | 1961 |
def execute(self, job=None): |
1962 |
formdatas = self.formdef.data_class().get_ids(self.item_ids) |
|
1962 |
# sort formdatas so we know for sure the processing order |
|
1963 |
formdatas = self.formdef.data_class().get_ids( |
|
1964 |
item_ids, |
|
1965 |
order_by='receipt_time') |
|
1963 | 1966 |
job.completion_status = '{}/{}'.format(0, len(formdatas)) |
1964 | 1967 |
job.store() |
1965 | 1968 |
publisher = get_publisher() |
1969 |
if formdatas: |
|
1970 |
first_lazy_form = formdatas[0].get_as_lazy() |
|
1966 | 1971 |
for i, formdata in enumerate(formdatas): |
1967 | 1972 |
publisher.substitutions.reset() |
1968 | 1973 |
publisher.substitutions.feed(publisher) |
1969 | 1974 |
publisher.substitutions.feed(self.formdef) |
1970 | 1975 |
publisher.substitutions.feed(formdata) |
1976 |
publisher.substitutions.feed({ |
|
1977 |
'first_form': first_lazy_form, |
|
1978 |
'mass_action_index': i, |
|
1979 |
'mass_action_length': len(formdatas), |
|
1980 |
}) |
|
1971 | 1981 |
if getattr(self.action['action'], 'status_action', False): |
1972 | 1982 |
# manual jump action |
1973 | 1983 |
from wcs.wf.jump import jump_and_perform |
wcs/formdata.py | ||
---|---|---|
841 | 841 | |
842 | 842 |
return d |
843 | 843 | |
844 |
def get_as_lazy(self): |
|
845 |
from wcs.variables import LazyFormData |
|
846 |
return LazyFormData(self) |
|
847 | ||
844 | 848 |
def get_substitution_variables(self, minimal=False): |
845 | 849 |
from .qommon.substitution import CompatibilityNamesDict |
846 |
from wcs.variables import LazyFormData |
|
847 | 850 |
from wcs.workflows import AttachmentsSubstitutionProxy |
848 | 851 |
variables = CompatibilityNamesDict({ |
849 |
'form': LazyFormData(self),
|
|
852 |
'form': self.get_as_lazy(),
|
|
850 | 853 |
'attachments': AttachmentsSubstitutionProxy(self), |
851 | 854 |
}) |
852 | 855 |
if self.formdef.category: |
wcs/qommon/substitution.py | ||
---|---|---|
119 | 119 |
return d |
120 | 120 |
d = CompatibilityNamesDict() |
121 | 121 |
for source in self.sources: |
122 |
if isinstance(source, dict): |
|
123 |
d.update(source) |
|
124 |
continue |
|
122 | 125 |
d.update(source.get_substitution_variables()) |
123 | 126 |
if not lazy and hasattr(source, 'get_static_substitution_variables'): |
124 | 127 |
d.update(source.get_static_substitution_variables()) |
125 |
- |