0002-export-workflow-in-formdef-json-exports-fixes-9849.patch
help/fr/api-schema.page | ||
---|---|---|
179 | 179 |
"type": "email", |
180 | 180 |
"varname": "email" |
181 | 181 |
} |
182 |
] |
|
182 |
], |
|
183 |
"workflow": { |
|
184 |
"name": "Workflow Newsletter", |
|
185 |
"id": "_default", |
|
186 |
"last_modification_time": "2015-12-12T10:20:45", |
|
187 |
"statuses": { |
|
188 |
"1": { |
|
189 |
"name": "Nouveau", |
|
190 |
"forced_endpoint": false |
|
191 |
}, |
|
192 |
"2": { |
|
193 |
"name": "En cours", |
|
194 |
"forced_endpoint": false |
|
195 |
}, |
|
196 |
"3": { |
|
197 |
"name": "Terminé", |
|
198 |
"forced_endpoint": false |
|
199 |
} |
|
200 |
} |
|
201 |
} |
|
183 | 202 |
} |
184 | 203 |
</code> |
185 | 204 |
tests/test_api.py | ||
---|---|---|
8 | 8 |
import urlparse |
9 | 9 |
import datetime |
10 | 10 |
import time |
11 |
import json |
|
11 | 12 | |
12 | 13 |
from quixote import cleanup, get_publisher |
13 | 14 |
from wcs.qommon.http_request import HTTPRequest |
... | ... | |
820 | 821 |
formdata.store() # (will get back to wf-st1) |
821 | 822 |
resp = get_app(pub).post(sign_uri(formdata.get_url() + 'jump/trigger/XXX'), |
822 | 823 |
status=403) |
824 | ||
825 |
def test_formdefs_api(pub, local_user): |
|
826 |
workflow = Workflow(name='test') |
|
827 |
st1 = workflow.add_status('Status1', 'st1') |
|
828 |
st2 = workflow.add_status('Status2', 'st2') |
|
829 |
workflow.store() |
|
830 | ||
831 |
FormDef.wipe() |
|
832 |
formdef = FormDef() |
|
833 |
formdef.name = 'test' |
|
834 |
formdef.fields = [] |
|
835 |
formdef.workflow_id = workflow.id |
|
836 |
formdef.store() |
|
837 | ||
838 |
resp = get_app(pub).get(sign_uri('/api/formdefs/test/schema', user=local_user)) |
|
839 |
assert set(resp.json.keys()) >= set(['enable_tracking_codes', 'url_name', 'description', |
|
840 |
'workflow', 'expiration_date', 'discussion', |
|
841 |
'last_modification_time', 'has_captcha', |
|
842 |
'always_advertise', 'name', 'disabled', 'only_allow_one', |
|
843 |
'private_status_and_history', 'fields', 'keywords', |
|
844 |
'publication_date', 'detailed_emails', |
|
845 |
'disabled_redirection']) |
|
846 |
assert len(resp.json['workflow']['statuses']) == 2 |
wcs/formdef.py | ||
---|---|---|
523 | 523 |
root['category'] = unicode(self.category.name, charset) |
524 | 524 |
root['category_id'] = str(self.category.id) |
525 | 525 |
if self.workflow: |
526 |
root['workflow'] = unicode(self.workflow.name, charset) |
|
527 |
root['workflow_id'] = str(self.workflow.id) |
|
526 |
root['workflow'] = self.workflow.to_dict(include_id=include_id) |
|
528 | 527 | |
529 | 528 |
if self.max_field_id is None and self.fields: |
530 | 529 |
self.max_field_id = max([lax_int(x.id) for x in self.fields]) |
... | ... | |
587 | 586 | |
588 | 587 |
if include_id and 'workflow_id' in value: |
589 | 588 |
formdef.workflow_id = value.get('workflow_id') |
589 |
elif (include_id |
|
590 |
and 'workflow' in value |
|
591 |
and isinstance(value['workflow'], dict) |
|
592 |
and 'id' in value['workflow']): |
|
593 |
formdef.workflow_id = value['workflow'].get('id') |
|
590 | 594 |
elif 'workflow' in value: |
591 |
workflow = value.get('workflow') |
|
595 |
if isinstance(value['workflow'], basestring): |
|
596 |
workflow = value.get('workflow') |
|
597 |
else: |
|
598 |
workflow = value['workflow'].get('name') |
|
592 | 599 |
from wcs.workflows import Workflow |
593 | 600 |
for w in Workflow.select(): |
594 | 601 |
if w.name == workflow: |
595 |
- |