Skip to content

Commit

Permalink
feat(views): ds dump filename;
Browse files Browse the repository at this point in the history
- Filename for ds dump endpoint.
  • Loading branch information
JVickery-TBS committed Feb 6, 2025
1 parent c7e89f5 commit 0942ba6
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 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,9 @@ def dump(resource_id: str):
limit = data.get('limit')
options = {'bom': data['bom']}
sort = data['sort']
# (canada fork only): filename to save stream to
custom_filename = data.get('filename')
filename = custom_filename if custom_filename else resource_id
search_params = {
k: v
for k, v in data.items()
Expand All @@ -127,19 +131,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

0 comments on commit 0942ba6

Please sign in to comment.