feat: add navbar
This commit is contained in:
parent
74423fde39
commit
ab96727082
|
@ -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}
|
|
@ -0,0 +1,3 @@
|
|||
from django.dispatch import Signal
|
||||
|
||||
populate_nav = Signal()
|
|
@ -13,11 +13,20 @@
|
|||
</head>
|
||||
<body>
|
||||
{% block body %}
|
||||
{% block navbar %}
|
||||
{% include "partials/navbar.html" %}
|
||||
{% endblock %}
|
||||
{% block messages %}
|
||||
{% bootstrap_messages %}
|
||||
{% endblock %}
|
||||
{% block content %}
|
||||
{% endblock %}
|
||||
{% endblock %}
|
||||
<script src="{% static 'bootstrap.bundle.min.js' %}"></script>
|
||||
<script>
|
||||
document.querySelectorAll('.navbar-collapse').forEach(e => {
|
||||
e.classList.remove('show');
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -4,10 +4,3 @@
|
|||
{% load i18n %}
|
||||
|
||||
{% 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 %}
|
||||
|
|
|
@ -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>
|
|
@ -73,6 +73,7 @@ TEMPLATES = [
|
|||
"django.template.context_processors.request",
|
||||
"django.contrib.auth.context_processors.auth",
|
||||
"django.contrib.messages.context_processors.messages",
|
||||
"lelcsc.core.context_processors.nav",
|
||||
],
|
||||
},
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue