api: add option to not include files content in card json (#55373)
This commit is contained in:
parent
519f412676
commit
ea00edc923
|
@ -264,6 +264,14 @@ def test_formdata(pub, local_user):
|
|||
assert resp.json['workflow']['status'] == {'id': 'new', 'name': 'New'}
|
||||
assert resp.json['workflow']['real_status'] == {'id': 'st1', 'name': 'Status1'}
|
||||
|
||||
# check ?include-files-content=off
|
||||
resp = get_app(pub).get(
|
||||
sign_uri('/api/forms/test/%s/?include-files-content=off' % formdata.id, user=local_user), status=200
|
||||
)
|
||||
assert 'content' not in resp.json['fields']['file']
|
||||
assert resp.json['fields']['file']['url']
|
||||
assert resp.json['fields']['file']['filename'] == 'test.txt'
|
||||
|
||||
|
||||
def test_formdata_backoffice_fields(pub, local_user):
|
||||
test_formdata(pub, local_user)
|
||||
|
|
|
@ -25,7 +25,7 @@ from quixote.html import TemplateIO, htmltext
|
|||
from quixote.util import randbytes
|
||||
|
||||
from wcs import data_sources
|
||||
from wcs.api_utils import get_user_from_api_query_string, is_url_signed, sign_url_auto_orig
|
||||
from wcs.api_utils import get_query_flag, get_user_from_api_query_string, is_url_signed, sign_url_auto_orig
|
||||
from wcs.blocks import BlockSubWidget, BlockWidget
|
||||
from wcs.qommon.admin.texts import TextsDirectory
|
||||
from wcs.workflows import EditableWorkflowStatusItem, RedisplayFormException
|
||||
|
@ -179,7 +179,9 @@ class FormStatusPage(Directory, FormTemplateMixin):
|
|||
def json(self):
|
||||
self.check_auth(api_call=True)
|
||||
anonymise = get_request().has_anonymised_data_api_restriction()
|
||||
return self.export_to_json(anonymise=anonymise)
|
||||
return self.export_to_json(
|
||||
anonymise=anonymise, include_files=get_query_flag('include-files-content', default=True)
|
||||
)
|
||||
|
||||
def workflow_messages(self, position='top'):
|
||||
if self.formdef.workflow:
|
||||
|
@ -382,9 +384,9 @@ class FormStatusPage(Directory, FormTemplateMixin):
|
|||
response.content_type = 'text/plain'
|
||||
return "Your browser should redirect you"
|
||||
|
||||
def export_to_json(self, anonymise=False):
|
||||
def export_to_json(self, include_files=True, anonymise=False):
|
||||
get_response().set_content_type('application/json')
|
||||
return self.filled.export_to_json(anonymise=anonymise)
|
||||
return self.filled.export_to_json(include_files=include_files, anonymise=anonymise)
|
||||
|
||||
def history(self):
|
||||
if not self.filled.evolution:
|
||||
|
|
Loading…
Reference in New Issue