0001-workflows-allow-attach-a-generated-document-without-.patch
tests/test_form_pages.py | ||
---|---|---|
2552 | 2552 |
assert formdef.data_class().count() == 1 |
2553 | 2553 |
assert formdef.data_class().select()[0].status == 'wf-st2' |
2554 | 2554 | |
2555 |
def test_formdata_generated_document_visibility(pub): |
|
2556 |
create_user(pub) |
|
2557 |
wf = Workflow(name='status') |
|
2558 |
st1 = wf.add_status('Status1', 'st1') |
|
2559 |
export_to = ExportToModel() |
|
2560 |
export_to.method = 'non-interactive' |
|
2561 |
template_filename = os.path.join(os.path.dirname(__file__), 'template.odt') |
|
2562 |
template = open(template_filename).read() |
|
2563 |
upload = QuixoteUpload('/foo/template.odt', content_type='application/octet-stream') |
|
2564 |
upload.fp = StringIO.StringIO() |
|
2565 |
upload.fp.write(template) |
|
2566 |
upload.fp.seek(0) |
|
2567 |
export_to.model_file = UploadedFile(pub.app_dir, None, upload) |
|
2568 |
export_to.id = '_export_to' |
|
2569 |
export_to.attach_to_history = False |
|
2570 |
export_to.varname = 'barfoo' |
|
2571 |
st1.items.append(export_to) |
|
2572 |
export_to.parent = st1 |
|
2573 | ||
2574 |
jump = JumpWorkflowStatusItem() |
|
2575 |
jump.status = 'st2' |
|
2576 |
st1.items.append(jump) |
|
2577 |
jump.parent = st1 |
|
2578 |
wf.add_status('Status2', 'st2') |
|
2579 |
wf.store() |
|
2580 | ||
2581 |
formdef = create_formdef() |
|
2582 |
formdef.workflow_id = wf.id |
|
2583 |
formdef.fields = [fields.TextField(id='0', label='comment', type='text', varname='comment')] |
|
2584 |
formdef.store() |
|
2585 |
formdef.data_class().wipe() |
|
2586 | ||
2587 |
resp = login(get_app(pub), username='foo', password='foo').get('/test/') |
|
2588 |
resp.form['f0'] = 'Hello\n\nWorld.' |
|
2589 |
resp = resp.forms[0].submit('submit') |
|
2590 |
assert 'Check values then click submit.' in resp.body |
|
2591 |
resp = resp.forms[0].submit('submit') |
|
2592 |
assert resp.status_int == 302 |
|
2593 |
resp = resp.follow() |
|
2594 |
assert 'The form has been recorded' in resp.body |
|
2595 | ||
2596 |
# not visible in history |
|
2597 |
assert 'template.odt' not in resp.body |
|
2598 |
# accessible with attachment substitution variables |
|
2599 |
variables = formdef.data_class().select()[0].get_substitution_variables() |
|
2600 |
assert 'form_attachments' in variables |
|
2601 |
assert variables['form_attachments'] is not None |
|
2602 |
assert hasattr(variables['form_attachments'], 'barfoo') |
|
2603 | ||
2555 | 2604 |
def test_formdata_generated_document_to_backoffice_field(pub): |
2556 | 2605 |
create_user_and_admin(pub) |
2557 | 2606 |
wf = Workflow(name='status') |
wcs/formdata.py | ||
---|---|---|
173 | 173 |
for p in self.parts: |
174 | 174 |
if not hasattr(p, 'view'): |
175 | 175 |
continue |
176 |
l.append(p.view()) |
|
176 |
display_part = p.view() |
|
177 |
if display_part is None: |
|
178 |
continue |
|
179 |
l.append(display_part) |
|
177 | 180 |
self._display_parts = l |
178 | 181 |
return self._display_parts |
179 | 182 |
wcs/wf/export_to_model.py | ||
---|---|---|
549 | 549 |
content_type = 'application/pdf' |
550 | 550 |
if self.push_to_portfolio: |
551 | 551 |
push_document(formdata.get_user(), filename, outstream) |
552 |
if self.attach_to_history: |
|
552 |
if self.attach_to_history or self.varname:
|
|
553 | 553 |
evo.add_part(AttachmentEvolutionPart( |
554 | 554 |
filename, |
555 | 555 |
outstream, |
556 | 556 |
content_type=content_type, |
557 |
varname=self.varname)) |
|
557 |
varname=self.varname, |
|
558 |
is_visible=bool(self.attach_to_history))) |
|
558 | 559 |
formdata.store() |
559 | 560 |
if self.backoffice_filefield_id: |
560 | 561 |
outstream.seek(0) |
wcs/workflows.py | ||
---|---|---|
162 | 162 |
content_type = None |
163 | 163 |
charset = None |
164 | 164 |
varname = None |
165 |
is_visible = None |
|
165 | 166 | |
166 | 167 |
def __init__(self, base_filename, fp, orig_filename=None, content_type=None, |
167 |
charset=None, varname=None): |
|
168 |
charset=None, varname=None, is_visible=None):
|
|
168 | 169 |
self.base_filename = base_filename |
169 | 170 |
self.orig_filename = orig_filename or base_filename |
170 | 171 |
self.content_type = content_type |
171 | 172 |
self.charset = charset |
172 | 173 |
self.fp = fp |
173 | 174 |
self.varname = varname |
175 |
self.is_visible = is_visible |
|
174 | 176 | |
175 | 177 |
@classmethod |
176 | 178 |
def from_upload(cls, upload, varname=None): |
... | ... | |
204 | 206 |
return odict |
205 | 207 | |
206 | 208 |
def view(self): |
207 |
return htmltext('<p class="wf-attachment"><a href="attachment?f=%s">%s</a>' % ( |
|
209 |
if self.is_visible is not False: |
|
210 |
return htmltext('<p class="wf-attachment"><a href="attachment?f=%s">%s</a>' % ( |
|
208 | 211 |
os.path.basename(self.filename), self.orig_filename)) |
209 | 212 | |
210 | 213 |
@classmethod |
211 |
- |