feat & chore: list logged in user in nav & linting
parent
64b4437acd
commit
5a10b06e11
2
Makefile
2
Makefile
|
@ -33,6 +33,8 @@ help: ## Prints help for targets with comments
|
||||||
lint: ## Run linter
|
lint: ## Run linter
|
||||||
@./venv/bin/black ./dashboard/*
|
@./venv/bin/black ./dashboard/*
|
||||||
@./venv/bin/black ./accounts/*
|
@./venv/bin/black ./accounts/*
|
||||||
|
@./venv/bin/black ./dash/*
|
||||||
|
@./venv/bin/black ./support/*
|
||||||
|
|
||||||
migrate: ## Run migrations
|
migrate: ## Run migrations
|
||||||
$(call run_migrations)
|
$(call run_migrations)
|
||||||
|
|
|
@ -2,5 +2,5 @@ from django.apps import AppConfig
|
||||||
|
|
||||||
|
|
||||||
class DashConfig(AppConfig):
|
class DashConfig(AppConfig):
|
||||||
default_auto_field = 'django.db.models.BigAutoField'
|
default_auto_field = "django.db.models.BigAutoField"
|
||||||
name = 'dash'
|
name = "dash"
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<aside class="secondary-nav__container">
|
<aside class="secondary-nav__container">
|
||||||
<nav class="secondary-nav">
|
<nav class="secondary-nav">
|
||||||
<div class="secondary-nav__options">
|
<div class="secondary-nav__options">
|
||||||
<p class="secondary-nav__option-link">realaravinth</p>
|
<p class="secondary-nav__option-link">Hello, {{ username }}!</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="secondary-nav__options">
|
<div class="secondary-nav__options">
|
||||||
<a href="/foo" class="secondary-nav__option-link">Instances</a>
|
<a href="/foo" class="secondary-nav__option-link">Instances</a>
|
||||||
|
|
|
@ -19,6 +19,7 @@ from django.test import TestCase, Client, override_settings
|
||||||
from django.contrib.auth import authenticate
|
from django.contrib.auth import authenticate
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
|
||||||
|
|
||||||
class DashHome(TestCase):
|
class DashHome(TestCase):
|
||||||
"""
|
"""
|
||||||
Tests create new app view
|
Tests create new app view
|
||||||
|
@ -45,7 +46,9 @@ class DashHome(TestCase):
|
||||||
# default LOGIN redirect URI that is used by @login_required decorator is
|
# default LOGIN redirect URI that is used by @login_required decorator is
|
||||||
# /accounts/login. There's a redirection endpoint at /accounts/login/ that
|
# /accounts/login. There's a redirection endpoint at /accounts/login/ that
|
||||||
# will redirect user to /login. Hence the /accounts prefix
|
# will redirect user to /login. Hence the /accounts prefix
|
||||||
redirect_login_uri = f"/accounts{reverse('accounts.login')}?next={reverse('dash.home')}"
|
redirect_login_uri = (
|
||||||
|
f"/accounts{reverse('accounts.login')}?next={reverse('dash.home')}"
|
||||||
|
)
|
||||||
self.assertEqual(resp.headers["location"], redirect_login_uri)
|
self.assertEqual(resp.headers["location"], redirect_login_uri)
|
||||||
|
|
||||||
def test_dash_home_renders(self):
|
def test_dash_home_renders(self):
|
||||||
|
@ -64,7 +67,7 @@ class DashHome(TestCase):
|
||||||
self.assertEqual(resp.headers["location"], reverse("accounts.home"))
|
self.assertEqual(resp.headers["location"], reverse("accounts.home"))
|
||||||
|
|
||||||
# email login works
|
# email login works
|
||||||
resp = c.get(reverse('dash.home'))
|
resp = c.get(reverse("dash.home"))
|
||||||
self.assertEqual(resp.status_code, 200)
|
self.assertEqual(resp.status_code, 200)
|
||||||
self.assertEqual(b"Billing" in resp.content, True)
|
self.assertEqual(b"Billing" in resp.content, True)
|
||||||
self.assertEqual(b"Support" in resp.content, True)
|
self.assertEqual(b"Support" in resp.content, True)
|
||||||
|
|
|
@ -15,9 +15,7 @@
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from django.urls import path, include
|
from django.urls import path, include
|
||||||
|
|
||||||
from .views import (
|
from .views import home
|
||||||
home
|
|
||||||
)
|
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path("", home, name="dash.home"),
|
path("", home, name="dash.home"),
|
||||||
|
|
|
@ -21,16 +21,24 @@ from django.http import HttpResponse
|
||||||
from django.views.decorators.csrf import csrf_protect
|
from django.views.decorators.csrf import csrf_protect
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
|
|
||||||
def default_ctx(title: str):
|
|
||||||
|
def default_ctx(title: str, username: str):
|
||||||
|
"""
|
||||||
|
Default context for all dashboard pages
|
||||||
|
"""
|
||||||
return {
|
return {
|
||||||
"title": title,
|
"title": title,
|
||||||
|
"username": username,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
def home(request):
|
def home(request):
|
||||||
|
"""
|
||||||
|
Dashboard homepage view
|
||||||
|
"""
|
||||||
PAGE_TITLE = "Home"
|
PAGE_TITLE = "Home"
|
||||||
ctx = default_ctx(title=PAGE_TITLE)
|
username = request.user
|
||||||
|
ctx = default_ctx(title=PAGE_TITLE, username=username.username)
|
||||||
|
|
||||||
return render(request, "dash/home/index.html", context=ctx)
|
return render(request, "dash/home/index.html", context=ctx)
|
||||||
|
|
Loading…
Reference in New Issue