Skip to content

maykinmedia/djangocms-export-page

Repository files navigation

Version:0.2.1
Source:https://bitbucket.org/maykinmedia/djangocms-export-page
Keywords:django cms export docx
PythonVersion:3.11

Build status Code quality checks black Coverage status

python-versions django-versions pypi-version

Export a Django CMS page or a model view to a DOCX document

  • Adds a menu entry in the CMS toolbar to export the current page
  • Ability to export a custom model, including placeholder fields

img/page-export-menu.png

  • Python 3.11 or above
  • Django 3.2 or above
  • Django CMS 4.1 or above
pip install djangocms-export-page

In your Django settings:

INSTALLED_APPS = [
    ...
    'djangocms_export_page',
    ...
]

CMS Page don't need any extra configuration to work.

If a Plugin has a reverse ForeignKey that would behave like children, add the following to the CMSPlugin model class:

_export_page = {
    'children': 'items'
}

@property
def items(self):
    return self.frequentlyaskedquestion_set.all()

where items is a iterable attribute of the model class.

And for on the ForeignKey Django model class:

_export_page = {
    'fields': ['name', ... ]
}

If you want to export the contents of a ForeignKey or OneToOneField inside the regular model you can use _export_page_field_names. Now these fields will be put in the some level as the plugin fields.

_export_page_field_names = ['number', 'title', 'lead', 'display_date', 'date', 'location']

If you need to export a Django model included in a AppHook, add the following to the model class:

_export_page = {
    'sections': [{
        'name': 'Meta',
        'fields': ['title', ... ]
    }, {
        'name': 'Body',
        'fields': ['content']
    }],
}

It's better to put the PlaceholderField (here content) in a separate section.

If you also want to export the static aliases of a page, some extra configuration is required. There is a setting called EXPORT_STATIC_ALIASES.

EXPORT_STATIC_ALIASES = {
    'template_name': ['static_alias_code']
}

So with the cms settings it will look like this:

# test.html
<div>
    {% static_alias 'test-placeholder' %}
</div>

# settings.py
CMS_TEMPLATES = [
    ('test.html', _('Test page')),
]

EXPORT_STATIC_ALIASES = {
    'test.html': ['test-placeholder']
}