Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
LanguageAndTranslationOfMixin,
MenuMixin,
RedirectMixin,
TemplateMixin,
)
from feincms3.pages import AbstractPage
from feincms3.plugins import external, html, image, richtext, snippet
class Page(
AbstractPage,
# For adding the articles app to pages through the CMS:
AppsMixin,
# Two page templates, one with only a main region and another with a
# sidebar as well:
TemplateMixin,
# We have a main and a footer navigation (meta):
MenuMixin,
# We're building a multilingual CMS. (Also, feincms3.apps depends on
# LanguageMixin currently):
LanguageAndTranslationOfMixin,
# Allow redirecting pages to other pages and/or arbitrary URLs:
RedirectMixin,
):
# TemplateMixin
TEMPLATES = [
Template(
key="standard",
title=_("standard"),
template_name="pages/standard.html",
regions=(Region(key="main", title=_("Main")),),
return self.template.regions if self.template else []
@staticmethod
def fill_template_key_choices(sender, **kwargs):
"""
Fills in the choices for ``menu`` from the ``MENUS`` class variable.
This method is a receiver of Django's ``class_prepared`` signal.
"""
if issubclass(sender, TemplateMixin) and not sender._meta.abstract:
field = sender._meta.get_field("template_key")
field.choices = [(t.key, t.title) for t in sender.TEMPLATES]
field.default = sender.TEMPLATES[0].key
sender.TEMPLATES_DICT = {t.key: t for t in sender.TEMPLATES}
signals.class_prepared.connect(TemplateMixin.fill_template_key_choices)
class LanguageMixin(models.Model):
"""
Pages may come in varying languages. ``LanguageMixin`` helps with that.
"""
language_code = models.CharField(
_("language"),
max_length=10,
choices=settings.LANGUAGES,
default=settings.LANGUAGES[0][0],
)
class Meta:
abstract = True
from django.db import models
from django.utils.translation import gettext_lazy as _
from content_editor.models import Region, Template, create_plugin_base
from feincms3.apps import AppsMixin
from feincms3.mixins import TemplateMixin, MenuMixin, LanguageMixin
from feincms3.pages import AbstractPage
from feincms3.plugins import image, richtext
class Page(
AbstractPage,
AppsMixin, # For adding the articles app to pages through the CMS.
TemplateMixin, # Two page templates, one with only a main
# region and another with a sidebar as well.
MenuMixin, # We have a main and a footer navigation (meta).
LanguageMixin, # We're building a multilingual CMS. (Also,
# feincms3.apps depends on LanguageMixin
# currently.)
):
# TemplateMixin
TEMPLATES = [
Template(
key='standard',
title=_('standard'),
template_name='pages/standard.html',
regions=(
Region(key='main', title=_('Main')),
),
def fill_template_key_choices(sender, **kwargs):
"""
Fills in the choices for ``menu`` from the ``MENUS`` class variable.
This method is a receiver of Django's ``class_prepared`` signal.
"""
if issubclass(sender, TemplateMixin) and not sender._meta.abstract:
field = sender._meta.get_field("template_key")
field.choices = [(t.key, t.title) for t in sender.TEMPLATES]
field.default = sender.TEMPLATES[0].key
sender.TEMPLATES_DICT = {t.key: t for t in sender.TEMPLATES}