Skip to content

Commit

Permalink
Merge pull request #256 from barseghyanartur/242-Form-Export-fails-si…
Browse files Browse the repository at this point in the history
…mplejson

242 Replace simplejson with json
  • Loading branch information
barseghyanartur authored Jan 25, 2021
2 parents 8f2167e + 43c0f98 commit c6f18cf
Show file tree
Hide file tree
Showing 14 changed files with 58 additions and 26 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@ are used for versioning (schema follows below):
0.3.4 to 0.4).
- All backwards incompatible changes are mentioned in this document.

0.17.1
------
2021-01-21

.. note::

Release dedicated to defenders of Armenia and Artsakh (Nagorno Karabakh)
and all the victims of Turkish and Azerbaijani aggression.

- Replace outdated `simplejson` with `json`.

0.17
----
2020-12-28
Expand Down
2 changes: 1 addition & 1 deletion examples/recepes/auto_save_every_fobi_form.rst
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ plugin (copy-paste mainly).
import datetime
import simplejson as json
import json
from fobi.base import (
form_callback_registry,
Expand Down
1 change: 0 additions & 1 deletion examples/requirements/common.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ Pygments>=2.0.2
pytz>=2019.1
#requests==2.8.1
simplegeneric>=0.8.1
simplejson>=3.8.0
six>=1.10.0
snowballstemmer>=1.2.0
Sphinx>=1.3.1
Expand Down
3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from distutils.version import LooseVersion
from setuptools import setup, find_packages

version = '0.17'
version = '0.17.1'

# ***************************************************************************
# ************************** Django version *********************************
Expand Down Expand Up @@ -249,7 +249,6 @@
'Unidecode>=0.04.1',
'vishap>=0.1.5,<2.0',
'easy-thumbnails>=2.4.1',
'simplejson>=3.0.0',
]

tests_require = [
Expand Down
2 changes: 1 addition & 1 deletion src/fobi/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
__title__ = 'django-fobi'
__version__ = '0.17'
__version__ = '0.17.1'
__author__ = 'Artur Barseghyan <[email protected]>'
__copyright__ = '2014-2020 Artur Barseghyan'
__license__ = 'GPL 2.0/LGPL 2.1'
Expand Down
9 changes: 5 additions & 4 deletions src/fobi/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@

from collections import defaultdict, OrderedDict

import simplejson as json
import json

from django import forms
from django.core.serializers.json import DjangoJSONEncoder
from django.forms import ModelForm
from django.forms.utils import ErrorList
from django.http import Http404
Expand Down Expand Up @@ -755,7 +756,7 @@ def _get_plugin_data(self, fields, request=None, json_format=True):
if not json_format:
return data

return json.dumps(data)
return json.dumps(data, cls=DjangoJSONEncoder)

def get_plugin_data(self, request=None, json_format=True):
"""Get plugin data.
Expand Down Expand Up @@ -1357,7 +1358,7 @@ def get_cloned_plugin_data(self, update={}):
for prop, value in update.items():
data.update({prop: value})

return json.dumps(data)
return json.dumps(data, cls=DjangoJSONEncoder)

def get_updated_plugin_data(self, update={}):
"""Get updated plugin data.
Expand All @@ -1376,7 +1377,7 @@ def get_updated_plugin_data(self, update={}):
for prop, value in update.items():
data.update({prop: value})

return json.dumps(data)
return json.dumps(data, cls=DjangoJSONEncoder)

def pre_processor(self):
"""Pre-processor (callback).
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from __future__ import absolute_import

from django.apps import apps
from django.core.serializers.json import DjangoJSONEncoder
from django.forms.models import ModelMultipleChoiceField
from django.forms.widgets import SelectMultiple
from django.utils.translation import gettext_lazy as _

import simplejson as json
import json

from fobi.base import FormFieldPlugin, get_theme
from fobi.constants import (
Expand Down Expand Up @@ -110,7 +111,10 @@ def submit_plugin_form_data(self, form_entry, request, form,

# Overwrite ``cleaned_data`` of the ``form`` with object qualifier.
if values:
form.cleaned_data[self.data.name] = json.dumps(values)
form.cleaned_data[self.data.name] = json.dumps(
values,
cls=DjangoJSONEncoder
)
else:
del form.cleaned_data[self.data.name]

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
from __future__ import absolute_import

from django.apps import apps
from django.core.serializers.json import DjangoJSONEncoder
from django.forms.widgets import SelectMultiple
from django.utils.translation import gettext_lazy as _

from mptt.fields import TreeNodeMultipleChoiceField

import simplejson as json
import json

from fobi.base import FormFieldPlugin, get_theme
from fobi.constants import (
Expand Down Expand Up @@ -102,7 +103,10 @@ def submit_plugin_form_data(self, form_entry, request, form,

# Overwrite ``cleaned_data`` of the ``form`` with object qualifier.
if values:
form.cleaned_data[self.data.name] = json.dumps(values)
form.cleaned_data[self.data.name] = json.dumps(
values,
cls=DjangoJSONEncoder
)
else:
del form.cleaned_data[self.data.name]

Expand Down
17 changes: 12 additions & 5 deletions src/fobi/contrib/plugins/form_handlers/db_store/base.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import datetime

import simplejson as json
import json

from django.core.serializers.json import DjangoJSONEncoder
from django.utils.translation import gettext_lazy as _
from django.urls import reverse

Expand Down Expand Up @@ -82,8 +83,11 @@ def save_form_data_entry(self,
saved_form_data_entry = SavedFormDataEntry(
form_entry=form_entry,
user=request.user if request.user and request.user.pk else None,
form_data_headers=json.dumps(field_name_to_label_map),
saved_data=json.dumps(cleaned_data)
form_data_headers=json.dumps(
field_name_to_label_map,
cls=DjangoJSONEncoder
),
saved_data=json.dumps(cleaned_data, cls=DjangoJSONEncoder)
)
saved_form_data_entry.save()

Expand Down Expand Up @@ -173,8 +177,11 @@ def run(self, form_wizard_entry, request, form_list, form_wizard,
saved_form_wizard_data_entry = SavedFormWizardDataEntry(
form_wizard_entry=form_wizard_entry,
user=request.user if request.user and request.user.pk else None,
form_data_headers=json.dumps(field_name_to_label_map),
saved_data=json.dumps(cleaned_data)
form_data_headers=json.dumps(
field_name_to_label_map,
cls=DjangoJSONEncoder
),
saved_data=json.dumps(cleaned_data, cls=DjangoJSONEncoder)
)
saved_form_wizard_data_entry.save()

Expand Down
11 changes: 8 additions & 3 deletions src/fobi/contrib/plugins/form_handlers/db_store/callbacks.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import datetime

import simplejson as json
import json

from django.core.serializers.json import DjangoJSONEncoder

from fobi.base import (
FormCallback,
Expand Down Expand Up @@ -59,7 +61,10 @@ def callback(self, form_entry, request, form):
saved_form_data_entry = SavedFormDataEntry(
form_entry=form_entry,
user=request.user if request.user and request.user.pk else None,
form_data_headers=json.dumps(field_name_to_label_map),
saved_data=json.dumps(cleaned_data)
form_data_headers=json.dumps(
field_name_to_label_map,
cls=DjangoJSONEncoder
),
saved_data=json.dumps(cleaned_data, cls=DjangoJSONEncoder)
)
saved_form_data_entry.save()
2 changes: 1 addition & 1 deletion src/fobi/contrib/plugins/form_handlers/db_store/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from django.http import HttpResponse

import simplejson as json
import json

from six import StringIO, BytesIO, text_type

Expand Down
2 changes: 1 addition & 1 deletion src/fobi/contrib/plugins/form_handlers/db_store/models.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import unicode_literals

import bleach
import simplejson as json
import json
from six import python_2_unicode_compatible, string_types

from django.conf import settings
Expand Down
6 changes: 4 additions & 2 deletions src/fobi/form_importers.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from django.urls import reverse

import simplejson as json
import json

from django.core.serializers.json import DjangoJSONEncoder
from six import text_type

from .base import BaseRegistry
Expand Down Expand Up @@ -104,7 +105,8 @@ def import_data(self, form_properties, form_data):

# Assign form data
form_element_entry.plugin_data = json.dumps(
self.extract_field_properties(field_data)
self.extract_field_properties(field_data),
cls=DjangoJSONEncoder
)

# Assign position in form
Expand Down
2 changes: 1 addition & 1 deletion src/fobi/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from collections import OrderedDict

import simplejson as json
import json

# from six import string_types

Expand Down

0 comments on commit c6f18cf

Please sign in to comment.