From 7b979855b70bf40f8a15dc4fc4d3c2a7b29ba8ca Mon Sep 17 00:00:00 2001 From: Fabian Braun Date: Thu, 21 Mar 2024 08:42:01 +0100 Subject: [PATCH] fix: removed Nav Container plugin and fixed Navigation Link plugin (#192) --- .../contrib/navigation/cms_plugins.py | 46 ++-- .../contrib/navigation/forms.py | 13 -- .../navigation/frameworks/bootstrap5.py | 2 + .../contrib/navigation/models.py | 3 + .../admin/nav_container.html | 3 - .../bootstrap5/navigation/default/brand.html | 4 +- .../bootstrap5/navigation/default/icon.html | 2 + .../bootstrap5/navigation/default/link.html | 4 + .../navigation/default/nav_container.html | 12 - .../navigation/default/navigation.html | 37 +-- .../bootstrap5/navigation/offcanvas/link.html | 18 +- .../bootstrap5/navigation/offcanvas/menu.html | 6 +- .../navigation/offcanvas/menu_dropdown.html | 2 +- .../navigation/offcanvas/nav_container.html | 17 -- .../navigation/offcanvas/navigation.html | 37 ++- .../locale/ar/LC_MESSAGES/django.po | 76 ++++--- .../locale/de/LC_MESSAGES/django.po | 98 ++++---- .../locale/en/LC_MESSAGES/django.po | 76 ++++--- .../locale/es/LC_MESSAGES/django.po | 94 ++++---- .../locale/fr/LC_MESSAGES/django.po | 213 ++++++++++-------- .../locale/nl/LC_MESSAGES/django.po | 162 +++++++------ .../locale/sq/LC_MESSAGES/django.po | 94 ++++---- .../static/djangocms_frontend/css/base.css | 2 +- .../djangocms_frontend/css/button_group.css | 2 +- .../templates/bootstrap5/menu.html | 4 +- .../djangocms_frontend/admin/deprecated.html | 12 + docs/source/components.rst | 17 ++ private/sass/base.scss | 10 +- private/sass/button_group.scss | 10 +- private/sass/components/_grid-layout.scss | 28 +-- private/sass/components/_icon-picker.scss | 22 +- private/sass/components/_icons.scss | 2 +- .../sass/components/_preview-generator.scss | 12 +- private/sass/components/_tabs.scss | 8 +- private/sass/components/_title.scss | 2 +- private/sass/components/_tooltip.scss | 4 +- tests/navigation/test_plugins.py | 30 +-- 37 files changed, 637 insertions(+), 547 deletions(-) delete mode 100644 djangocms_frontend/contrib/navigation/templates/djangocms_frontend/admin/nav_container.html create mode 100644 djangocms_frontend/contrib/navigation/templates/djangocms_frontend/bootstrap5/navigation/default/icon.html delete mode 100644 djangocms_frontend/contrib/navigation/templates/djangocms_frontend/bootstrap5/navigation/default/nav_container.html delete mode 100644 djangocms_frontend/contrib/navigation/templates/djangocms_frontend/bootstrap5/navigation/offcanvas/nav_container.html create mode 100644 djangocms_frontend/templates/djangocms_frontend/admin/deprecated.html diff --git a/djangocms_frontend/contrib/navigation/cms_plugins.py b/djangocms_frontend/contrib/navigation/cms_plugins.py index 897a9fd2..9deef2a8 100644 --- a/djangocms_frontend/contrib/navigation/cms_plugins.py +++ b/djangocms_frontend/contrib/navigation/cms_plugins.py @@ -23,7 +23,7 @@ class NavigationPlugin( CMSUIPlugin, ): """ - Creates a Navbar + The NavigationPlugin class is a plugin used in Django CMS to create navigation menus or off-canvas menus. """ name = _("Navigation") @@ -36,7 +36,6 @@ class NavigationPlugin( "NavLinkPlugin", "PageTreePlugin", "NavBrandPlugin", - "NavContainerPlugin", ] fieldsets = [ @@ -71,13 +70,18 @@ class PageTreePlugin( AttributesMixin, CMSUIPlugin, ): + """ + + The PageTreePlugin class is a plugin for Django CMS that allows users to display a hierarchical + tree-like structure of pages on the frontend. + """ name = _("Page tree") module = _("Frontend") model = models.PageTree form = forms.PageTreeForm change_form_template = "djangocms_frontend/admin/page_tree.html" allow_children = False - parent_classes = ["NavigationPlugin", "NavContainerPlugin"] + parent_classes = ["NavigationPlugin",] fieldsets = [ ( None, @@ -102,13 +106,18 @@ class NavBrandPlugin( LinkPluginMixin, CMSUIPlugin, ): + """ + The `NavBrandPlugin` class is a plugin used in Django CMS to create a navigation brand element. + This plugin allows the user to define a brand logo or text that will be displayed in the + navigation header. Content is added through child plugins. + """ name = _("Brand") module = _("Frontend") model = models.NavBrand form = forms.NavBrandForm change_form_template = "djangocms_frontend/admin/brand.html" allow_children = True - parent_classes = ["NavigationPlugin", "NavContainerPlugin"] + parent_classes = ["NavigationPlugin",] link_fieldset_position = -1 fieldsets = [ @@ -130,13 +139,15 @@ class NavContainerPlugin( AttributesMixin, CMSUIPlugin, ): + """ + The `NavContainerPlugin` class is a deprecated plugin without functionality. It will be removed. + """ name = _("Navigation container") module = _("Frontend") model = models.NavContainer - form = forms.NavContainerForm - change_form_template = "djangocms_frontend/admin/nav_container.html" + change_form_template = "djangocms_frontend/admin/deprecated.html" allow_children = True - parent_classes = ["NavigationPlugin"] + parent_classes = [""] # No parent classes child_classes = [ "NavLinkPlugin", "PageTreePlugin", @@ -150,24 +161,33 @@ class NavContainerPlugin( ), ] - def get_render_template(self, context, instance, placeholder): - return get_template_path( - "navigation", context.get("nav_template", default_template), "nav_container" - ) - @plugin_pool.register_plugin class NavLinkPlugin( mixin_factory("NavLink"), LinkPlugin, ): + """ + A plugin that allows creating navigation links for the frontend. + + Attributes: + ----------- + - `name` (str): The name of the plugin, displayed in the plugin list when editing a page. + - `module` (str): The module where the plugin belongs, displayed in the plugin list when editing a page. + - `model` (Model): The Django model used to store the plugin's data. + - `form` (Form): The form used to render the plugin's settings in the admin interface. + - `change_form_template` (str): The path to the template used to render the plugin's change form in the admin interface. + - `allow_children` (bool): Whether the plugin allows having child plugins. + - `parent_classes` (list): List of parent plugin classes that this plugin can be nested within. + - `child_classes` (list): List of child plugin classes that can be nested within this plugin. + """ name = _("Navigation link") module = _("Frontend") model = models.NavLink form = forms.NavLinkForm change_form_template = "djangocms_frontend/admin/navlink.html" allow_children = True - parent_classes = ["NavigationPlugin", "NavContainerPlugin", "NavLinkPlugin"] + parent_classes = ["NavigationPlugin", "NavLinkPlugin"] child_classes = [ "NavLinkPlugin", "GridContainerPlugin", diff --git a/djangocms_frontend/contrib/navigation/forms.py b/djangocms_frontend/contrib/navigation/forms.py index ee3a5f93..2e6ed8bd 100644 --- a/djangocms_frontend/contrib/navigation/forms.py +++ b/djangocms_frontend/contrib/navigation/forms.py @@ -108,18 +108,5 @@ class Meta: attributes = AttributesFormField() -class NavContainerForm(mixin_factory("NavContainer"), EntangledModelForm): - class Meta: - model = FrontendUIItem - entangled_fields = { - "config": [ - "attributes", - ] - } - untangled_fields = () - - attributes = AttributesFormField() - - class NavLinkForm(mixin_factory("NavLink"), LinkForm): link_is_optional = True diff --git a/djangocms_frontend/contrib/navigation/frameworks/bootstrap5.py b/djangocms_frontend/contrib/navigation/frameworks/bootstrap5.py index 5e9e4b78..5698683f 100644 --- a/djangocms_frontend/contrib/navigation/frameworks/bootstrap5.py +++ b/djangocms_frontend/contrib/navigation/frameworks/bootstrap5.py @@ -5,6 +5,8 @@ def render(self, context, instance, placeholder): f"navbar-{instance.config.get('navbar_design', '')}", f"navbar-expand-{instance.config.get('navbar_breakpoint', '')}", ) + if instance.config.get("navbar_design", "") == "dark": + instance.add_classes("bg-dark") return super().render(context, instance, placeholder) diff --git a/djangocms_frontend/contrib/navigation/models.py b/djangocms_frontend/contrib/navigation/models.py index ef583348..90580e6d 100644 --- a/djangocms_frontend/contrib/navigation/models.py +++ b/djangocms_frontend/contrib/navigation/models.py @@ -23,6 +23,9 @@ class Meta: proxy = True verbose_name = _("Navigation container") + def get_short_description(self): + return _("(deprecated)") + class NavLink(Link): class Meta: diff --git a/djangocms_frontend/contrib/navigation/templates/djangocms_frontend/admin/nav_container.html b/djangocms_frontend/contrib/navigation/templates/djangocms_frontend/admin/nav_container.html deleted file mode 100644 index 9ccbe992..00000000 --- a/djangocms_frontend/contrib/navigation/templates/djangocms_frontend/admin/nav_container.html +++ /dev/null @@ -1,3 +0,0 @@ -{% extends "djangocms_frontend/admin/base.html" %} - -{% block custom_class %}djangocms-frontend-nav-container{% endblock %} diff --git a/djangocms_frontend/contrib/navigation/templates/djangocms_frontend/bootstrap5/navigation/default/brand.html b/djangocms_frontend/contrib/navigation/templates/djangocms_frontend/bootstrap5/navigation/default/brand.html index 1cd8da16..24b13134 100644 --- a/djangocms_frontend/contrib/navigation/templates/djangocms_frontend/bootstrap5/navigation/default/brand.html +++ b/djangocms_frontend/contrib/navigation/templates/djangocms_frontend/bootstrap5/navigation/default/brand.html @@ -1,6 +1,6 @@ -{% load cms_tags sekizai_tags %}{% spaceless %}{% with link=instance.get_link %}{% if link %}{% else %} <{{ instance.tag_type }}{{ instance.get_attributes }}>{% endif %} +{% load cms_tags sekizai_tags %}{% spaceless %}{% with link=instance.get_link %}{% if link %}{% else %} {% endif %} {% for plugin in instance.child_plugin_instances %} {% with parentloop=forloop parent=instance %}{% render_plugin plugin %}{% endwith %} {% empty %}{{ instance.simple_content }}{% endfor %} -{% if link %}{% else %}{% endif %}{% endwith %} +{% if link %}{% else %}{% endif %}{% endwith %} {% endspaceless %} diff --git a/djangocms_frontend/contrib/navigation/templates/djangocms_frontend/bootstrap5/navigation/default/icon.html b/djangocms_frontend/contrib/navigation/templates/djangocms_frontend/bootstrap5/navigation/default/icon.html new file mode 100644 index 00000000..10db3950 --- /dev/null +++ b/djangocms_frontend/contrib/navigation/templates/djangocms_frontend/bootstrap5/navigation/default/icon.html @@ -0,0 +1,2 @@ +{% if "iconClass" in icon_class %}{% load icon_tags %}{% add_css_for_icon icon_class %}{{ icon_class.iconText }} +{% else %}{% endif %} diff --git a/djangocms_frontend/contrib/navigation/templates/djangocms_frontend/bootstrap5/navigation/default/link.html b/djangocms_frontend/contrib/navigation/templates/djangocms_frontend/bootstrap5/navigation/default/link.html index b23ff0a4..6aea9f78 100644 --- a/djangocms_frontend/contrib/navigation/templates/djangocms_frontend/bootstrap5/navigation/default/link.html +++ b/djangocms_frontend/contrib/navigation/templates/djangocms_frontend/bootstrap5/navigation/default/link.html @@ -6,8 +6,10 @@ {% else %}
{% endif %} + {% if instance.icon_left %}{% include "djangocms_frontend/bootstrap5/navigation/default/icon.html" with icon_class=instance.icon_left attribute_class="pe-0 nav-link" %}{% endif %} {{ instance.name }} + {% if instance.icon_right %}{% include "djangocms_frontend/bootstrap5/navigation/default/icon.html" with icon_class=instance.icon_right attribute_class="ps-0 nav-link" %}{% endif %}