<commit_before>from __future__ import absolute_import, unicode_literals
from distutils.version import LooseVersion

from django.conf import settings
from django.utils.functional import SimpleLazyObject
from django.utils.translation import ugettext_lazy as _

from wagtail.wagtailadmin.edit_handlers import (
    FieldPanel, FieldRowPanel, InlinePanel, MultiFieldPanel, PageChooserPanel,
    ObjectList, TabbedInterface)

from . import app_settings


# ########################################################
# For menu models
# ########################################################
def _define_inlinepanel(relation_name, **kwargs):
    klass = InlinePanel
    panel_kwargs = dict(
        label=_('menu items')
    )
    if 'condensedinlinepanel' in settings.INSTALLED_APPS:
        import condensedinlinepanel
        from condensedinlinepanel.edit_handlers import CondensedInlinePanel
        if LooseVersion(condensedinlinepanel.__version__) >= LooseVersion('0.3'):
            klass = CondensedInlinePanel
            panel_kwargs = dict(
                heading=_('Menu items'),
                label=("Add new item"),
                new_card_header_text=_("New item"),
            )
    panel_kwargs.update(kwargs)
    return klass(relation_name, **panel_kwargs)


def FlatMenuItemsInlinePanel(**kwargs):  # noqa
    """
    If ``collapsedinlinepanel`` is installed a `CondensedInlinePanel` will be
    used, otherwise Wagtail's built-in `InlinePanel` will be used.
    Use in panel definitions like so:

    panels = [
        FieldPanel('title'),
        FlatMenuItemsInlinePanel(),
    ]
    """
    return _define_inlinepanel(
        rel_name=app_settings.FLAT_MENU_ITEMS_RELATED_NAME, **kwargs)


def MainMenuItemsInlinePanel(**kwargs):  # noqa
    """
    Returns a ``InlinePanel`` instance for editing menu items for a main menu.
    If ``collapsedinlinepanel`` is installed a ``CondensedInlinePanel``
    instance will be returned instead. Use in panel definitions like so:

    panels = [
        FieldPanel('title'),
        MainMenuItemsInlinePanel(),
    ]
    """
    return _define_inlinepanel(
        rel_name=app_settings.MAIN_MENU_ITEMS_RELATED_NAME, **kwargs)


main_menu_content_panels = [
    SimpleLazyObject(MainMenuItemsInlinePanel),
]

flat_menu_content_panels = [
    MultiFieldPanel(
        heading=_("Menu details"),
        children=(
            FieldPanel('title'),
            FieldPanel('site'),
            FieldPanel('handle'),
            FieldPanel('heading'),
        ),
        classname="collapsible"
    ),
    SimpleLazyObject(FlatMenuItemsInlinePanel),
]

menu_settings_panels = [
    MultiFieldPanel(
        heading=_('Rendering setings'),
        children=(
            FieldPanel('max_levels'),
            FieldPanel('use_specific')
        ),
        classname="collapsible"
    ),
]

<commit_msg>- Now that we're testing the result of FlatMenuItemsInlinePanel and MainMenuItemsInlinePanel instead of the values of flat_menu_content_panels and main_menu_content_panels, the SimpleLazyObject isn't needed, so removing. - For consisitency/simplicity, just use standard dict definition syntax in _define_inlinepanel - Update docstrings for FlatMenuItemsInlinePanel and MainMenuItemsInlinePanel<commit_after>from __future__ import absolute_import, unicode_literals
from distutils.version import LooseVersion

from django.conf import settings
from django.utils.translation import ugettext_lazy as _

from wagtail.wagtailadmin.edit_handlers import (
    FieldPanel, FieldRowPanel, InlinePanel, MultiFieldPanel, PageChooserPanel,
    ObjectList, TabbedInterface)

from . import app_settings


# ########################################################
# For menu models
# ########################################################
def _define_inlinepanel(relation_name, **kwargs):
    klass = InlinePanel
    defaults = {'label': _('menu items')}
    if 'condensedinlinepanel' in settings.INSTALLED_APPS:
        import condensedinlinepanel
        from condensedinlinepanel.edit_handlers import CondensedInlinePanel
        if LooseVersion(condensedinlinepanel.__version__) >= LooseVersion('0.3'):
            klass = CondensedInlinePanel
            defaults = {
                'heading': _('Menu items'),
                'label': _("Add new item"),
                'new_card_header_text': _("New item"),
            }
    defaults.update(kwargs)
    return klass(relation_name, **defaults)


def FlatMenuItemsInlinePanel(**kwargs):  # noqa
    """
    Returns either a ``InlinePanel`` or ``CondensedInlinePanel`` instance (
    depending on whether a sufficient version of `condensedinlinepanel` is
    installed) for editing menu items for a flat menu.

    Use in panel definitions like any standard panel class. Any supplied kwargs
    will be passed on as kwargs to the target class's __init__ method.
    """
    return _define_inlinepanel(
        relation_name=app_settings.FLAT_MENU_ITEMS_RELATED_NAME, **kwargs)


def MainMenuItemsInlinePanel(**kwargs):  # noqa
    """
    Returns either a ``InlinePanel`` or ``CondensedInlinePanel`` instance (
    depending on whether a sufficient version of `condensedinlinepanel` is
    installed) for editing menu items for a main menu.

    Use in panel definitions like any standard panel class. Any supplied kwargs
    will be passed on as kwargs to the target class's __init__ method.
    """
    return _define_inlinepanel(
        relation_name=app_settings.MAIN_MENU_ITEMS_RELATED_NAME, **kwargs)


main_menu_content_panels = [
    MainMenuItemsInlinePanel(),
]

flat_menu_content_panels = [
    MultiFieldPanel(
        heading=_("Menu details"),
        children=(
            FieldPanel('title'),
            FieldPanel('site'),
            FieldPanel('handle'),
            FieldPanel('heading'),
        ),
        classname="collapsible"
    ),
    FlatMenuItemsInlinePanel(),
]

menu_settings_panels = [
    MultiFieldPanel(
        heading=_('Rendering setings'),
        children=(
            FieldPanel('max_levels'),
            FieldPanel('use_specific')
        ),
        classname="collapsible"
    ),
]


{'fraction_non_alphanumeric': 0.11739768465677483, 'fraction_numerical': 0.0006522093592043046, 'mean_word_length': 3.4806428049671294, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3063687', 'n_tokens_mistral': 1657, 'n_tokens_neox': 1647, 'n_words': 413}