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.
- Bumped
django-twc-package
template to v2024.29. - Switched project and dependency management over to use
uv
across the board (pyproject.toml
,Justfile
recipes, GHA workflows).
- Dropped support for Python 3.8.
- Checking whether a
NavItem
orNavGroup
is active now takes into account the URL scheme and domain name for both the nav item and request.
- Support for Python 3.13.
- Bumped
django-twc-package
template to v2024.23. - Removed
westerveltco/setup-ci-action
from GitHub Actions workflows.
- Updated
NavItem.get_active
to allow for using URLs that contain query strings.
- Updated
NavItem.url
andNavItem.get_url
to allow for using a callable. This allowsNavItem.url
to supportdjango.urls.reverse
ordjango.urls.reverse_lazy
primarily, but it can be any callable as long as it returns a string.
NavItem
andNavGroup
now both have aget_context_data
that returns the context needed for template rendering.NavItem
andNavGroup
now both have aget_url
method for returning the URL for the item.NavItem
andNavGroup
now both have aget_active
method for returning whether the item is active or not, meaning it's the URL currently being requested.NavItem
andNavGroup
now both have acheck_permissions
method for checking whether the item should be rendered for a given request.NavItem
andNavGroup
now support using a callable in the list ofpermissions
. This callable should take anHttpRequest
and return abool
indicating whether the item should be rendered for a given request.- The
Nav
class now has aget_template
method that returns the template to render. This method takes an optionaltemplate_name
argument, and if not provided is taken from theget_template_name
method. If overridden, you can return a string as a way to embed a template directly in theNav
definition. NavItem
now has aget_items
method. This is to aid a future refactor.
- Internals of library have been refactored to slightly simplify it, including
Nav
,NavGroup
,NavItem
and thedjango_simple_nav
templatetag. Nav.get_items
now returns a list ofNavGroup
orNavItem
, instead of a list ofRenderedNavItem
.- Check for the existence of a user attached to the
request
object passed in todjango_simple_nav.permissions.check_item_permissions
has been moved to allow for an early return if there is no user. There are instances where thedjango.contrib.auth
app 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
. NavGroup
is now marked as active if the request path matches it's URL (if set) or and of its items' URLs.
- The
extra_context
attribute ofNavItem
andNavGroup
now only renders the contents of the dictionary to the template context. Previously it did that as well as providedextra_context
to 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_context
and the keys provided within theextra_context
attribute), there is now just one (the keys provided within theextra_context
attribute). RenderedNavItem
has been removed and it's functionality refactored into bothNavItem
andNavGroup
. This should not affect the public API of this library, but I thought it should be noted.django_simple_nav.permissions
module has been removed and it's functionality refactored intoNavItem
.- Dropped support for Django 3.2.
active
boolean for aNavItem
should now accurately match the request URL, taking into account any potential nesting and a project'sAPPEND_SLASH
setting.- The permissions check for
NavGroup
has been fixed to apply to the child items as well. Previously, it only checked the top-level permissions on theNavGroup
instance itself. If the items within theNavGroup
have permissions defined, they will now be checked and filtered out. If the check ends up filtering all of the items out and theNavGroup
has no url set, then it will not be rendered.
- Added two new methods to
Nav
:get_items
andget_template_name
. These should allow for further flexibility and customization of rendering theNav
.
- Now using v2024.16 of
django-twc-package
.
- Active nav item matching is now correctly using the
url
property onRenderedNavItem
.
- Added the requisite
py.typed
file to the package, so that it plays nicely when type-checking in projects usingdjango-simple-nav
.
- An number of examples have been added to a new
example
directory. These examples are intended to demonstrate various ways how to usedjango-simple-nav
in a Django project and include basic usage and usage with some popular CSS frameworks.
check_item_permission
now takes arequest
argument instead of auser
argument.
check_item_permission
now explicitly checks ifdjango.contrib.auth
is installed before attempting to check if a user has a permission. If it is not, it will returnTrue
by default and log a warning.- The
request
object is now passed torender_to_string
when rendering the navigation template, so that therequest
object is available in the template context. This allows for nesting thedjango_simple_nav
template tag within anotherdjango_simple_nav
template tag, and having therequest
object available in the nested template.
- The
Nav
class now has two new methods:get_context_data
andrender
. 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_data
method takes a DjangoHttpRequest
object and returns a dictionary of context data that can be used to render the navigation to a template.Nav.render
method takes a DjangoHttpRequest
object and an optional template name and renders the navigation to a template, returning the rendered template as a string.
Nav.render_from_request
method has been removed. This was only used within the template tag to render aNav
template from anHttpRequest
object. It has been removed in favor of the newNav.get_context_data
andNav.render
methods.
NavGroup
andNavItem
now has a newextra_context
attribute. This allows for passing additional context to the template when rendering the navigation, either via the extra attribute (item.foo
) or theextra_context
attribute itself (item.extra_context.foo
).
- Now using v2024.13 of
django-twc-package
.
RenderedNavItem.items
property now correctly returns a list ofRenderedNavItem
objects, rather than a list ofNavItem
objects. This fixes a bug where the properties that should be available (e.g.active
,url
, etc.) were not available when iterating over theRenderedNavItem.items
list if the item was aNavGroup
object with child items.
- The
django_simple_nav
template tag can now take an instance of aNav
class, in addition to aNav
dotted path string. This should give greater flexibility for rendering aNav
, as it can now be overridden on a per-view/template basis.
- Now using
django-twc-package
template for repository and package structure.
Initial release! 🎉
- A group of navigation classes --
Nav
,NavGroup
, andNavItem
-- that can be used together to build a simple navigation structure.Nav
is the main container for a navigation structure.NavGroup
is a container for a group ofNavItem
objects.NavItem
is a single navigation item.
- A
django_simple_nav
template tag that renders aNav
object to a template. The template tag takes a string represented the dotted path to aNav
object 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
active
if the current request path matches the item's URL. This is can be useful for highlighting the current page in the navigation. - A
Nav
object'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).
- Josh Thomas [email protected] (maintainer)
- Jeff Triplett @jefftriplett