[Django] #24916: DjangoJSONEncoder: Decimal type localization mechanism is missing

6 views
Skip to first unread message

Django

unread,
Jun 4, 2015, 5:07:36 AM6/4/15
to django-...@googlegroups.com
#24916: DjangoJSONEncoder: Decimal type localization mechanism is missing
--------------------------------------+--------------------
Reporter: vartagg | Owner: nobody
Type: Bug | Status: new
Component: Core (Serialization) | Version: 1.8
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+--------------------
Currently, DjangoJSONEncoder officially supports Decimal types. But
localization of this type aren't using.
In current version of code, Decimal variable simply converts to str type,
without use of force_text and formats.localize (as in "localize" Django
standard template tag).

--
Ticket URL: <https://code.djangoproject.com/ticket/24916>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jun 4, 2015, 7:38:12 AM6/4/15
to django-...@googlegroups.com
#24916: DjangoJSONEncoder: Decimal type localization mechanism is missing
-------------------------------------+-------------------------------------
Reporter: vartagg | Owner: nobody
Type: Bug | Status: closed
Component: Core | Version: 1.8
(Serialization) |
Severity: Normal | Resolution: wontfix
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by timgraham):

* status: new => closed
* needs_better_patch: => 0
* resolution: => wontfix
* needs_tests: => 0
* needs_docs: => 0


Comment:

The JSON standard for serializing decimal values does not provide for
localized formatting. (See JSON.org.) This is why values are not
localized. I think it would also make the date less portable across
locales.

If you need localized values, then I'd suggest to create a custom encoder
for your serializer of choice which outputs the decimals appropriately.

If you disagree and feel this is something Django should provide, please
raise the issue on the DevelopersMailingList.

--
Ticket URL: <https://code.djangoproject.com/ticket/24916#comment:1>

Django

unread,
Jun 4, 2015, 11:03:27 AM6/4/15
to django-...@googlegroups.com
#24916: DjangoJSONEncoder: Decimal type localization mechanism is missing
-------------------------------------+-------------------------------------
Reporter: vartagg | Owner: nobody

Type: Bug | Status: closed
Component: Core | Version: 1.8
(Serialization) |
Severity: Normal | Resolution: wontfix
Keywords: | Triage Stage:
| Unreviewed

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by vartagg):

The JSON standard for serializing decimal values does not provide for
localized formatting. (See JSON.org.) This is why values are not
localized. I think it would also make the date less portable across
locales.

By following this, support of Decimals in DjangoJSONEncoder makes sense
only for web-applications that don't use localizations.

If you need localized values, then I'd suggest to create a custom encoder
for your serializer of choice which outputs the decimals appropriately.

Ok, but DjangoJSONEncoder has only one method: "default", what making it
hard to override. How about to divide it to different methods? It would be
very helpful.

--
Ticket URL: <https://code.djangoproject.com/ticket/24916#comment:2>

Reply all
Reply to author
Forward
0 new messages