Skip to content

Commit

Permalink
feat: use CustomJsonEncoder class in json.dumps call
Browse files Browse the repository at this point in the history
I want to translate our repo names, the `CustomJsonEncoder` can resolve
the `translate` objects. Just in case I've added this class where it
could make sense to have translated objects too.
  • Loading branch information
sveneberth committed Nov 15, 2023
1 parent 6dee673 commit f0307ad
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/viur/core/render/json/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,4 +224,4 @@ def listRootNodes(self, rootNodes, *args, **kwargs):
for rn in rootNodes:
rn["key"] = db.encodeKey(rn["key"])

return json.dumps(rootNodes)
return json.dumps(rootNodes, cls=CustomJsonEncoder)
5 changes: 3 additions & 2 deletions src/viur/core/render/json/user.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import json
from viur.core.modules.user import UserSecondFactorAuthentication
from . import default as DefaultRender
from .default import CustomJsonEncoder


class UserRender(DefaultRender): # Render user-data to json
Expand All @@ -11,7 +12,7 @@ def login(self, skel, **kwargs):
return self.edit(skel, **kwargs)

def loginChoices(self, authMethods, **kwargs):
return json.dumps(list(set([x[0] for x in authMethods])))
return json.dumps(list(set([x[0] for x in authMethods])), cls=CustomJsonEncoder)

def loginSucceeded(self, msg="OKAY", **kwargs):
return json.dumps(msg)
Expand Down Expand Up @@ -47,4 +48,4 @@ def second_factor_choice(
):
second_factors = [{"name": second_factor.NAME, "start_url": second_factor.start_url}
for second_factor in second_factors]
return json.dumps(second_factors)
return json.dumps(second_factors, cls=CustomJsonEncoder)
2 changes: 1 addition & 1 deletion src/viur/core/render/vi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def get_settings():
fields["admin.user.google.clientID"] = conf.user.google_client_id

current.request.get().response.headers["Content-Type"] = "application/json"
return json.dumps(fields)
return json.dumps(fields, cls=CustomJsonEncoder)


def _postProcessAppObj(obj):
Expand Down

0 comments on commit f0307ad

Please sign in to comment.