<commit_before>"""Toolbar extensions for CMS"""
from django.core.urlresolvers import reverse
from django.utils.translation import ugettext_lazy as _

from cms.toolbar_base import CMSToolbar
from cms.toolbar_pool import toolbar_pool


class ZinniaToolbar(CMSToolbar):

    def populate(self):
        user = self.request.user
        zinnia_menu = self.toolbar.get_or_create_menu(
            'zinnia-menu', _('Zinnia'))

        if user.has_perm('zinnia.add_entry'):
            url = reverse('admin:zinnia_entry_add')
            zinnia_menu.add_sideframe_item(_('New entry'), url=url)

        if user.has_perm('zinnia.add_category'):
            url = reverse('admin:zinnia_category_add')
            zinnia_menu.add_sideframe_item(_('New category'), url=url)

        if zinnia_menu.get_items():
            zinnia_menu.add_break()

        if user.has_perm('zinnia.change_entry'):
            url = reverse('admin:zinnia_entry_changelist')
            zinnia_menu.add_sideframe_item(_('Entries list'), url=url)

        if user.has_perm('zinnia.change_category'):
            url = reverse('admin:zinnia_category_changelist')
            zinnia_menu.add_sideframe_item(_('Categories list'), url=url)

        if user.has_perm('tagging.change_tag'):
            url = reverse('admin:tagging_tag_changelist')
            zinnia_menu.add_sideframe_item(_('Tags list'), url=url)

        if not zinnia_menu.get_items():
            self.toolbar.remove_item(zinnia_menu)


toolbar_pool.register(ZinniaToolbar)<commit_msg>Disable menu items instead of removing them (when lacking permissions)<commit_after>"""Toolbar extensions for CMS"""
from django.core.urlresolvers import reverse
from django.utils.translation import ugettext_lazy as _

from cms.toolbar_base import CMSToolbar
from cms.toolbar_pool import toolbar_pool


class ZinniaToolbar(CMSToolbar):

    def populate(self):
        user = self.request.user
        zinnia_menu = self.toolbar.get_or_create_menu(
            'zinnia-menu', _('Zinnia'))

        url = reverse('admin:zinnia_entry_add')
        zinnia_menu.add_sideframe_item(
            _('New entry'), url=url,
            disabled=not user.has_perm('zinnia.add_entry'))

        url = reverse('admin:zinnia_category_add')
        zinnia_menu.add_sideframe_item(
            _('New category'), url=url,
            disabled=not user.has_perm('zinnia.add_category'))

        zinnia_menu.add_break()

        url = reverse('admin:zinnia_entry_changelist')
        zinnia_menu.add_sideframe_item(
            _('Entries list'), url=url,
            disabled=not user.has_perm('zinnia.change_entry'))

        url = reverse('admin:zinnia_category_changelist')
        zinnia_menu.add_sideframe_item(
            _('Categories list'), url=url,
            disabled=not user.has_perm('zinnia.change_category'))

        url = reverse('admin:tagging_tag_changelist')
        zinnia_menu.add_sideframe_item(
            _('Tags list'), url=url,
            disabled=not user.has_perm('tagging.change_tag'))

        # remove complete menu if all items are disabled
        for item in zinnia_menu.get_items():
            if hasattr(item, 'disabled') and not item.disabled:
                return
        self.toolbar.remove_item(zinnia_menu)


toolbar_pool.register(ZinniaToolbar)
{'fraction_non_alphanumeric': 0.10336465595635042, 'fraction_numerical': 0.0, 'mean_word_length': 3.094292803970223, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '3493890', 'n_tokens_mistral': 1049, 'n_tokens_neox': 1027, 'n_words': 175}