Skip to main content

Adds import and export of plugin data.

Project description

pypi coverage python django djangocms

django CMS Transfer is an experimental package that allows you to export and import plugin data from a page or a placeholder. It does not support foreign key relations and won’t import/export related data, such as media.

preview.gif

Contribute to this project and win rewards

Because this is an open-source project, we welcome everyone to get involved in the project and receive a reward for their contribution. Become part of a fantastic community and help us make django CMS the best CMS in the world.

We’ll be delighted to receive your feedback in the form of issues and pull requests. Before submitting your pull request, please review our contribution guidelines.

We’re grateful to all contributors who have helped create and maintain this package. Contributors are listed at the contributors section.

Documentation

The setting DJANGO_CMS_TRANSFER_SERIALIZER allows registration of a custom JSON serializer. An example use case would be subclassing Django’s built-in Python serializer to base64-encode inline image data.

See REQUIREMENTS in the setup.py file for additional dependencies:

Installation

For a manual install:

  • run pip install djangocms-transfer

  • add djangocms_transfer to your INSTALLED_APPS

  • run python manage.py migrate djangocms_transfer

Version Compatibility

For django CMS 4.0 or later, you must use djangocms-transfer 2.0 or later.

For django CMS 3.7 through 3.11 use versions 1.x of djangocms-transfer.

Customization

Following settings are available:

  • DJANGOCMS_TRANSFER_PROCESS_EXPORT_PLUGIN_DATA:

    Enables processing of plugin instances prior to serialization, e.g. myapp.module.function.

  • DJANGOCMS_TRANSFER_PROCESS_IMPORT_PLUGIN_DATA:

    Enables processing of plugin instances prior to saving, e.g. myapp.module.function. For example: set default-values for ForeignKeys (images for django_filer, ..)

As an example the combination of _PROCESS_EXPORT_PLUGIN_DATA and _PROCESS_IMPORT_PLUGIN_DATA lets you export and import the data between different systems while setting the contents as you need it:

# settings.py
.._PROCESS_EXPORT_PLUGIN_DATA = "myapp.some.module.export_function"
.._PROCESS_IMPORT_PLUGIN_DATA = "myapp.some.module.import_function"

# custom functions
def export_function(plugin, plugin_data):
    # remove child-plugins which can't be handled
    if plugin.parent_id and plugin.parent.plugin_type == "SomeParentPlugin":
        return None
    # change data
    if plugin.plugin_type == "SomePlugin":
        plugin_data["data"].update({
            "some_field": "TODO: change me",
        })
    return plugin_data

def import_function(deserialized_object):
    some_related_object = MyModel.objects.first()
    for field in deserialized_object.object._meta.fields:
        # example of setting a default value for a related field
        if isinstance(field, ForeignKey):
            value = getattr(deserialized_object.object, field.attname)
            if field.related_model == MyModel and value is not None:
                setattr(deserialized_object.object, field.name, some_related_object)

Running Tests

You can run tests by executing:

virtualenv env
source env/bin/activate
pip install -r tests/requirements/base.txt
python setup.py test

For code formatting, black is used. To automatically fix errors reported from black, you can install it via virtualenv and pip install -r tests/requirements/base.txt. After this you just need to run tools/black.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

djangocms_transfer-2.0.0a0.tar.gz (15.3 kB view details)

Uploaded Source

Built Distribution

djangocms_transfer-2.0.0a0-py3-none-any.whl (15.6 kB view details)

Uploaded Python 3

File details

Details for the file djangocms_transfer-2.0.0a0.tar.gz.

File metadata

  • Download URL: djangocms_transfer-2.0.0a0.tar.gz
  • Upload date:
  • Size: 15.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for djangocms_transfer-2.0.0a0.tar.gz
Algorithm Hash digest
SHA256 ee64cc6599a8a899dd16625117be702c420026ef2a55153b520239dbe99c3086
MD5 95159b9e9accb653fb381494e69fab4a
BLAKE2b-256 8fabe9bbe95af8f043c49840cf0654bc8fa99aa339973b7eed0a6979ae45e983

See more details on using hashes here.

File details

Details for the file djangocms_transfer-2.0.0a0-py3-none-any.whl.

File metadata

File hashes

Hashes for djangocms_transfer-2.0.0a0-py3-none-any.whl
Algorithm Hash digest
SHA256 0989ecd508eb7c2bc19926b79924b788b290a20bc847020af03f5519dc44da53
MD5 97585aa33a53412d97352a68c16d457b
BLAKE2b-256 d447ed61c7dfdb56be1c719e0a352a1293154adf5281ab5677511d0c59170772

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page