# Path: djangocms_blog/cms_appconfig.py
# class BlogConfig(TranslatableModel, AppHookConfig):
#     """
#     Adds translatable, per-app-instance fields.
#     """
# 
#     translations = TranslatedFields(
#         app_title=models.CharField(_("application title"), max_length=234),
#         object_name=models.CharField(_("object name"), max_length=234, default=get_setting("DEFAULT_OBJECT_NAME")),
#     )
# 
#     class Meta:
#         verbose_name = _("blog config")
#         verbose_name_plural = _("blog configs")
# 
#     def get_app_title(self):
#         return getattr(self, "app_title", _("untitled"))
# 
#     @property
#     def schemaorg_type(self):
#         """Compatibility shim to fetch data from legacy gplus_type field."""
#         return self.gplus_type
# 
# Path: djangocms_blog/cms_menus.py
# class BlogCategoryMenu(CMSAttachMenu):
#     """
#     Main menu class
# 
#     Handles all types of blog menu
#     """
# 
#     name = _("Blog menu")
#     _config = {}
# 
#     def get_nodes(self, request):
#         """
#         Generates the nodelist
# 
#         :param request:
#         :return: list of nodes
#         """
#         nodes = []
# 
#         language = get_language_from_request(request, check_path=True)
#         current_site = get_current_site(request)
# 
#         page_site = self.instance.node.site
#         if self.instance and page_site != current_site:
#             return []
# 
#         categories_menu = False
#         posts_menu = False
#         config = False
#         if self.instance:
#             if not self._config.get(self.instance.application_namespace, False):
#                 try:
#                     self._config[self.instance.application_namespace] = BlogConfig.objects.get(
#                         namespace=self.instance.application_namespace
#                     )
#                 except BlogConfig.DoesNotExist as e:
#                     logger.exception(e)
#                     return []
#             config = self._config[self.instance.application_namespace]
#             if not getattr(request, "toolbar", False) or not request.toolbar.edit_mode_active:
#                 if self.instance == self.instance.get_draft_object():
#                     return []
#             else:
#                 if self.instance == self.instance.get_public_object():
#                     return []
#         if config and config.menu_structure in (MENU_TYPE_COMPLETE, MENU_TYPE_CATEGORIES):
#             categories_menu = True
#         if config and config.menu_structure in (MENU_TYPE_COMPLETE, MENU_TYPE_POSTS):
#             posts_menu = True
#         if config and config.menu_structure in (MENU_TYPE_NONE,):
#             return nodes
# 
#         used_categories = []
#         if posts_menu:
#             posts = Post.objects
#             if hasattr(self, "instance") and self.instance:
#                 posts = posts.namespace(self.instance.application_namespace).on_site()
#             posts = (
#                 posts.active_translations(language)
#                 .distinct()
#                 .select_related("app_config")
#                 .prefetch_related("translations", "categories")
#             )
#             for post in posts:
#                 post_id = None
#                 parent = None
#                 used_categories.extend(post.categories.values_list("pk", flat=True))
#                 if categories_menu:
#                     category = post.categories.first()
#                     if category:
#                         parent = "{}-{}".format(category.__class__.__name__, category.pk)
#                         post_id = ("{}-{}".format(post.__class__.__name__, post.pk),)
#                 else:
#                     post_id = ("{}-{}".format(post.__class__.__name__, post.pk),)
#                 if post_id:
#                     node = NavigationNode(post.get_title(), post.get_absolute_url(language), post_id, parent)
#                     nodes.append(node)
# 
#         if categories_menu:
#             categories = BlogCategory.objects
#             if config:
#                 categories = categories.namespace(self.instance.application_namespace)
#             if config and not config.menu_empty_categories:
#                 categories = categories.active_translations(language).filter(pk__in=used_categories).distinct()
#             else:
#                 categories = categories.active_translations(language).distinct()
#             categories = (
#                 categories.order_by("parent__id", "translations__name")
#                 .select_related("app_config")
#                 .prefetch_related("translations")
#             )
#             added_categories = []
#             for category in categories:
#                 if category.pk not in added_categories:
#                     node = NavigationNode(
#                         category.name,
#                         category.get_absolute_url(),
#                         "{}-{}".format(category.__class__.__name__, category.pk),
#                         ("{}-{}".format(category.__class__.__name__, category.parent.id) if category.parent else None),
#                     )
#                     nodes.append(node)
#                     added_categories.append(category.pk)
# 
#         return nodes
# 
# 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 aldryn_apphooks_config.app_base import CMSConfigApp
from cms.apphook_pool import apphook_pool
from django.utils.translation import gettext_lazy as _
from djangocms_apphook_setup.base import AutoCMSAppMixin
from .cms_appconfig import BlogConfig
from .cms_menus import BlogCategoryMenu
from .settings import get_setting



@apphook_pool.register
class BlogApp(AutoCMSAppMixin, CMSConfigApp):
    name = _("Blog")
    _urls = [get_setting("URLCONF")]
    app_name = "djangocms_blog"
    app_config = BlogConfig
    _menus = [BlogCategoryMenu]
    auto_setup = {
        "enabled": get_setting("AUTO_SETUP"),
        "home title": get_setting("AUTO_HOME_TITLE"),
        "page title": get_setting("AUTO_BLOG_TITLE"),
        "namespace": get_setting("AUTO_NAMESPACE"),
        "config_fields": {},
        "config_translated_fields": {
            "app_title": get_setting("AUTO_APP_TITLE"),

# Path: djangocms_blog/cms_appconfig.py
# class BlogConfig(TranslatableModel, AppHookConfig):
#     """
#     Adds translatable, per-app-instance fields.
#     """
# 
#     translations = TranslatedFields(
#         app_title=models.CharField(_("application title"), max_length=234),
#         object_name=models.CharField(_("object name"), max_length=234, default=get_setting("DEFAULT_OBJECT_NAME")),
#     )
# 
#     class Meta:
#         verbose_name = _("blog config")
#         verbose_name_plural = _("blog configs")
# 
#     def get_app_title(self):
#         return getattr(self, "app_title", _("untitled"))
# 
#     @property
#     def schemaorg_type(self):
#         """Compatibility shim to fetch data from legacy gplus_type field."""
#         return self.gplus_type
# 
# Path: djangocms_blog/cms_menus.py
# class BlogCategoryMenu(CMSAttachMenu):
#     """
#     Main menu class
# 
#     Handles all types of blog menu
#     """
# 
#     name = _("Blog menu")
#     _config = {}
# 
#     def get_nodes(self, request):
#         """
#         Generates the nodelist
# 
#         :param request:
#         :return: list of nodes
#         """
#         nodes = []
# 
#         language = get_language_from_request(request, check_path=True)
#         current_site = get_current_site(request)
# 
#         page_site = self.instance.node.site
#         if self.instance and page_site != current_site:
#             return []
# 
#         categories_menu = False
#         posts_menu = False
#         config = False
#         if self.instance:
#             if not self._config.get(self.instance.application_namespace, False):
#                 try:
#                     self._config[self.instance.application_namespace] = BlogConfig.objects.get(
#                         namespace=self.instance.application_namespace
#                     )
#                 except BlogConfig.DoesNotExist as e:
#                     logger.exception(e)
#                     return []
#             config = self._config[self.instance.application_namespace]
#             if not getattr(request, "toolbar", False) or not request.toolbar.edit_mode_active:
#                 if self.instance == self.instance.get_draft_object():
#                     return []
#             else:
#                 if self.instance == self.instance.get_public_object():
#                     return []
#         if config and config.menu_structure in (MENU_TYPE_COMPLETE, MENU_TYPE_CATEGORIES):
#             categories_menu = True
#         if config and config.menu_structure in (MENU_TYPE_COMPLETE, MENU_TYPE_POSTS):
#             posts_menu = True
#         if config and config.menu_structure in (MENU_TYPE_NONE,):
#             return nodes
# 
#         used_categories = []
#         if posts_menu:
#             posts = Post.objects
#             if hasattr(self, "instance") and self.instance:
#                 posts = posts.namespace(self.instance.application_namespace).on_site()
#             posts = (
#                 posts.active_translations(language)
#                 .distinct()
#                 .select_related("app_config")
#                 .prefetch_related("translations", "categories")
#             )
#             for post in posts:
#                 post_id = None
#                 parent = None
#                 used_categories.extend(post.categories.values_list("pk", flat=True))
#                 if categories_menu:
#                     category = post.categories.first()
#                     if category:
#                         parent = "{}-{}".format(category.__class__.__name__, category.pk)
#                         post_id = ("{}-{}".format(post.__class__.__name__, post.pk),)
#                 else:
#                     post_id = ("{}-{}".format(post.__class__.__name__, post.pk),)
#                 if post_id:
#                     node = NavigationNode(post.get_title(), post.get_absolute_url(language), post_id, parent)
#                     nodes.append(node)
# 
#         if categories_menu:
#             categories = BlogCategory.objects
#             if config:
#                 categories = categories.namespace(self.instance.application_namespace)
#             if config and not config.menu_empty_categories:
#                 categories = categories.active_translations(language).filter(pk__in=used_categories).distinct()
#             else:
#                 categories = categories.active_translations(language).distinct()
#             categories = (
#                 categories.order_by("parent__id", "translations__name")
#                 .select_related("app_config")
#                 .prefetch_related("translations")
#             )
#             added_categories = []
#             for category in categories:
#                 if category.pk not in added_categories:
#                     node = NavigationNode(
#                         category.name,
#                         category.get_absolute_url(),
#                         "{}-{}".format(category.__class__.__name__, category.pk),
#                         ("{}-{}".format(category.__class__.__name__, category.parent.id) if category.parent else None),
#                     )
#                     nodes.append(node)
#                     added_categories.append(category.pk)
# 
#         return nodes
# 
# 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_apps.py
from aldryn_apphooks_config.app_base import CMSConfigApp
from cms.apphook_pool import apphook_pool
from django.utils.translation import gettext_lazy as _
from djangocms_apphook_setup.base import AutoCMSAppMixin
from .cms_appconfig import BlogConfig
from .cms_menus import BlogCategoryMenu
from .settings import get_setting




@apphook_pool.register
class BlogApp(AutoCMSAppMixin, CMSConfigApp):
    name = _("Blog")
    _urls = [get_setting("URLCONF")]
    app_name = "djangocms_blog"
    app_config = BlogConfig
    _menus = [BlogCategoryMenu]
    auto_setup = {
        "enabled": get_setting("AUTO_SETUP"),
        "home title": get_setting("AUTO_HOME_TITLE"),
        "page title": get_setting("AUTO_BLOG_TITLE"),
        "namespace": get_setting("AUTO_NAMESPACE"),
        "config_fields": {},
        "config_translated_fields": {
            "app_title": get_setting("AUTO_APP_TITLE"),

            "object_name": get_setting("DEFAULT_OBJECT_NAME"),