Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible bug: '?format=csv' is appended to URLs in the downloaded CSV #56

Open
dfarre opened this issue Oct 7, 2016 · 3 comments
Open

Comments

@dfarre
Copy link

dfarre commented Oct 7, 2016

We are with the last version using the PaginatedCSVRenderer, specified in the settings. CSVs are not correctly downloaded if we either put 'format=csv' in the query string or use the drop-down menu for choosing the format in the browsable API; then '?format=csv' is appended to the URLs in the downloaded CSVs - using hyperlinked serializers. URLs are correct if we specify 'text/csv' in the accept header and not in the query string.

@mjumbewu
Copy link
Owner

mjumbewu commented Nov 5, 2016

If I'm understanding correctly, you're seeing the filenames contain "?format=csv" when it's supplied in the URL. There's currently no way within the renderer to specify the name of the generated file. That might be something that you'd want to handle within the view by adding a Content-disposition header to the response (e.g. https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Disposition#Examples)

@dfarre
Copy link
Author

dfarre commented Nov 7, 2016

Thanks for your reply. It is not the file name but the values within the file that are URL's (hyperlinks in the browsable API); e.g., the value of "user" could be "http://api.mysite/users/22/", and wrongly appear as "http://api.mysite/users/22/?format=csv".

@mjumbewu
Copy link
Owner

@dfarre This is actually because of the way that DRF constructs links to relations. I could think of a few things you could do:

  • Create a subclass of HyperlinkedRelatedField and override the get_url method to exclude the format parameter.
  • If you're using a subclass of HyperlinkedRelatedSerializer, then override the serializer_related_field attribute, and set it to the HyperlinkedRelatedField subcless you created above.

- OR -

  • Set CSV as the default format so that you don't have to include the format parameter

- OR -

  • Request the resource with an HTTP Accept header set to "text/csv" so that you can omit the format parameter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants