feat: add navbar

This commit is contained in:
Luca 2024-09-15 23:58:05 +02:00
parent 74423fde39
commit ab96727082
6 changed files with 57 additions and 7 deletions

View File

@ -0,0 +1,12 @@
from .signals import populate_nav
def nav(request):
nav_items = [
item
for _, items in populate_nav.send(sender=request)
if isinstance(items, list)
for item in items
]
return {"nav_items": nav_items}

3
lelcsc/core/signals.py Normal file
View File

@ -0,0 +1,3 @@
from django.dispatch import Signal
populate_nav = Signal()

View File

@ -13,11 +13,20 @@
</head> </head>
<body> <body>
{% block body %} {% block body %}
{% block navbar %}
{% include "partials/navbar.html" %}
{% endblock %}
{% block messages %} {% block messages %}
{% bootstrap_messages %} {% bootstrap_messages %}
{% endblock %} {% endblock %}
{% block content %} {% block content %}
{% endblock %} {% endblock %}
{% endblock %} {% endblock %}
<script src="{% static 'bootstrap.bundle.min.js' %}"></script>
<script>
document.querySelectorAll('.navbar-collapse').forEach(e => {
e.classList.remove('show');
});
</script>
</body> </body>
</html> </html>

View File

@ -4,10 +4,3 @@
{% load i18n %} {% load i18n %}
{% block page_title %}{% translate "Overview" %}{% endblock %} {% block page_title %}{% translate "Overview" %}{% endblock %}
{% block content %}
<form action="{% url 'oidc_logout' %}" method="post">
{% csrf_token %}
{% bootstrap_button button_type="submit" content="Log out" %}
</form>
{% endblock %}

View File

@ -0,0 +1,32 @@
{% load django_bootstrap5 %}
{% load i18n %}
<nav class="navbar navbar-expand-md bg-primary" role="navigation" data-bs-theme="dark">
<div class="container-fluid">
<a class="navbar-brand" href="{% url 'index' %}">lelcsc</a>
<button class="navbar-toggler" data-bs-toggle="collapse" data-bs-target="#navbarContent" aria-controls="navbarContent" aria-expanded="true" aria-label="{% translate "Toggle navigation" %}">
<span class="navbar-toggler-icon"></span>
</button>
<div class="navbar-collapse collapse show" id="navbarContent">
<ul class="navbar-nav me-auto">
{% for item in nav_items %}
<li class="nav-item">
<a class="nav-link{% if item.is_active %} active{% endif %}" href="{{ item.link }}"{% if item.is_active %} aria-current="page"{% endif %}>
{{ item.text }}
</a>
</li>
{% endfor %}
</ul>
{% if request.user.is_authenticated %}
<form action="{% url 'oidc_logout' %}" method="post">
{% csrf_token %}
{% translate "Log out" as logout_button_text %}
{% bootstrap_button button_type="submit" content=logout_button_text %}
</form>
{% else %}
{% translate "Log in" as login_button_text %}
{% url 'oidc_authentication_init' as login_url %}
{% bootstrap_button button_type="link" content=login_button_text href=login_url %}
{% endif %}
</div>
</div>
</nav>

View File

@ -73,6 +73,7 @@ TEMPLATES = [
"django.template.context_processors.request", "django.template.context_processors.request",
"django.contrib.auth.context_processors.auth", "django.contrib.auth.context_processors.auth",
"django.contrib.messages.context_processors.messages", "django.contrib.messages.context_processors.messages",
"lelcsc.core.context_processors.nav",
], ],
}, },
}, },