Skip to content

Commit

Permalink
feat: created custom django_cms serializer to be able to handle djang…
Browse files Browse the repository at this point in the history
…o cms filer images
  • Loading branch information
mihalikv committed Aug 12, 2022
1 parent 2601c0b commit 2d1e507
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Changelog
==================

* Added support for custom serializer
* Added serializer `django_cms` to be able to serializer `filer.Image`
* Added serializer `django_cms` to be able to serialize `filer.Image`

1.0.0 (2020-09-02)
==================
Expand Down
5 changes: 2 additions & 3 deletions djangocms_transfer/datastructures.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@

from cms.models import CMSPlugin

from .utils import get_plugin_model

from .utils import get_plugin_model, get_serializer_name

BaseArchivedPlugin = namedtuple(
'ArchivedPlugin',
Expand All @@ -35,7 +34,7 @@ def deserialized_instance(self):
}

# TODO: Handle deserialization error
return list(deserialize('python', [data]))[0]
return list(deserialize(get_serializer_name(), [data]))[0]

@transaction.atomic
def restore(self, placeholder, language, parent=None, with_data=True):
Expand Down
4 changes: 2 additions & 2 deletions djangocms_transfer/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from django.core import serializers

from .utils import get_plugin_fields, get_plugin_model
from .utils import get_plugin_fields, get_plugin_model, get_serializer_name


def get_bound_plugins(plugins):
Expand Down Expand Up @@ -41,7 +41,7 @@ def get_plugin_data(plugin, only_meta=False):
custom_data = None
else:
plugin_fields = get_plugin_fields(plugin.plugin_type)
_plugin_data = serializers.serialize('python', (plugin,), fields=plugin_fields)[0]
_plugin_data = serializers.serialize(get_serializer_name(), (plugin,), fields=plugin_fields)[0]
custom_data = _plugin_data['fields']

plugin_data = {
Expand Down
5 changes: 5 additions & 0 deletions djangocms_transfer/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,8 @@ def get_plugin_fields(plugin_type):
@lru_cache()
def get_plugin_model(plugin_type):
return get_plugin_class(plugin_type).model


def get_serializer_name(default='python'):
from django.conf import settings
return getattr(settings, 'DJANGO_CMS_TRANSFER_SERIALIZER', default)

0 comments on commit 2d1e507

Please sign in to comment.