From e3d42d0109e087e48f2fd695dcedb510848ecf53 Mon Sep 17 00:00:00 2001 From: Frederic Date: Fri, 26 Apr 2019 14:21:15 +0200 Subject: [PATCH] add custom templating --- README.md | 10 +++- bam/templates/bam/base.html | 75 ++++++++++++++++++++++++++ bam/templates/bam/logged_out.html | 5 ++ bam/templates/bam/login.html | 36 +++++++++++++ bam/templates/bam/password_change.html | 32 +++++++++++ bam/templates/bam/profile.html | 4 ++ bam/templates/base.html | 8 --- bam/templates/profile.html | 7 --- bam/templates/registration/login.html | 38 ------------- bam/urls.py | 42 ++++++++++++++- bam/views.py | 2 +- 11 files changed, 202 insertions(+), 57 deletions(-) create mode 100644 bam/templates/bam/base.html create mode 100644 bam/templates/bam/logged_out.html create mode 100644 bam/templates/bam/login.html create mode 100644 bam/templates/bam/password_change.html create mode 100644 bam/templates/bam/profile.html delete mode 100644 bam/templates/base.html delete mode 100644 bam/templates/profile.html delete mode 100644 bam/templates/registration/login.html diff --git a/README.md b/README.md index 00e2c83..803576d 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ ## Installation -Currently, this repository does only contain a plain `Django` app without a +Currently, this repository does only contain a plain _Django_ app without a project. The app is not (yet) packaged. Therfore, the following steps are necessary to initialize a development environment: @@ -35,6 +35,14 @@ ln -sr bam PROJECT_DIRECTORY/bam ``` ./manage.py createsuperuser +``` + + 8. Download _Pure.css_ and extract it to `bam/static/`. + + 9. Start the development server: + + ``` +./manage.py runserver ``` ## ToDo diff --git a/bam/templates/bam/base.html b/bam/templates/bam/base.html new file mode 100644 index 0000000..a6f8bee --- /dev/null +++ b/bam/templates/bam/base.html @@ -0,0 +1,75 @@ +{% load static %} + + + + + + + {% block content-extra-head %} + {% endblock %} + + + + + + +
+ {% block content %} + {% endblock %} +
+ + diff --git a/bam/templates/bam/logged_out.html b/bam/templates/bam/logged_out.html new file mode 100644 index 0000000..0297913 --- /dev/null +++ b/bam/templates/bam/logged_out.html @@ -0,0 +1,5 @@ +{% extends "bam/base.html" %} +{% block content %} +

Logged out

You have been logged out.

+

Log in again

+{% endblock %} diff --git a/bam/templates/bam/login.html b/bam/templates/bam/login.html new file mode 100644 index 0000000..a6612b1 --- /dev/null +++ b/bam/templates/bam/login.html @@ -0,0 +1,36 @@ +{% extends "bam/base.html" %} +{% block content %} +

Login

+ +{% if form.errors %} +

Your username and password didn't match. Please try again.

+{% endif %} + +{% if next %} + {% if user.is_authenticated %} +

Your account doesn't have access to this page. To proceed, + please login with an account that has access.

+ {% else %} +

Please login to see this page.

+ {% endif %} +{% endif %} + +
+ {% csrf_token %} +
+
+ {{ form.username.label_tag }} + {{ form.username }} +
+
+ {{ form.password.label_tag }} + {{ form.password }} +
+
+ + Lost password? +
+ +
+
+{% endblock %} diff --git a/bam/templates/bam/password_change.html b/bam/templates/bam/password_change.html new file mode 100644 index 0000000..721f770 --- /dev/null +++ b/bam/templates/bam/password_change.html @@ -0,0 +1,32 @@ +{% extends "bam/base.html" %} +{% block content-extra-head %} + +{% endblock %} +{% block content %} +

Password Change

+ +

+

+ {% csrf_token %} +
+ {% for field in form %} +
+ {{ field.label_tag }} + {{ field }} + {% for error in field.errors %} + {{ error }} + {% endfor %} +
+ {% endfor %} +
+ +
+ +
+
+

+{% endblock %} diff --git a/bam/templates/bam/profile.html b/bam/templates/bam/profile.html new file mode 100644 index 0000000..c0dab0d --- /dev/null +++ b/bam/templates/bam/profile.html @@ -0,0 +1,4 @@ +{% extends "bam/base.html" %} +{% block content %} +

Welcome, {{ user.username }}!

+{% endblock %} diff --git a/bam/templates/base.html b/bam/templates/base.html deleted file mode 100644 index ab807ba..0000000 --- a/bam/templates/base.html +++ /dev/null @@ -1,8 +0,0 @@ - - - - -{% block content %} -{% endblock %} - - diff --git a/bam/templates/profile.html b/bam/templates/profile.html deleted file mode 100644 index 68a1819..0000000 --- a/bam/templates/profile.html +++ /dev/null @@ -1,7 +0,0 @@ -{% extends "base.html" %} - -{% block content %} - -Change password - -{% endblock %} diff --git a/bam/templates/registration/login.html b/bam/templates/registration/login.html deleted file mode 100644 index dce5873..0000000 --- a/bam/templates/registration/login.html +++ /dev/null @@ -1,38 +0,0 @@ -{% extends "base.html" %} - -{% block content %} - -{% if form.errors %} -

Your username and password didn't match. Please try again.

-{% endif %} - -{% if next %} - {% if user.is_authenticated %} -

Your account doesn't have access to this page. To proceed, - please login with an account that has access.

- {% else %} -

Please login to see this page.

- {% endif %} -{% endif %} - -
-{% csrf_token %} - - - - - - - - - -
{{ form.username.label_tag }}{{ form.username }}
{{ form.password.label_tag }}{{ form.password }}
- - - -
- -{# Assumes you setup the password_reset view in your URLconf #} -

Lost password?

- -{% endblock %} diff --git a/bam/urls.py b/bam/urls.py index 1a66007..6c3b655 100644 --- a/bam/urls.py +++ b/bam/urls.py @@ -3,9 +3,47 @@ from django.urls import path from django.urls import include from django.views.generic.base import RedirectView from bam.views import ProfileView +import django.contrib.auth.views as auth_views urlpatterns = [ - path('accounts/profile/', ProfileView.as_view(), name='profile'), - path('accounts/', include('django.contrib.auth.urls')), + path('accounts/profile/', RedirectView.as_view(pattern_name='profile')), path('', RedirectView.as_view(pattern_name='profile')), + path('profile/', ProfileView.as_view(), name='profile'), + + path('login/', + auth_views.LoginView.as_view(template_name='bam/login.html'), + name='login'), + path('logout/', + auth_views.LogoutView.as_view(template_name='bam/logged_out.html'), + name='logout'), + path('password_change/', + auth_views.PasswordChangeView.as_view( + template_name='bam/password_change.html' + ), + name='password_change'), + path('password_change_done/', + auth_views.PasswordChangeDoneView.as_view( + template_name='bam/password_change_done.html' + ), + name='password_change_done'), + path('password_reset/', + auth_views.PasswordResetView.as_view( + template_name='bam/password_reset.html' + ), + name='password_reset'), + path('password_reset_done/', + auth_views.PasswordResetDoneView.as_view( + template_name='bam/password_reset_done.html' + ), + name='password_reset_done'), + path('password_reset_confirm/', + auth_views.PasswordResetConfirmView.as_view( + template_name='bam/password_reset_confirm.html' + ), + name='password_reset_confirm'), + path('password_reset_complete/', + auth_views.PasswordResetCompleteView.as_view( + template_name='bam/password_reset_complete.html' + ), + name='password_reset_complete'), ] diff --git a/bam/views.py b/bam/views.py index d8894d5..5a9f665 100644 --- a/bam/views.py +++ b/bam/views.py @@ -2,4 +2,4 @@ from django.views.generic.base import TemplateView from django.contrib.auth.mixins import LoginRequiredMixin class ProfileView(LoginRequiredMixin, TemplateView): - template_name = 'profile.html' + template_name = 'bam/profile.html'