Use new CMS (Migration)

Migrate to the new Content Management System and use data from xmm.

Requirements

XMM >= 1.23.0

Settings

The following changes has to be done in the settings.py First off all you have to deactivate CMS_LEGACY_MODE.

CMS_LEGACY_MODE = False

If you have catalog_node page types to migrate from xmm, the following configration must be made.

CMS_CATALOG_PAGE = {
    'page_type': 'default',
    'blocks': [{
        'active_languages': [],
        'attributes': {
            'cms_section_background_color': 'transparent',
            'cms_section_background_image': None,
            'cms_section_background_position': 'center center',
            'cms_section_width': 'full',
            'cms_section_heading': {lang: '' for lang, lang_label in LANGUAGES},
            'cms_section_style': 'frameless',
        },
        'attributes_desc': {},
        'blocks': [{
            'active_languages': [],
            'attributes': {
                'cms_node_node': None,
            },
            'attributes_desc': {},
            'is_active': True,
            'is_hidden': False,
            'restriction': '',
            'type': {'key': 'node'},
            'valid_from': None,
            'valid_until': None,
        }],
        'is_active': True,
        'is_hidden': False,
        'restriction': '',
        'type': {'key': 'section'},
        'valid_from': None,
        'valid_until': None,
    }],
}

INSTALLED_APPS

Add treewidget and tinymce to the INSTALLED_APPS section.

INSTALLED_APPS = [
    'colorfield',
    'treewidget',
    'tinymce',
    'modeltranslation',
    ...
]

MIDDLEWARE

Add the new CMSMiddleware as first entry.

MIDDLEWARE = [
    'eshop.modules.cms.middleware.CMSMiddleware',
    ...
]

VIEWS

CMS views are in the cms views package. The inheritance must be checked if the views have been overwritten.

VIEWS = {
   'cms-page-index': 'eshop.modules.cms.views.cms_page',
   'cms-page': 'eshop.modules.cms.views.cms_page',
}

TINYMCE

Add new tinymce editor settings.

TINYMCE_INCLUDE_JQUERY = False
TINYMCE_DEFAULT_CONFIG = {
    'theme': 'silver',
    'height': 400,
    'branding': False,
    'relative_urls': False,
    'convert_urls': False,
    'removed_menuitems': 'newdocument,visualaid,backcolor,forecolor',
    'plugins': (
        'advlist,autolink,lists,link,charmap,anchor,table,'
        'searchreplace,code,fullscreen,emoticons,table,paste,'
        'code,wordcount,help'
    ),
    'toolbar': (
        'undo redo | formatselect | '
        'bold italic | alignleft aligncenter '
        'alignright alignjustify | bullist numlist | table'
    ),
}

DEBUG_TOOLBAR

Add __preview__ lookup to show_toolbar_callback.

def show_toolbar_callback(request):
    if '__preview__' in request.GET:
        return False
    ...

MEDIA

Add cms media root and upload root to settings.py and create the corresponding directories on the filesystem:

UPLOAD_ROOT = BASE_DIR('upload')
CMS_MEDIA_ROOT = BASE_DIR('media/cms')

Unused settings

The following settings keys can be deleted:

CMS_OBJECT
CMS_PAGE_CLASS
CMS_PAGE_CLASSES
CMS_BLOCK_CLASSES
CMS_NOTIFICATIONS_URL
CMS_FORMS
CMS_MODELS

Backend

Admin

Add notifications and cms-sites to customer admin.

admin_site.register(Notification, NotificationAdmin)
admin_site.register(Device, DeviceAdmin)
admin_site.register(NewsCategory, NewsCategoryAdmin)
admin_site.register(CMSSite, CMSSiteAdmin)

Frontend

CMS Templates

Check project specific cms templates and change extends to cms package. Check your templates and change logic to get block/page data.

{% extends "cms/bocks/article.html" %}
{% extends "cms/pages/default.html" %}

New you will find the form template in the block directory:

cms/blocks/contact_form.html

Header Template

Add CMS navigation entry for cms users to shopheader.html:

{% block hamburger-navigation-account-admin-entries %}
    {% if user.is_staff %}
        {% url "admin:index" as nav_url %}
        {% widget "navigation:mobile-entry" icon="gear" label=_("Administration") url=nav_url target="admin" app="django.contrib.admin" %}
    {% elif user.has_cms_permission %}
        {% url "cmsadmin:index" as nav_url %}
        {% widget "navigation:mobile-entry" icon="edit" label=_("CMS") url=nav_url target="cms" app="django.contrib.admin" %}
    {% endif %}
    ...
{% endblock %}

{% block admin-navigation-admin-entries %}
    {% if user.is_staff %}
        {% url "admin:index" as nav_url %}
        {% widget "navigation:entry" icon="gear" label=_("Administration") url=nav_url target="admin" app="django.contrib.admin" %}
    {% elif user.has_cms_permission %}
        {% url "cmsadmin:index" as nav_url %}
        {% widget "navigation:entry" icon="edit" label=_("CMS") url=nav_url target="cms" app="django.contrib.admin" %}
    {% endif %}
    ...
{% endblock %}

Replace and migrate all page data lookups:

page.attributes.cms_megamenu  ->  page.content.megamenu

Migrate legacy cms data

Execute the following migrate command and sync legacy cms data from xmm and all used media files. Start migration twice to resolve referencing issues.

./manage.py migrate_legacy_cms_data
./manage.py migrate_legacy_cms_data

./manage.py rebuild_index cms
./manage.py rebuild_index published_cms

Docker Konfiguration auf Kundensystem

Create new cms media directory.

mkdir /var/lib/eshop/media/cms

Map new volume in docker-compose.yml.

/var/lib/eshop/media/cms:/app/media/cms