# Path: djangocms_blog/settings.py
# def get_setting(name):
#     """Get setting value from django settings with fallback to globals defaults."""
#     from django.conf import settings
# 
#     return getattr(settings, "BLOG_%s" % name, params["BLOG_%s" % name])


from cms.toolbar_base import CMSToolbar
from cms.toolbar_pool import toolbar_pool
from cms.utils.urlutils import admin_reverse
from django.urls import reverse
from django.utils.translation import gettext_lazy as _, override
from .settings import get_setting
                import djangocms_page_meta  # NOQA
                import djangocms_page_tags  # NOQA



@toolbar_pool.register
class BlogToolbar(CMSToolbar):
    def populate(self):
        if (
            not self.is_current_app and not get_setting("ENABLE_THROUGH_TOOLBAR_MENU")
        ) or not self.request.user.has_perm("djangocms_blog.add_post"):
            return  # pragma: no cover
        admin_menu = self.toolbar.get_or_create_menu("djangocms_blog", _("Blog"))
        with override(self.current_lang):
            url = reverse("admin:djangocms_blog_post_changelist")
            admin_menu.add_modal_item(_("Post list"), url=url)
            url = reverse("admin:djangocms_blog_post_add")
            admin_menu.add_modal_item(_("Add post"), url=url)
            current_config = getattr(self.request, get_setting("CURRENT_NAMESPACE"), None)
            if current_config:
                url = reverse("admin:djangocms_blog_blogconfig_change", args=(current_config.pk,))
                admin_menu.add_modal_item(_("Edit configuration"), url=url)


# Path: djangocms_blog/settings.py
# def get_setting(name):
#     """Get setting value from django settings with fallback to globals defaults."""
#     from django.conf import settings
# 
#     return getattr(settings, "BLOG_%s" % name, params["BLOG_%s" % name])


# Path: djangocms_blog/cms_toolbars.py
from cms.toolbar_base import CMSToolbar
from cms.toolbar_pool import toolbar_pool
from cms.utils.urlutils import admin_reverse
from django.urls import reverse
from django.utils.translation import gettext_lazy as _, override
from .settings import get_setting
                import djangocms_page_meta  # NOQA
                import djangocms_page_tags  # NOQA




@toolbar_pool.register
class BlogToolbar(CMSToolbar):
    def populate(self):
        if (
            not self.is_current_app and not get_setting("ENABLE_THROUGH_TOOLBAR_MENU")
        ) or not self.request.user.has_perm("djangocms_blog.add_post"):
            return  # pragma: no cover
        admin_menu = self.toolbar.get_or_create_menu("djangocms_blog", _("Blog"))
        with override(self.current_lang):
            url = reverse("admin:djangocms_blog_post_changelist")
            admin_menu.add_modal_item(_("Post list"), url=url)
            url = reverse("admin:djangocms_blog_post_add")
            admin_menu.add_modal_item(_("Add post"), url=url)
            current_config = getattr(self.request, get_setting("CURRENT_NAMESPACE"), None)
            if current_config:
                url = reverse("admin:djangocms_blog_blogconfig_change", args=(current_config.pk,))
                admin_menu.add_modal_item(_("Edit configuration"), url=url)


            current_post = getattr(self.request, get_setting("CURRENT_POST_IDENTIFIER"), None)