Skip to content

Commit 7b97985

Browse files
authored
fix: removed Nav Container plugin and fixed Navigation Link plugin (#192)
1 parent eee6258 commit 7b97985

File tree

37 files changed

+637
-547
lines changed

37 files changed

+637
-547
lines changed

djangocms_frontend/contrib/navigation/cms_plugins.py

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class NavigationPlugin(
2323
CMSUIPlugin,
2424
):
2525
"""
26-
Creates a Navbar
26+
The NavigationPlugin class is a plugin used in Django CMS to create navigation menus or off-canvas menus.
2727
"""
2828

2929
name = _("Navigation")
@@ -36,7 +36,6 @@ class NavigationPlugin(
3636
"NavLinkPlugin",
3737
"PageTreePlugin",
3838
"NavBrandPlugin",
39-
"NavContainerPlugin",
4039
]
4140

4241
fieldsets = [
@@ -71,13 +70,18 @@ class PageTreePlugin(
7170
AttributesMixin,
7271
CMSUIPlugin,
7372
):
73+
"""
74+
75+
The PageTreePlugin class is a plugin for Django CMS that allows users to display a hierarchical
76+
tree-like structure of pages on the frontend.
77+
"""
7478
name = _("Page tree")
7579
module = _("Frontend")
7680
model = models.PageTree
7781
form = forms.PageTreeForm
7882
change_form_template = "djangocms_frontend/admin/page_tree.html"
7983
allow_children = False
80-
parent_classes = ["NavigationPlugin", "NavContainerPlugin"]
84+
parent_classes = ["NavigationPlugin",]
8185
fieldsets = [
8286
(
8387
None,
@@ -102,13 +106,18 @@ class NavBrandPlugin(
102106
LinkPluginMixin,
103107
CMSUIPlugin,
104108
):
109+
"""
110+
The `NavBrandPlugin` class is a plugin used in Django CMS to create a navigation brand element.
111+
This plugin allows the user to define a brand logo or text that will be displayed in the
112+
navigation header. Content is added through child plugins.
113+
"""
105114
name = _("Brand")
106115
module = _("Frontend")
107116
model = models.NavBrand
108117
form = forms.NavBrandForm
109118
change_form_template = "djangocms_frontend/admin/brand.html"
110119
allow_children = True
111-
parent_classes = ["NavigationPlugin", "NavContainerPlugin"]
120+
parent_classes = ["NavigationPlugin",]
112121
link_fieldset_position = -1
113122

114123
fieldsets = [
@@ -130,13 +139,15 @@ class NavContainerPlugin(
130139
AttributesMixin,
131140
CMSUIPlugin,
132141
):
142+
"""
143+
The `NavContainerPlugin` class is a deprecated plugin without functionality. It will be removed.
144+
"""
133145
name = _("Navigation container")
134146
module = _("Frontend")
135147
model = models.NavContainer
136-
form = forms.NavContainerForm
137-
change_form_template = "djangocms_frontend/admin/nav_container.html"
148+
change_form_template = "djangocms_frontend/admin/deprecated.html"
138149
allow_children = True
139-
parent_classes = ["NavigationPlugin"]
150+
parent_classes = [""] # No parent classes
140151
child_classes = [
141152
"NavLinkPlugin",
142153
"PageTreePlugin",
@@ -150,24 +161,33 @@ class NavContainerPlugin(
150161
),
151162
]
152163

153-
def get_render_template(self, context, instance, placeholder):
154-
return get_template_path(
155-
"navigation", context.get("nav_template", default_template), "nav_container"
156-
)
157-
158164

159165
@plugin_pool.register_plugin
160166
class NavLinkPlugin(
161167
mixin_factory("NavLink"),
162168
LinkPlugin,
163169
):
170+
"""
171+
A plugin that allows creating navigation links for the frontend.
172+
173+
Attributes:
174+
-----------
175+
- `name` (str): The name of the plugin, displayed in the plugin list when editing a page.
176+
- `module` (str): The module where the plugin belongs, displayed in the plugin list when editing a page.
177+
- `model` (Model): The Django model used to store the plugin's data.
178+
- `form` (Form): The form used to render the plugin's settings in the admin interface.
179+
- `change_form_template` (str): The path to the template used to render the plugin's change form in the admin interface.
180+
- `allow_children` (bool): Whether the plugin allows having child plugins.
181+
- `parent_classes` (list): List of parent plugin classes that this plugin can be nested within.
182+
- `child_classes` (list): List of child plugin classes that can be nested within this plugin.
183+
"""
164184
name = _("Navigation link")
165185
module = _("Frontend")
166186
model = models.NavLink
167187
form = forms.NavLinkForm
168188
change_form_template = "djangocms_frontend/admin/navlink.html"
169189
allow_children = True
170-
parent_classes = ["NavigationPlugin", "NavContainerPlugin", "NavLinkPlugin"]
190+
parent_classes = ["NavigationPlugin", "NavLinkPlugin"]
171191
child_classes = [
172192
"NavLinkPlugin",
173193
"GridContainerPlugin",

djangocms_frontend/contrib/navigation/forms.py

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -108,18 +108,5 @@ class Meta:
108108
attributes = AttributesFormField()
109109

110110

111-
class NavContainerForm(mixin_factory("NavContainer"), EntangledModelForm):
112-
class Meta:
113-
model = FrontendUIItem
114-
entangled_fields = {
115-
"config": [
116-
"attributes",
117-
]
118-
}
119-
untangled_fields = ()
120-
121-
attributes = AttributesFormField()
122-
123-
124111
class NavLinkForm(mixin_factory("NavLink"), LinkForm):
125112
link_is_optional = True

djangocms_frontend/contrib/navigation/frameworks/bootstrap5.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ def render(self, context, instance, placeholder):
55
f"navbar-{instance.config.get('navbar_design', '')}",
66
f"navbar-expand-{instance.config.get('navbar_breakpoint', '')}",
77
)
8+
if instance.config.get("navbar_design", "") == "dark":
9+
instance.add_classes("bg-dark")
810
return super().render(context, instance, placeholder)
911

1012

djangocms_frontend/contrib/navigation/models.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ class Meta:
2323
proxy = True
2424
verbose_name = _("Navigation container")
2525

26+
def get_short_description(self):
27+
return _("(deprecated)")
28+
2629

2730
class NavLink(Link):
2831
class Meta:

djangocms_frontend/contrib/navigation/templates/djangocms_frontend/admin/nav_container.html

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
{% load cms_tags sekizai_tags %}{% spaceless %}{% with link=instance.get_link %}{% if link %}<a {{ instance.get_attributes }} href="{{ link }}"{% if instance.target %} target="{{ instance.target }}"{% endif %}>{% else %} <{{ instance.tag_type }}{{ instance.get_attributes }}>{% endif %}
1+
{% load cms_tags sekizai_tags %}{% spaceless %}{% with link=instance.get_link %}{% if link %}<a {{ instance.get_attributes }} href="{{ link }}"{% if instance.target %} target="{{ instance.target }}"{% endif %}>{% else %} <span {{ instance.get_attributes }}>{% endif %}
22
{% for plugin in instance.child_plugin_instances %}
33
{% with parentloop=forloop parent=instance %}{% render_plugin plugin %}{% endwith %}
44
{% empty %}{{ instance.simple_content }}{% endfor %}
5-
{% if link %}</a>{% else %}</{{ instance.tag_type }}>{% endif %}{% endwith %}
5+
{% if link %}</a>{% else %}</span>{% endif %}{% endwith %}
66
{% endspaceless %}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
{% if "iconClass" in icon_class %}{% load icon_tags %}{% add_css_for_icon icon_class %}<i class="{{ icon_class.iconClass }} {{ attribute_class }}">{{ icon_class.iconText }}</i>
2+
{% else %}<i class="{{ icon_class }} {{ attribute_class }}" aria-hidden="true"></i>{% endif %}

djangocms_frontend/contrib/navigation/templates/djangocms_frontend/bootstrap5/navigation/default/link.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66
{% else %}
77
<div class="{{ item|default:"nav" }}-item {{ drop|default:"dropdown" }}">
88
{% endif %}
9+
{% 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 %}
910
<a {{ instance.get_attributes }} href="{{ instance.get_link }}"
1011
{% if parent.plugin_type != "NavLinkPlugin" %}data-bs-toggle="dropdown"{% endif %}>{{ instance.name }}</a>
12+
{% 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 %}
1113
<ul class="dropdown-menu">
1214
{% for plugin in instance.child_plugin_instances %}
1315
{% with forloop=parentloop parent=instance drop="dropend" item="dropdown" %}{% render_plugin plugin %}{% endwith %}
@@ -20,7 +22,9 @@
2022
{% endif %}
2123
{% else %}
2224
{% if parent.plugin_type != "NavigationPlugin" %}<li class="{{ item|default:"nav" }}-item">{% endif %}
25+
{% 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 %}
2326
<a {{ instance.get_attributes }} href="{{ instance.get_link }}"{% if instance.target %} target="{{ instance.target }}"{% endif %}>{{ instance.name }}</a>
27+
{% 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 %}
2428
{% if parent.plugin_type != "NavigationPlugin" %}</li>{% endif %}
2529
{% endif %}{# djlint:on #}
2630
{% endspaceless %}

djangocms_frontend/contrib/navigation/templates/djangocms_frontend/bootstrap5/navigation/default/nav_container.html

Lines changed: 0 additions & 12 deletions
This file was deleted.
Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
1-
{% load cms_tags frontend %}{% spaceless %}
2-
<nav{{ instance.get_attributes }}>
3-
{% if instance.navbar_container %}<div class="container">{% endif %}
1+
{% load cms_tags frontend %}
2+
<nav{{ instance.get_attributes }}>
3+
{% if instance.navbar_container %}<div class="container">{% endif %}
4+
{% for plugin in instance.child_plugin_instances %}
5+
{% if plugin.plugin_type == "NavBrandPlugin" %}
6+
{% render_plugin plugin %}
7+
{% endif %}
8+
{% endfor %}
9+
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#nav{{ instance.id|safe }}" aria-controls="nav{{ instance.id|safe }}" aria-expanded="false" aria-label="Toggle navigation">
10+
<span class="navbar-toggler-icon"></span>
11+
</button>
12+
<div class="collapse navbar-collapse" id="nav{{ instance.id|safe }}">
413
<ul class="navbar-nav">
5-
{% for plugin in instance.child_plugin_instances %}
6-
{% if plugin.plugin_type == "BrandPlugin" %}
7-
{% render_plugin plugin %}
8-
{% endif %}
9-
{% endfor %}
10-
{% for plugin in instance.child_plugin_instances %}
11-
{% if plugin.plugin_type != "BrandPlugin" %}
12-
{% with forloop=parentloop parent=instance %}{% render_plugin plugin %}{% endwith %}
13-
{% endif %}
14-
{% endfor %}
14+
{% for plugin in instance.child_plugin_instances %}
15+
{% if plugin.plugin_type != "NavBrandPlugin" %}
16+
{% with forloop=parentloop parent=instance %}{% render_plugin plugin %}{% endwith %}
17+
{% endif %}
18+
{% endfor %}
1519
</ul>
16-
{% if instance.navbar_container %}</div>{% endif %}
17-
</nav>
18-
{% endspaceless %}
20+
</div>
21+
{% if instance.navbar_container %}</div>{% endif %}
22+
</nav>
23+

0 commit comments

Comments
 (0)