Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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")),),
),
Template(
def menu(menu, level=0, depth=1, **kwargs):
"""menu(menu, level=0, depth=1, **kwargs)
This tag expects the ``page`` variable to contain the page we're on
currently. The active pages are fetched using ``.objects.active()`` and
filtered further according to the arguments passed to the tag. This tag
depends on :class:`~feincms3.mixins.MenuMixin` and on a ``page`` context
variable which must be an instance of the pages model.
**Note**: MPTT levels are zero-based.
The default is to return all root nodes from the matching ``menu``.
"""
return concrete_model(MenuMixin).objects.active().filter(
menu=menu,
**kwargs
).extra(where=[
'depth BETWEEN %d AND %d' % (level + 1, level + depth),
])
def fill_menu_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, MenuMixin) and not sender._meta.abstract:
field = sender._meta.get_field("menu")
field.choices = sender.MENUS
field.default = field.choices[0][0]
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')),
),
),
Template(
class Meta:
abstract = True
@staticmethod
def fill_menu_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, MenuMixin) and not sender._meta.abstract:
field = sender._meta.get_field("menu")
field.choices = sender.MENUS
field.default = field.choices[0][0]
signals.class_prepared.connect(MenuMixin.fill_menu_choices)
class TemplateMixin(models.Model):
"""
It is sometimes useful to have different templates for CMS models such
as pages, articles or anything comparable. The ``TemplateMixin``
provides a ready-made solution for selecting django-content-editor
``Template`` instances through Django's administration interface.
"""
template_key = models.CharField(
_("template"),
max_length=100,
choices=(("", ""),), # Non-empty choices for get_*_display
)