Skip to content

Commit

Permalink
Add translate_func
Browse files Browse the repository at this point in the history
  • Loading branch information
Amertz08 committed Aug 17, 2020
1 parent d3fc8d4 commit ede0d09
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
- h3 heading
- X.X.X - YYYY-MM-DD

### 1.7.0.alpha1 - 2020-08-17

- Added `UJSONRenderer.translate_func` attribute for translating data into a `ujson`
serializable object.

### 1.6.0 - 2020-03-10

- Add `ujson>=2` compatibility
Expand Down
2 changes: 1 addition & 1 deletion drf_ujson/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
__author__ = "y.gavenchuk aka murminathor"
__version__ = (1, 6, 1)
__version__ = (1, 7, 0)
6 changes: 6 additions & 0 deletions drf_ujson/renderers.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ class UJSONRenderer(JSONRenderer):
# Unicode sequences.
encode_html_chars: bool = False

# TODO: typing
translate_func = None

def render(
self,
data: Union[dict, None],
Expand All @@ -30,6 +33,9 @@ def render(
if data is None:
return bytes()

if self.translate_func is not None:
data = self.translate_func(data)

accepted_media_type = accepted_media_type or ""
renderer_context = renderer_context or {}
indent = self.get_indent(accepted_media_type, renderer_context)
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
with open("README.md", "r") as fh:
long_description = fh.read()

# TODO: remove alpha
setup(
name="drf_ujson2",
version=".".join([str(i) for i in __version__]),
version=".".join([str(i) for i in __version__]) + ".alpha1",
python_requires=">=3.6",
description="Django Rest Framework UJSON Renderer",
keywords="django,djangorestframework,ujson",
Expand Down

0 comments on commit ede0d09

Please sign in to comment.