0002-api-comment-template-dependencies-39178.patch
tests/api/test_export_import.py | ||
---|---|---|
12 | 12 |
BlockCategory, |
13 | 13 |
CardDefCategory, |
14 | 14 |
Category, |
15 |
CommentTemplateCategory, |
|
15 | 16 |
DataSourceCategory, |
16 | 17 |
MailTemplateCategory, |
17 | 18 |
WorkflowCategory, |
18 | 19 |
) |
20 |
from wcs.comment_templates import CommentTemplate |
|
19 | 21 |
from wcs.data_sources import NamedDataSource |
20 | 22 |
from wcs.fields import BlockField, CommentField, PageField, StringField |
21 | 23 |
from wcs.formdef import FormDef |
... | ... | |
49 | 51 |
Workflow.wipe() |
50 | 52 |
MailTemplateCategory.wipe() |
51 | 53 |
MailTemplate.wipe() |
54 |
CommentTemplateCategory.wipe() |
|
55 |
CommentTemplate.wipe() |
|
52 | 56 |
DataSourceCategory.wipe() |
53 | 57 |
NamedDataSource.wipe() |
54 | 58 |
NamedWsCall.wipe() |
... | ... | |
132 | 136 |
wscall.store() |
133 | 137 |
wscall = NamedWsCall(name='Test quinquies') |
134 | 138 |
wscall.store() |
139 |
wscall = NamedWsCall(name='Test sexies') |
|
140 |
wscall.store() |
|
135 | 141 | |
136 | 142 |
carddef = CardDef() |
137 | 143 |
carddef.name = 'Test' |
... | ... | |
142 | 148 |
carddef = CardDef() |
143 | 149 |
carddef.name = 'Test ter' |
144 | 150 |
carddef.store() |
151 |
carddef = CardDef() |
|
152 |
carddef.name = 'Test quater' |
|
153 |
carddef.store() |
|
145 | 154 | |
146 | 155 |
formdef = FormDef() |
147 | 156 |
formdef.name = 'Test bis' |
... | ... | |
153 | 162 |
formdef.name = 'Test quater' |
154 | 163 |
formdef.store() |
155 | 164 |
formdef = FormDef() |
165 |
formdef.name = 'Test quinquies' |
|
166 |
formdef.store() |
|
167 |
formdef = FormDef() |
|
156 | 168 |
formdef.name = 'Test' |
157 | 169 |
formdef.store() |
158 | 170 | |
... | ... | |
237 | 249 |
'value': '{{ cards|objects:"test-ter" }} {{ webservice.test_ter }}', |
238 | 250 |
} |
239 | 251 | |
252 |
register_comment = status.add_action('register-comment') |
|
253 |
register_comment.to = [role.id] |
|
254 |
register_comment.comment = ( |
|
255 |
'{{ cards|objects:"test-quater" }} {{ forms|objects:"test-quinquies" }} {{ webservice.test_sexies }}' |
|
256 |
) |
|
257 | ||
240 | 258 |
dispatch_auto = status.add_action('dispatch') |
241 | 259 |
dispatch_auto.rules = [{'role_id': role.id, 'value': 'xxx'}] |
242 | 260 | |
... | ... | |
304 | 322 |
('test', 'wscalls'), |
305 | 323 |
('test_bis', 'wscalls'), |
306 | 324 |
('test_ter', 'wscalls'), |
325 |
('test_sexies', 'wscalls'), |
|
307 | 326 |
('test', 'cards'), |
308 | 327 |
('test-bis', 'cards'), |
309 | 328 |
('test-ter', 'cards'), |
329 |
('test-quater', 'cards'), |
|
310 | 330 |
('test-ter', 'forms'), |
311 | 331 |
('test-bis', 'forms'), |
332 |
('test-quinquies', 'forms'), |
|
312 | 333 |
('test', 'blocks'), |
313 | 334 |
('test-role', 'roles'), |
314 | 335 |
} |
... | ... | |
323 | 344 |
mail_template = MailTemplate(name='test mail template') |
324 | 345 |
mail_template.store() |
325 | 346 |
send_mail.mail_template = mail_template.slug |
347 |
comment_template = CommentTemplate(name='test comment template') |
|
348 |
comment_template.store() |
|
349 |
register_comment.comment_template = comment_template.slug |
|
326 | 350 |
workflow.store() |
327 | 351 |
resp = get_app(pub).get(sign_uri('/api/export-import/workflows/')) |
328 | 352 |
resp = get_app(pub).get(sign_uri(resp.json['data'][0]['urls']['dependencies'])) |
... | ... | |
335 | 359 |
('test-bis', 'forms'), |
336 | 360 |
('test', 'blocks'), |
337 | 361 |
('test-mail-template', 'mail-templates'), |
362 |
('test-comment-template', 'comment-templates'), |
|
338 | 363 |
('test-role', 'roles'), |
339 | 364 |
} |
340 | 365 |
for dependency in resp.json['data']: |
... | ... | |
345 | 370 |
cat = MailTemplateCategory(name='Cat') |
346 | 371 |
cat.store() |
347 | 372 |
mail_template.category_id = cat.id |
373 |
mail_template.subject = '{{ webservice.test }}' |
|
374 |
mail_template.body = '{{ cards|objects:"test" }} {{ forms|objects:"test-ter" }}' |
|
348 | 375 |
mail_template.store() |
349 | 376 |
resp = get_app(pub).get(sign_uri('/api/export-import/workflows/')) |
350 | 377 |
resp = get_app(pub).get(sign_uri(resp.json['data'][0]['urls']['dependencies'])) |
351 | 378 |
mail_template_entry = [x for x in resp.json['data'] if x['type'] == 'mail-templates'][0] |
352 | 379 |
resp = get_app(pub).get(sign_uri(mail_template_entry['urls']['dependencies'])) |
353 |
assert {(x['id'], x['type']) for x in resp.json['data']} == {('cat', 'mail-templates-categories')} |
|
380 |
assert {(x['id'], x['type']) for x in resp.json['data']} == { |
|
381 |
('cat', 'mail-templates-categories'), |
|
382 |
('test', 'cards'), |
|
383 |
('test', 'wscalls'), |
|
384 |
('test-ter', 'forms'), |
|
385 |
} |
|
386 |
for dependency in resp.json['data']: |
|
387 |
get_app(pub).get(sign_uri(dependency['urls']['export'])) |
|
388 | ||
389 |
cat = CommentTemplateCategory(name='Cat') |
|
390 |
cat.store() |
|
391 |
comment_template.category_id = cat.id |
|
392 |
comment_template.comment = ( |
|
393 |
'{{ cards|objects:"test-quater" }} {{ forms|objects:"test-quinquies" }} {{ webservice.test_sexies }}' |
|
394 |
) |
|
395 |
comment_template.store() |
|
396 |
resp = get_app(pub).get(sign_uri('/api/export-import/workflows/')) |
|
397 |
resp = get_app(pub).get(sign_uri(resp.json['data'][0]['urls']['dependencies'])) |
|
398 |
comment_template_entry = [x for x in resp.json['data'] if x['type'] == 'comment-templates'][0] |
|
399 |
resp = get_app(pub).get(sign_uri(comment_template_entry['urls']['dependencies'])) |
|
400 |
assert {(x['id'], x['type']) for x in resp.json['data']} == { |
|
401 |
('cat', 'comment-templates-categories'), |
|
402 |
('test-quater', 'cards'), |
|
403 |
('test-quinquies', 'forms'), |
|
404 |
('test_sexies', 'wscalls'), |
|
405 |
} |
|
354 | 406 |
for dependency in resp.json['data']: |
355 | 407 |
get_app(pub).get(sign_uri(dependency['urls']['export'])) |
356 | 408 |
wcs/api_export_import.py | ||
---|---|---|
30 | 30 |
BlockCategory, |
31 | 31 |
CardDefCategory, |
32 | 32 |
Category, |
33 |
CommentTemplateCategory, |
|
33 | 34 |
DataSourceCategory, |
34 | 35 |
MailTemplateCategory, |
35 | 36 |
WorkflowCategory, |
36 | 37 |
) |
38 |
from wcs.comment_templates import CommentTemplate |
|
37 | 39 |
from wcs.data_sources import NamedDataSource, StubNamedDataSource |
38 | 40 |
from wcs.formdef import FormDef |
39 | 41 |
from wcs.mail_templates import MailTemplate |
... | ... | |
57 | 59 |
'roles': Role, |
58 | 60 |
'mail-templates-categories': MailTemplateCategory, |
59 | 61 |
'mail-templates': MailTemplate, |
62 |
'comment-templates-categories': CommentTemplateCategory, |
|
63 |
'comment-templates': CommentTemplate, |
|
60 | 64 |
'workflows-categories': WorkflowCategory, |
61 | 65 |
'workflows': Workflow, |
62 | 66 |
'wscalls': NamedWsCall, |
... | ... | |
83 | 87 |
{'id': 'blocks', 'text': _('Blocks'), 'singular': _('Block of fields'), 'minor': True}, |
84 | 88 |
{'id': 'data-sources', 'text': _('Data Sources'), 'singular': _('Data Source'), 'minor': True}, |
85 | 89 |
{'id': 'mail-templates', 'text': _('Mail Templates'), 'singular': _('Mail Template'), 'minor': True}, |
90 |
{ |
|
91 |
'id': 'comment-templates', |
|
92 |
'text': _('Comment Templates'), |
|
93 |
'singular': _('Mail Template'), |
|
94 |
'minor': True, |
|
95 |
}, |
|
86 | 96 |
{'id': 'wscalls', 'text': _('Webservice Calls'), 'singular': _('Webservice Call'), 'minor': True}, |
87 | 97 |
{ |
88 | 98 |
'id': 'blocks-categories', |
... | ... | |
114 | 124 |
'singular': _('Category (mail templates)'), |
115 | 125 |
'minor': True, |
116 | 126 |
}, |
127 |
{ |
|
128 |
'id': 'comment-templates-categories', |
|
129 |
'text': _('Categories (comment templates)'), |
|
130 |
'singular': _('Category (comment templates)'), |
|
131 |
'minor': True, |
|
132 |
}, |
|
117 | 133 |
{ |
118 | 134 |
'id': 'data-sources-categories', |
119 | 135 |
'text': _('Categories (data sources)'), |
wcs/comment_templates.py | ||
---|---|---|
21 | 21 |
from wcs.categories import CommentTemplateCategory |
22 | 22 |
from wcs.qommon import _, get_logger |
23 | 23 |
from wcs.qommon.form import OptGroup |
24 |
from wcs.qommon.misc import check_carddefs, check_formdefs, check_wscalls |
|
24 | 25 |
from wcs.qommon.xml_storage import XmlStorableObject |
25 | 26 | |
26 | 27 | |
... | ... | |
126 | 127 |
get_logger().warning("comment template '%s' does not exist" % slug) |
127 | 128 |
return comment_template |
128 | 129 | |
130 |
def get_dependencies(self): |
|
131 |
yield self.category |
|
132 |
for string in self.get_computed_strings(): |
|
133 |
yield from check_wscalls(string) |
|
134 |
yield from check_carddefs(string) |
|
135 |
yield from check_formdefs(string) |
|
136 | ||
137 |
def get_computed_strings(self): |
|
138 |
yield self.comment |
|
139 | ||
129 | 140 |
def export_to_xml(self, include_id=False): |
130 | 141 |
root = super().export_to_xml(include_id=include_id) |
131 | 142 |
CommentTemplateCategory.object_category_xml_export(self, root, include_id=include_id) |
wcs/mail_templates.py | ||
---|---|---|
21 | 21 |
from wcs.categories import MailTemplateCategory |
22 | 22 |
from wcs.qommon import _, get_logger |
23 | 23 |
from wcs.qommon.form import OptGroup |
24 |
from wcs.qommon.misc import check_carddefs, check_formdefs, check_wscalls |
|
24 | 25 |
from wcs.qommon.xml_storage import XmlStorableObject |
25 | 26 | |
26 | 27 | |
... | ... | |
130 | 131 | |
131 | 132 |
def get_dependencies(self): |
132 | 133 |
yield self.category |
134 |
for string in self.get_computed_strings(): |
|
135 |
yield from check_wscalls(string) |
|
136 |
yield from check_carddefs(string) |
|
137 |
yield from check_formdefs(string) |
|
138 | ||
139 |
def get_computed_strings(self): |
|
140 |
yield self.subject |
|
141 |
yield self.body |
|
133 | 142 | |
134 | 143 |
def export_to_xml(self, include_id=False): |
135 | 144 |
root = super().export_to_xml(include_id=include_id) |
wcs/wf/register_comment.py | ||
---|---|---|
89 | 89 |
to = None |
90 | 90 |
attachments = None |
91 | 91 | |
92 |
def get_dependencies(self): |
|
93 |
yield from super().get_dependencies() |
|
94 |
yield CommentTemplate.get_by_slug(self.comment_template) |
|
95 | ||
92 | 96 |
def add_parameters_widgets(self, form, parameters, prefix='', formdef=None, **kwargs): |
93 | 97 |
super().add_parameters_widgets(form, parameters, prefix=prefix, formdef=formdef, **kwargs) |
94 | 98 |
subject_body_attrs = {} |
... | ... | |
144 | 148 |
get_publisher().record_error(exception=e, context='[comment/attachments]', notify=True) |
145 | 149 |
continue |
146 | 150 | |
151 |
def get_computed_strings(self): |
|
152 |
yield from super().get_computed_strings() |
|
153 |
if not self.comment_template: |
|
154 |
yield self.comment |
|
155 | ||
147 | 156 |
def perform(self, formdata): |
148 | 157 |
if not formdata.evolution: |
149 | 158 |
return |
150 |
- |