Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changes/190.canada.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added a `filename` option to the DataStore Dump endpoint.
11 changes: 7 additions & 4 deletions ckanext/datastore/blueprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ def dump_schema() -> Schema:
u'language': [ignore_missing, unicode_only],
u'fields': [exclude_id_from_ds_dump, ignore_missing, list_of_strings_or_string], # (canada fork only): exclude _id field from Blueprint dump
u'sort': [default(u'_id'), list_of_strings_or_string],
'filename': [ignore_missing, unicode_only] # (canada fork only): filename to save stream to
}


Expand All @@ -111,6 +112,8 @@ def dump(resource_id: str):
limit = data.get('limit')
options = {'bom': data['bom']}
sort = data['sort']
# (canada fork only): filename to save stream to
filename = data.get('filename', resource_id)
search_params = {
k: v
for k, v in data.items()
Expand All @@ -127,19 +130,19 @@ def dump(resource_id: str):

if fmt == 'csv':
content_disposition = 'attachment; filename="{name}.csv"'.format(
name=resource_id)
name=filename) # (canada fork only): filename to save stream to
content_type = b'text/csv; charset=utf-8'
elif fmt == 'tsv':
content_disposition = 'attachment; filename="{name}.tsv"'.format(
name=resource_id)
name=filename) # (canada fork only): filename to save stream to
content_type = b'text/tab-separated-values; charset=utf-8'
elif fmt == 'json':
content_disposition = 'attachment; filename="{name}.json"'.format(
name=resource_id)
name=filename) # (canada fork only): filename to save stream to
content_type = b'application/json; charset=utf-8'
elif fmt == 'xml':
content_disposition = 'attachment; filename="{name}.xml"'.format(
name=resource_id)
name=filename) # (canada fork only): filename to save stream to
content_type = b'text/xml; charset=utf-8'
else:
abort(404, _('Unsupported format'))
Expand Down