Simply add context related links to your Django views.
- Python 98.2%
- HTML 1.8%
| project | register contextactions.tests.urls in urlpatterns | |
| src/contextactions | import: filter_by_permissions from .permissions into src/contextactions/utils/__init__.py | |
| LICENSE | add LICENSE | |
| manage.py | add project for testing | |
| pyproject.toml | fix: 'django' version 5.2.15 is outdated (latest: 6.0.6) | |
| README.md | add information on how to use this project to README.md | |
Django Context-Actions
Quickly link to other pages of your django application.
Features
- Simple definition of links to other pages
- Static or dynamic definition of ContextActions
- Filters out links to views that the user is not allowed to access
- Automatically uses the most recent
nextparameter of GET queries
Setup
from django.utils.translation import gettext_lazy as _
from django.views.generic import TemplateView
from contextactions.contextactions import ContextAction
from contextactions.mixins import ContextActionsMixin
class MyView(
ContextActionsMixin,
TemplateView,
):
context_actions = [
ContextAction(
name='my_app:my_view',
label=_('my human readable translated link text'),
),
]
template_name = 'my_template.html'
In your template include the provided context actions template...
{% include 'contextactions/contextactions.html' %}
or implement you own using view.get_context_actions
{% for action in view.get_context_actions %}
<a href="{% if action.url %}{{ action.url }}{% else %}{% url action.name %}{% endif %}">{% if action.label %}{{ action.label }}{% else %}{{ action.url }}{% endif %}</a>
{% endfor %}