Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: removed Nav Container plugin and fixed Navigation Link plugin #192

Merged
merged 39 commits into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
4245adc
Fix: Update locales and add floating options for images
fsbraun Nov 7, 2023
e66e618
Merge branch 'master' of github.com:fsbraun/djangocms-frontend
fsbraun Nov 7, 2023
cbaccdd
Merge branch 'master' of github.com:fsbraun/djangocms-frontend
fsbraun Nov 28, 2023
66e053e
fix: icons not showing in ckeditor
fsbraun Nov 28, 2023
fec0ece
Merge branch 'django-cms:master' into master
fsbraun Nov 28, 2023
49e4acc
Merge branch 'django-cms:master' into master
fsbraun Nov 28, 2023
a9ead97
Add image drag and drop
fsbraun Nov 28, 2023
9ac7126
Merge branch 'master' of github.com:fsbraun/djangocms-frontend
fsbraun Nov 28, 2023
f5f27b6
Update docs
fsbraun Nov 28, 2023
6d5fac4
Add tests
fsbraun Nov 28, 2023
18d60ab
Fix tests for v4
fsbraun Nov 28, 2023
44d5035
Bump version
fsbraun Nov 28, 2023
210cccd
Update changelog
fsbraun Nov 28, 2023
510494e
Merge branch 'django-cms:master' into master
fsbraun Nov 28, 2023
297d436
Merge branch 'django-cms:master' into master
fsbraun Dec 13, 2023
fc20a5a
Merge branch 'django-cms:master' into master
fsbraun Dec 15, 2023
606cc91
fix/remove-unused-css
fsbraun Dec 15, 2023
1af2ef9
Merge branch 'django-cms:master' into master
fsbraun Jan 4, 2024
60f810f
Merge branch 'django-cms:master' into master
fsbraun Jan 8, 2024
05a0939
Merge branch 'django-cms:master' into master
fsbraun Jan 8, 2024
a8e5f2d
Doc typos
fsbraun Jan 8, 2024
c7c8bcf
Merge branch 'django-cms:master' into master
fsbraun Jan 9, 2024
ad90c57
Fix: Missing space in auto column short description
fsbraun Jan 11, 2024
d2a2e78
Merge branch 'master' of github.com:fsbraun/djangocms-frontend
fsbraun Jan 11, 2024
41e58bc
Merge branch 'master' into master
fsbraun Jan 11, 2024
ef87c91
Unlist removed iconsets from the docs
fsbraun Jan 12, 2024
8d63c99
Merge branch 'django-cms:master' into master
fsbraun Jan 12, 2024
a165dcd
Merge branch 'master' into master
fsbraun Jan 13, 2024
c7e34a2
Merge branch 'django-cms:master' into master
fsbraun Feb 14, 2024
aa0aff9
Merge branch 'django-cms:master' into master
fsbraun Feb 16, 2024
1017581
Merge branch 'django-cms:master' into master
fsbraun Feb 28, 2024
eb85690
and the changes
fsbraun Feb 28, 2024
bcc8cb5
Remove superflous "x" from menu template
fsbraun Feb 28, 2024
97d59a9
Fix tests
fsbraun Feb 28, 2024
1e5684c
remove unused code
fsbraun Feb 28, 2024
322b050
Add minimal docs
fsbraun Feb 29, 2024
b8395aa
Fix offcanvas markup
fsbraun Mar 21, 2024
df37898
Merge branch 'master' into fix/nav_container
fsbraun Mar 21, 2024
37fac26
Fix: Container close button covered by CMS toolbar
fsbraun Mar 21, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 33 additions & 13 deletions djangocms_frontend/contrib/navigation/cms_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -36,7 +36,6 @@ class NavigationPlugin(
"NavLinkPlugin",
"PageTreePlugin",
"NavBrandPlugin",
"NavContainerPlugin",
]

fieldsets = [
Expand Down Expand Up @@ -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,
Expand All @@ -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 = [
Expand All @@ -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",
Expand All @@ -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",
Expand Down
13 changes: 0 additions & 13 deletions djangocms_frontend/contrib/navigation/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
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")

Check warning on line 9 in djangocms_frontend/contrib/navigation/frameworks/bootstrap5.py

View check run for this annotation

Codecov / codecov/patch

djangocms_frontend/contrib/navigation/frameworks/bootstrap5.py#L9

Added line #L9 was not covered by tests
return super().render(context, instance, placeholder)


Expand Down
3 changes: 3 additions & 0 deletions djangocms_frontend/contrib/navigation/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
proxy = True
verbose_name = _("Navigation container")

def get_short_description(self):
return _("(deprecated)")

Check warning on line 27 in djangocms_frontend/contrib/navigation/models.py

View check run for this annotation

Codecov / codecov/patch

djangocms_frontend/contrib/navigation/models.py#L27

Added line #L27 was not covered by tests


class NavLink(Link):
class Meta:
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% 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 %}
{% 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 %}
{% for plugin in instance.child_plugin_instances %}
{% with parentloop=forloop parent=instance %}{% render_plugin plugin %}{% endwith %}
{% empty %}{{ instance.simple_content }}{% endfor %}
{% if link %}</a>{% else %}</{{ instance.tag_type }}>{% endif %}{% endwith %}
{% if link %}</a>{% else %}</span>{% endif %}{% endwith %}
{% endspaceless %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{% 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>
{% else %}<i class="{{ icon_class }} {{ attribute_class }}" aria-hidden="true"></i>{% endif %}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
{% else %}
<div class="{{ item|default:"nav" }}-item {{ drop|default:"dropdown" }}">
{% 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 %}
<a {{ instance.get_attributes }} href="{{ instance.get_link }}"
{% if parent.plugin_type != "NavLinkPlugin" %}data-bs-toggle="dropdown"{% endif %}>{{ instance.name }}</a>
{% 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 %}
<ul class="dropdown-menu">
{% for plugin in instance.child_plugin_instances %}
{% with forloop=parentloop parent=instance drop="dropend" item="dropdown" %}{% render_plugin plugin %}{% endwith %}
Expand All @@ -20,7 +22,9 @@
{% endif %}
{% else %}
{% if parent.plugin_type != "NavigationPlugin" %}<li class="{{ item|default:"nav" }}-item">{% 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 %}
<a {{ instance.get_attributes }} href="{{ instance.get_link }}"{% if instance.target %} target="{{ instance.target }}"{% endif %}>{{ instance.name }}</a>
{% 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 %}
{% if parent.plugin_type != "NavigationPlugin" %}</li>{% endif %}
{% endif %}{# djlint:on #}
{% endspaceless %}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
{% load cms_tags frontend %}{% spaceless %}
<nav{{ instance.get_attributes }}>
{% if instance.navbar_container %}<div class="container">{% endif %}
{% load cms_tags frontend %}
<nav{{ instance.get_attributes }}>
{% if instance.navbar_container %}<div class="container">{% endif %}
{% for plugin in instance.child_plugin_instances %}
{% if plugin.plugin_type == "NavBrandPlugin" %}
{% render_plugin plugin %}
{% endif %}
{% endfor %}
<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">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="nav{{ instance.id|safe }}">
<ul class="navbar-nav">
{% for plugin in instance.child_plugin_instances %}
{% if plugin.plugin_type == "BrandPlugin" %}
{% render_plugin plugin %}
{% endif %}
{% endfor %}
{% for plugin in instance.child_plugin_instances %}
{% if plugin.plugin_type != "BrandPlugin" %}
{% with forloop=parentloop parent=instance %}{% render_plugin plugin %}{% endwith %}
{% endif %}
{% endfor %}
{% for plugin in instance.child_plugin_instances %}
{% if plugin.plugin_type != "NavBrandPlugin" %}
{% with forloop=parentloop parent=instance %}{% render_plugin plugin %}{% endwith %}
{% endif %}
{% endfor %}
</ul>
{% if instance.navbar_container %}</div>{% endif %}
</nav>
{% endspaceless %}
</div>
{% if instance.navbar_container %}</div>{% endif %}
</nav>

Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
{% else %}
<div class="{{ item|default:"nav" }}-item {{ drop|default:"dropdown" }}">
{% endif %}
<a {{ instance.get_attributes }} href="{{ instance.get_link }}"
{% if parent.plugin_type != "NavLinkPlugin" %}data-bs-toggle="dropdown"{% endif %}>{{ instance.name }}</a>
<ul class="dropdown-menu">
<a class="nav-link" href="{{ instance.get_link }}">{{ instance.name }}</a>
<ul>
{% for plugin in instance.child_plugin_instances %}
{% with forloop=parentloop parent=instance drop="dropend" item="dropdown" %}{% render_plugin plugin %}{% endwith %}
{% endfor %}
Expand All @@ -19,18 +18,7 @@
{% endif %}
{% else %}
{% if parent.plugin_type != "NavigationPlugin" %}<li class="{{ item|default:"nav" }}-item">{% endif %}
<a {{ instance.get_attributes }} href="{{ instance.get_link }}"{% if instance.target %} target="{{ instance.target }}"{% endif %}>{{ instance.name }}</a>
<a class="nav-link" href="{{ instance.get_link }}"{% if instance.target %} target="{{ instance.target }}"{% endif %}>{{ instance.name }}</a>
{% if parent.plugin_type != "NavigationPlugin" %}</li>{% endif %}
{% endif %}{# djlint:on #}
{% endspaceless %}
{% addtoblock "css" %}
<style>
.dropdown-menu > li:hover > .dropdown-menu {
display: block;
}
.dropdown-menu .dropdown-menu {
left: calc(100% - 0.3rem);
top: calc(0.3rem - 8px);
}
</style>
{% endaddtoblock %}
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{% load i18n menu_tags cache %}{% spaceless %}
{% for child in children %}
<li class="nav-item {% if child.ancestor %}ancestor{% endif %}{% if child.children %} dropdown{% endif %}">
{% if child.children %}<a class="nav-link dropdown-toggle" role="button" data-bs-toggle="dropdown" href="{{ child.get_absolute_url }}" id="menu-{{ child.id|safe }}">{{ child.get_menu_title }}</a>
<div class="dropdown-menu" aria-labelledby="menu-{{ child.ancestor.id|safe }}">
{% if child.children %}<a href="{{ child.get_absolute_url }}" id="menu-{{ child.id|safe }}">{{ child.get_menu_title }}</a>
<div class="ms-3" aria-labelledby="menu-{{ child.ancestor.id|safe }}">
{% show_menu from_level to_level extra_inactive extra_active "djangocms_frontend/bootstrap5/navigation/offcanvas/menu_dropdown.html" "" "" child %}
</div>
{% else %}
<a class="nav-link{% if child.selected %} active{% endif %}" href="{{ child.get_absolute_url }}"><span>{{ child.get_menu_title }}</span></a>
<a class="{% if child.selected %} active{% endif %}" href="{{ child.get_absolute_url }}"><span>{{ child.get_menu_title }}</span></a>
{% endif %}
</li>
{% endfor %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
{% if child.get_menu_title|first == ' ' %}
<div class="dropdown-divider"></div>
{% endif %}
<a class="dropdown-item" href="{{ child.get_absolute_url }}"><span>{{ child.get_menu_title }}</span></a>
<a href="{{ child.get_absolute_url }}"><span>{{ child.get_menu_title }}</span></a>
{% endfor %}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,16 +1,33 @@
{% load cms_tags frontend %}{% spaceless %}
<nav{{ instance.get_attributes }}>
{% if instance.navbar_container %}<div class="container">{% endif %}
{% for plugin in instance.child_plugin_instances %}
{% if plugin.plugin_type == "BrandPlugin" %}
{% render_plugin plugin %}
{% endif %}
{% endfor %}
{% for plugin in instance.child_plugin_instances %}
{% if plugin.plugin_type != "BrandPlugin" %}
{% with forloop=parentloop parent=instance %}{% render_plugin plugin %}{% endwith %}
{% endif %}
{% endfor %}
{% for plugin in instance.child_plugin_instances %}
{% if plugin.plugin_type == "NavBrandPlugin" %}
{% render_plugin plugin %}
{% endif %}
{% endfor %}
<button class="btn" type="button" data-bs-toggle="offcanvas" data-bs-target="#nav{{ instance.id|safe }}" aria-controls="nav{{ instance.id|safe }}" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
{% if instance.navbar_container %}</div>{% endif %}
</nav>
<div class="offcanvas offcanvas-end" id="nav{{ instance.id|safe }}">
<div class="offcanvas-header">
<button type="button" class="btn-close text-reset" data-bs-dismiss="offcanvas" aria-label="Close"></button>
</div>
<div class="offcanvas-body">
<ul class="navbar-nav justify-content-end flex-grow-1 pe-3">
{% for plugin in instance.child_plugin_instances %}
{% if plugin.plugin_type != "NavBrandPlugin" %}
{% with forloop=parentloop parent=instance %}{% render_plugin plugin %}{% endwith %}
{% endif %}
{% endfor %}
</ul>
</div>
</div>
{% endspaceless %}
<style>
html.cms-toolbar-expanded .offcanvas-header {
margin-top: 3rem;
}
</style>
Loading