How to use the feincms3.mixins.MenuMixin function in feincms3

To help you get started, we’ve selected a few feincms3 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github matthiask / feincms3 / tests / testapp / models.py View on Github external
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(
github matthiask / feincms3 / feincms3 / templatetags / feincms3_pages.py View on Github external
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),
    ])
github matthiask / feincms3 / feincms3 / mixins.py View on Github external
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]
github matthiask / feincms3-example / app / pages / models.py View on Github external
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(
github matthiask / feincms3 / feincms3 / mixins.py View on Github external
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
    )