Skip to content

Commit 44ed6eb

Browse files
authored
Merge pull request #85 from srobo/feature/links
Add support for custom links in navbar
2 parents 9f6a22d + 6837c5f commit 44ed6eb

File tree

10 files changed

+72
-4
lines changed

10 files changed

+72
-4
lines changed

helpdesk/core/__init__.py

Whitespace-only changes.

helpdesk/core/admin.py

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from django.contrib import admin
2+
3+
from .models import NavigationLink
4+
5+
6+
class NavigationLinkAdmin(admin.ModelAdmin):
7+
list_display = ["name", "url"]
8+
9+
10+
admin.site.register(NavigationLink, NavigationLinkAdmin)
+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Generated by Django 4.2.11 on 2025-02-18 20:12
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
initial = True
8+
9+
dependencies = []
10+
11+
operations = [
12+
migrations.CreateModel(
13+
name="NavigationLink",
14+
fields=[
15+
("id", models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")),
16+
("name", models.CharField(max_length=64, unique=True)),
17+
("url", models.URLField(unique=True)),
18+
],
19+
options={
20+
"ordering": ["name"],
21+
},
22+
),
23+
]

helpdesk/core/migrations/__init__.py

Whitespace-only changes.

helpdesk/core/models.py

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from django.db import models
2+
3+
4+
class NavigationLink(models.Model):
5+
name = models.CharField(max_length=64, unique=True)
6+
url = models.URLField(unique=True)
7+
8+
class Meta:
9+
ordering = ["name"]
10+
11+
def __str__(self) -> str:
12+
return self.name

helpdesk/core/templatetags/__init__.py

Whitespace-only changes.
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from django.template import Library, RequestContext
2+
3+
from core.models import NavigationLink
4+
5+
register = Library()
6+
7+
8+
@register.inclusion_tag("tags/navigation.html", takes_context=True)
9+
def navigation(context: RequestContext) -> dict:
10+
return {**context.flatten(), "links": NavigationLink.objects.all()}

helpdesk/helpdesk/settings.py

+1
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@
104104
"helpdesk",
105105
"teams",
106106
"tickets",
107+
"core",
107108
"crispy_forms",
108109
"crispy_bulma",
109110
"django_filters",

helpdesk/templates/layouts/base_app.html

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
{% extends "layouts/base.html" %}
2+
{% load navigation %}
23

34
{% block body %}
4-
{% include "inc/nav/nav.html" %}
5+
{% navigation %}
56
<main>
67
<div class="container is-fluid" style="margin-top: 1em;">
78
<div class="columns is-vcentered mb-3">

helpdesk/templates/inc/nav/nav.html helpdesk/templates/tags/navigation.html

+14-3
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,20 @@
3434
<a class="navbar-item" href="{% url 'tickets:ticket_create' %}">
3535
New Ticket
3636
</a>
37-
<a class="navbar-item" target="_blank" href="https://studentrobotics.org/runbook/competition/team-support/">
38-
Docs
39-
</a>
37+
{% endif %}
38+
39+
{% if links %}
40+
<div class="navbar-item has-dropdown is-hoverable">
41+
<a class="navbar-link">
42+
Links
43+
</a>
44+
45+
<div class="navbar-dropdown">
46+
{% for link in links %}
47+
<a class="navbar-item" href="{{ link.url }}">{{ link.name }}</a>
48+
{% endfor %}
49+
</div>
50+
</div>
4051
{% endif %}
4152

4253
{% if user.is_authenticated %}

0 commit comments

Comments
 (0)