-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #180 from center-for-threat-informed-defense/175-f…
…ix-json-export Fix JSON export for reports (#175)
- Loading branch information
Showing
6 changed files
with
73 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import io | ||
|
||
from rest_framework import renderers | ||
|
||
import tram.report.docx | ||
|
||
|
||
class DocxReportRenderer(renderers.BaseRenderer): | ||
"""This custom renderer exports mappings into Word .docx format.""" | ||
|
||
media_type = ( | ||
"application/vnd.openxmlformats-officedocument.wordprocessingml.document" | ||
) | ||
format = "docx" | ||
|
||
def render(self, data, accepted_media_type=None, renderer_context=None): | ||
""" | ||
Export report mappings into Word .docx format. | ||
:param data: the report mappings dict | ||
:param accepted_media_type: the content type negotiated by DRF | ||
:param renderer_context: optional additional data | ||
:returns bytes: .docx binary data | ||
""" | ||
document = tram.report.docx.build(data) | ||
buffer = io.BytesIO() | ||
document.save(buffer) | ||
buffer.seek(0) | ||
return buffer.read() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters