0001-workflows-allow-attach-a-generated-document-without-.patch
tests/test_form_pages.py | ||
---|---|---|
3471 | 3471 |
assert formdef.data_class().count() == 1 |
3472 | 3472 |
assert formdef.data_class().select()[0].status == 'wf-st2' |
3473 | 3473 | |
3474 |
def test_formdata_generated_document_visibility(pub): |
|
3475 |
create_user(pub) |
|
3476 |
wf = Workflow(name='status') |
|
3477 |
st1 = wf.add_status('Status1', 'st1') |
|
3478 |
export_to = ExportToModel() |
|
3479 |
export_to.method = 'non-interactive' |
|
3480 |
template_filename = os.path.join(os.path.dirname(__file__), 'template.odt') |
|
3481 |
template = open(template_filename).read() |
|
3482 |
upload = QuixoteUpload('/foo/template.odt', content_type='application/octet-stream') |
|
3483 |
upload.fp = StringIO.StringIO() |
|
3484 |
upload.fp.write(template) |
|
3485 |
upload.fp.seek(0) |
|
3486 |
export_to.model_file = UploadedFile(pub.app_dir, None, upload) |
|
3487 |
export_to.convert_to_pdf = False |
|
3488 |
export_to.id = '_export_to' |
|
3489 |
export_to.attach_to_history = False # document will not be visible |
|
3490 |
export_to.varname = 'barfoo' |
|
3491 |
st1.items.append(export_to) |
|
3492 |
export_to.parent = st1 |
|
3493 | ||
3494 |
jump = JumpWorkflowStatusItem() |
|
3495 |
jump.status = 'st2' |
|
3496 |
st1.items.append(jump) |
|
3497 |
jump.parent = st1 |
|
3498 |
wf.add_status('Status2', 'st2') |
|
3499 |
wf.store() |
|
3500 | ||
3501 |
formdef = create_formdef() |
|
3502 |
formdef.workflow_id = wf.id |
|
3503 |
formdef.fields = [fields.TextField(id='0', label='comment', type='text', varname='comment')] |
|
3504 |
formdef.store() |
|
3505 |
formdef.data_class().wipe() |
|
3506 | ||
3507 |
resp = login(get_app(pub), username='foo', password='foo').get('/test/') |
|
3508 |
resp.form['f0'] = 'Hello\n\nWorld.' |
|
3509 |
resp = resp.forms[0].submit('submit') |
|
3510 |
assert 'Check values then click submit.' in resp.body |
|
3511 |
resp = resp.forms[0].submit('submit') |
|
3512 |
assert resp.status_int == 302 |
|
3513 |
resp = resp.follow() |
|
3514 |
assert 'The form has been recorded' in resp.body |
|
3515 | ||
3516 |
# not visible in history |
|
3517 |
assert 'template.odt' not in resp.body |
|
3518 |
# accessible with attachment substitution variables |
|
3519 |
variables = formdef.data_class().select()[0].get_substitution_variables() |
|
3520 |
assert 'form_attachments' in variables |
|
3521 |
assert variables['form_attachments'] is not None |
|
3522 |
assert hasattr(variables['form_attachments'], 'barfoo') |
|
3523 | ||
3524 |
# try to directly download the attachment -> 404 |
|
3525 |
url = variables['form_attachments'].barfoo.url |
|
3526 |
login(get_app(pub), username='foo', password='foo').get(url, status=404) |
|
3527 | ||
3474 | 3528 |
def test_formdata_generated_document_to_backoffice_field(pub): |
3475 | 3529 |
create_user_and_admin(pub) |
3476 | 3530 |
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/attachment.py | ||
---|---|---|
39 | 39 |
for p in evo.parts: |
40 | 40 |
if not isinstance(p, AttachmentEvolutionPart): |
41 | 41 |
continue |
42 |
if p.is_visible is False: |
|
43 |
continue |
|
42 | 44 |
if file_reference and os.path.basename(p.filename) != file_reference: |
43 | 45 |
continue |
44 | 46 |
if p.base_filename == filename: |
... | ... | |
58 | 60 |
for p in evo.parts: |
59 | 61 |
if not isinstance(p, AttachmentEvolutionPart): |
60 | 62 |
continue |
63 |
if p.is_visible is False: |
|
64 |
continue |
|
61 | 65 |
if os.path.basename(p.filename) == fn: |
62 | 66 |
return redirect( '%sfiles/attachment-%s/%s' % ( |
63 | 67 |
self.filled.get_url(), fn, p.base_filename)) |
wcs/wf/export_to_model.py | ||
---|---|---|
521 | 521 |
content_type = 'application/pdf' |
522 | 522 |
if self.push_to_portfolio: |
523 | 523 |
push_document(formdata.get_user(), filename, outstream) |
524 |
if self.attach_to_history: |
|
524 |
if self.attach_to_history or self.varname:
|
|
525 | 525 |
evo.add_part(AttachmentEvolutionPart( |
526 | 526 |
filename, |
527 | 527 |
outstream, |
528 | 528 |
content_type=content_type, |
529 |
varname=self.varname)) |
|
529 |
varname=self.varname, |
|
530 |
is_visible=bool(self.attach_to_history))) |
|
530 | 531 |
formdata.store() |
531 | 532 |
if self.backoffice_filefield_id: |
532 | 533 |
outstream.seek(0) |
wcs/workflows.py | ||
---|---|---|
166 | 166 |
content_type = None |
167 | 167 |
charset = None |
168 | 168 |
varname = None |
169 |
is_visible = None |
|
169 | 170 | |
170 | 171 |
def __init__(self, base_filename, fp, orig_filename=None, content_type=None, |
171 |
charset=None, varname=None): |
|
172 |
charset=None, varname=None, is_visible=None):
|
|
172 | 173 |
self.base_filename = base_filename |
173 | 174 |
self.orig_filename = orig_filename or base_filename |
174 | 175 |
self.content_type = content_type |
175 | 176 |
self.charset = charset |
176 | 177 |
self.fp = fp |
177 | 178 |
self.varname = varname |
179 |
self.is_visible = is_visible |
|
178 | 180 | |
179 | 181 |
@classmethod |
180 | 182 |
def from_upload(cls, upload, varname=None): |
... | ... | |
211 | 213 |
return odict |
212 | 214 | |
213 | 215 |
def view(self): |
214 |
return htmltext('<p class="wf-attachment"><a href="attachment?f=%s">%s</a>' % ( |
|
216 |
if self.is_visible is not False: |
|
217 |
return htmltext('<p class="wf-attachment"><a href="attachment?f=%s">%s</a>' % ( |
|
215 | 218 |
os.path.basename(self.filename), self.orig_filename)) |
216 | 219 | |
217 | 220 |
@classmethod |
218 |
- |