Skip to content

Commit

Permalink
Merge pull request #145 from ImperialCollegeLondon/navbar_ui
Browse files Browse the repository at this point in the history
adding user info and help page setup
  • Loading branch information
cc-a authored Oct 10, 2024
2 parents 33b8433 + e47dde1 commit 61373b8
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 0 deletions.
5 changes: 5 additions & 0 deletions main/templates/main/help.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{% extends "main/base.html" %}
{% block content %}
<h1>Help</h1>
<p>This is the help page.</p>
{% endblock content %}
10 changes: 10 additions & 0 deletions main/templates/main/navbar.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@
</li>
{% endif %}
</ul>
<ul class="navbar-nav">
{% if user.is_authenticated %}
<li class="nav-item">
<a class="nav-link">Welcome: {{ user.username }}</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{% url 'main:help' %}">Help</a>
</li>
{% endif %}
</ul>
</div>
</div>
</nav>
1 change: 1 addition & 0 deletions main/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@
urlpatterns = [
path("", views.index, name="index"),
path("accounts/", include("django.contrib.auth.urls")),
path("help/", views.HelpView.as_view(), name="help"),
]
9 changes: 9 additions & 0 deletions main/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,18 @@
from django.contrib.auth.decorators import login_required
from django.http import HttpRequest, HttpResponse
from django.shortcuts import render
from django.views import View


@login_required
def index(request: HttpRequest) -> HttpResponse:
"""View that renders the index/home page."""
return render(request=request, template_name="main/index.html")


class HelpView(View):
"""View that renders the help page."""

def get(self, request: HttpRequest) -> HttpResponse:
"""Render the help page."""
return render(request=request, template_name="main/help.html")
8 changes: 8 additions & 0 deletions tests/main/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,11 @@ def test_index_view_authenticated(self, auth_client):
response,
f'<a href="{reverse("controller:index")}" class="btn btn-secondary">Controller</a>', # noqa: E501
)

def test_help_view(self, auth_client):
"""Test that the help view is rendered."""
response = auth_client.get(reverse("main:help"))
assert response.status_code == HTTPStatus.OK
assertTemplateUsed(response, "main/help.html")
assertContains(response, "<h1>Help</h1>")
assertContains(response, "This is the help page.")

0 comments on commit 61373b8

Please sign in to comment.