Changelog¶
All notable changes to this project will be documented in this file.
The format is based on Keep a Changelog, and this project attempts to adhere to Semantic Versioning.
Unreleased¶
Changed¶
The
django_simple_navtemplate tag now acceptstemplate_nameas a keyword argument (e.g.template_name="footer_nav.html"). Positional usage is still supported.
0.15.0¶
Added¶
Navcan now be constructed directly withtemplate_nameanditemskeyword arguments, without needing to subclass it.The
django_simple_navtemplate tag and Jinja2 extension now accept factory functions. A factory receives the current request and returns aNav, making it easy to build request-aware navs (e.g. based on user authentication or permissions).Added
is_anonymous,is_active, andis_superuseras built-in user attribute permission checks, joining the existingis_authenticatedandis_staff.
0.14.0¶
Added¶
Added
append_slashoption toNavItemfor per-item control over trailing slash behavior.NavItemandNavGroupcan now render themselves viarender(request), enabling{{ item }}in templates — similar to how Django forms support{{ form }}. Each item can have its owntemplate_namefor per-item rendering customization.Added
NavItemContext, a dict subclass returned byNav.get_context_data(). It supports both dict-style access ({{ item.title }}) and self-rendering ({{ item }}), so existing templates work unchanged.Default templates
django_simple_nav/navitem.htmlanddjango_simple_nav/navgroup.htmlship with the package for use with the self-rendering feature. These are minimal, semantic HTML witharia-current="page"for active links.Support for Python 3.14.
Support for Django 6.0.
Removed¶
Dropped support for Python 3.9.
Removed
docs,tests, andtypesoptional dependency groups (e.g.pip install django-simple-nav[tests]). These are now internal development dependencies only.
0.13.0¶
Added¶
Support for the
django.templates.backends.jinja2.Jinja2template engine backend.Support for Django 5.2.
Removed¶
Dropped support for Django 5.0.
New Contributors¶
0.12.0¶
Changed¶
Bumped
django-twc-packagetemplate to v2024.29.Switched project and dependency management over to use
uvacross the board (pyproject.toml,Justfilerecipes, GHA workflows).
Removed¶
Dropped support for Python 3.8.
0.11.0¶
Fixed¶
Checking whether a
NavItemorNavGroupis active now takes into account the URL scheme and domain name for both the nav item and request.
0.10.0¶
Added¶
Support for Python 3.13.
Changed¶
Bumped
django-twc-packagetemplate to v2024.23.Removed
westerveltco/setup-ci-actionfrom GitHub Actions workflows.
0.9.0¶
Changed¶
Updated
NavItem.get_activeto allow for using URLs that contain query strings.
0.8.0¶
Changed¶
Updated
NavItem.urlandNavItem.get_urlto allow for using a callable. This allowsNavItem.urlto supportdjango.urls.reverseordjango.urls.reverse_lazyprimarily, but it can be any callable as long as it returns a string.
0.7.0¶
Added¶
NavItemandNavGroupnow both have aget_context_datathat returns the context needed for template rendering.NavItemandNavGroupnow both have aget_urlmethod for returning the URL for the item.NavItemandNavGroupnow both have aget_activemethod for returning whether the item is active or not, meaning it’s the URL currently being requested.NavItemandNavGroupnow both have acheck_permissionsmethod for checking whether the item should be rendered for a given request.NavItemandNavGroupnow support using a callable in the list ofpermissions. This callable should take anHttpRequestand return aboolindicating whether the item should be rendered for a given request.The
Navclass now has aget_templatemethod that returns the template to render. This method takes an optionaltemplate_nameargument, and if not provided is taken from theget_template_namemethod. If overridden, you can return a string as a way to embed a template directly in theNavdefinition.NavItemnow has aget_itemsmethod. This is to aid a future refactor.
Changed¶
Internals of library have been refactored to slightly simplify it, including
Nav,NavGroup,NavItemand thedjango_simple_navtemplatetag.Nav.get_itemsnow returns a list ofNavGrouporNavItem, instead of a list ofRenderedNavItem.Check for the existence of a user attached to the
requestobject passed in todjango_simple_nav.permissions.check_item_permissionshas been moved to allow for an early return if there is no user. There are instances where thedjango.contrib.authapp can be installed, but no user is attached to the request object. This change will allow this function to correctly be used in those instances.Now using v2024.20 of
django-twc-package.NavGroupis now marked as active if the request path matches it’s URL (if set) or and of its items’ URLs.
Removed¶
The
extra_contextattribute ofNavItemandNavGroupnow only renders the contents of the dictionary to the template context. Previously it did that as well as providedextra_contextto the context. If this sounds confusing, that’s because it kinda is. 😅 This basically just means instead of two places to get the extra context (extra_contextand the keys provided within theextra_contextattribute), there is now just one (the keys provided within theextra_contextattribute).RenderedNavItemhas been removed and it’s functionality refactored into bothNavItemandNavGroup. This should not affect the public API of this library, but I thought it should be noted.django_simple_nav.permissionsmodule has been removed and it’s functionality refactored intoNavItem.Dropped support for Django 3.2.
Fixed¶
activeboolean for aNavItemshould now accurately match the request URL, taking into account any potential nesting and a project’sAPPEND_SLASHsetting.The permissions check for
NavGrouphas been fixed to apply to the child items as well. Previously, it only checked the top-level permissions on theNavGroupinstance itself. If the items within theNavGrouphave permissions defined, they will now be checked and filtered out. If the check ends up filtering all of the items out and theNavGrouphas no url set, then it will not be rendered.
0.6.0¶
Added¶
Added two new methods to
Nav:get_itemsandget_template_name. These should allow for further flexibility and customization of rendering theNav.
Changed¶
Now using v2024.16 of
django-twc-package.
Fixed¶
Active nav item matching is now correctly using the
urlproperty onRenderedNavItem.
0.5.1¶
Added¶
Added the requisite
py.typedfile to the package, so that it plays nicely when type-checking in projects usingdjango-simple-nav.
0.5.0¶
Added¶
An number of examples have been added to a new
exampledirectory. These examples are intended to demonstrate various ways how to usedjango-simple-navin a Django project and include basic usage and usage with some popular CSS frameworks.
Changed¶
check_item_permissionnow takes arequestargument instead of auserargument.
Fixed¶
check_item_permissionnow explicitly checks ifdjango.contrib.authis installed before attempting to check if a user has a permission. If it is not, it will returnTrueby default and log a warning.The
requestobject is now passed torender_to_stringwhen rendering the navigation template, so that therequestobject is available in the template context. This allows for nesting thedjango_simple_navtemplate tag within anotherdjango_simple_navtemplate tag, and having therequestobject available in the nested template.
0.4.0¶
Added¶
The
Navclass now has two new methods:get_context_dataandrender. These methods are used to render the navigation to a template. These new methods give greater flexibility for customizing the rendering of the navigation, as they can be overridden when defining a newNav.Nav.get_context_datamethod takes a DjangoHttpRequestobject and returns a dictionary of context data that can be used to render the navigation to a template.Nav.rendermethod takes a DjangoHttpRequestobject and an optional template name and renders the navigation to a template, returning the rendered template as a string.
Removed¶
Nav.render_from_requestmethod has been removed. This was only used within the template tag to render aNavtemplate from anHttpRequestobject. It has been removed in favor of the newNav.get_context_dataandNav.rendermethods.
0.3.0¶
Added¶
NavGroupandNavItemnow has a newextra_contextattribute. This allows for passing additional context to the template when rendering the navigation, either via the extra attribute (item.foo) or theextra_contextattribute itself (item.extra_context.foo).
Changed¶
Now using v2024.13 of
django-twc-package.
Fixed¶
RenderedNavItem.itemsproperty now correctly returns a list ofRenderedNavItemobjects, rather than a list ofNavItemobjects. This fixes a bug where the properties that should be available (e.g.active,url, etc.) were not available when iterating over theRenderedNavItem.itemslist if the item was aNavGroupobject with child items.
0.2.0¶
Added¶
The
django_simple_navtemplate tag can now take an instance of aNavclass, in addition to aNavdotted path string. This should give greater flexibility for rendering aNav, as it can now be overridden on a per-view/template basis.
Changed¶
Now using
django-twc-packagetemplate for repository and package structure.
0.1.0¶
Initial release! 🎉
Added¶
A group of navigation classes –
Nav,NavGroup, andNavItem– that can be used together to build a simple navigation structure.Navis the main container for a navigation structure.NavGroupis a container for a group ofNavItemobjects.NavItemis a single navigation item.
A
django_simple_navtemplate tag that renders aNavobject to a template. The template tag takes a string represented the dotted path to aNavobject and renders it to the template.Navigation item urls can be either a URL string (e.g.
https://example.com/about/or/about/) or a Django URL name (e.g.about-view). When rendering out to the template, the template tag will resolve the URL name to the actual URL.Navigation items also can take a list of permissions to control the visibility of the item. The permissions can be user attributes (e.g.
is_staff,is_superuser, etc.) or a specific permission (e.g.auth.add_user).Navigation items are marked as
activeif the current request path matches the item’s URL. This is can be useful for highlighting the current page in the navigation.A
Navobject’s template can either be set as a class attribute (template_name) or passed in as a keyword argument when rendering the template tag. This allows for easy customization of the navigation structure on a per-template or per-view basis.Initial documentation.
Initial tests.
Initial CI/CD (GitHub Actions).
New Contributors¶
Josh Thomas josh@joshthomas.dev (maintainer)
Jeff Triplett @jefftriplett