-
Notifications
You must be signed in to change notification settings - Fork 98
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
Fix JSON export for reports (#175) #180
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't feel like this is the ideal way to do this with DRF since you can get JSON with built-in behavior by changing the original URL from /api/report-export/1/?type=json
to /api/report-export/1/?format=json
, but at least this removes a ViewSet and is using the JSONRenderer
. For consistency, it would be ideal to have a docx renderer, but I don't see that being strictly necessary until it is needed in more than one place.
Also, the unit tests need to be updated.
JSON exports were being rendered through an HTML template due to content negotiation in the browser (e.g. Accept:text/html). This commit forces the renderer to use JSON regardless of content negotiation and also cleans up the json and docx export code.
955a3ed
to
efe82ac
Compare
Based on Nick's feedback, reverted to using two ViewSets, moved the docx code into a custom renderer, and use Django's built in format parameter instead of type. This makes for a much cleaner PR.
efe82ac
to
d4e968e
Compare
Kudos, SonarCloud Quality Gate passed!
|
Codecov Report
@@ Coverage Diff @@
## main #180 +/- ##
==========================================
- Coverage 95.76% 95.75% -0.01%
==========================================
Files 9 10 +1
Lines 874 872 -2
==========================================
- Hits 837 835 -2
Misses 37 37
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I definitely like this approach much more than the original. I confirmed that both JSON and DOCX exports work as expected.
JSON exports were being rendered through an HTML template due to
content negotiation in the browser (e.g. Accept:text/html). This commit
forces the renderer to use JSON regardless of content negotiation and
also cleans up the json and docx export code.