From d8a46c9570a4b277213f3946aecbd14775ddf001 Mon Sep 17 00:00:00 2001 From: Roman Romanenko Date: Sat, 26 Oct 2024 16:17:48 +0000 Subject: [PATCH 1/3] Add theme toggle. --- static/js/base.js | 22 ++++++++++++++++++++++ templates/_base.html | 11 +++++++++-- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/static/js/base.js b/static/js/base.js index e69de29bb..0ca1a2b6c 100644 --- a/static/js/base.js +++ b/static/js/base.js @@ -0,0 +1,22 @@ +// From https://albertoroura.com/building-a-theme-switcher-for-bootstrap/ + +function setTheme (mode = 'auto') { + const userMode = localStorage.getItem('bs-theme'); + const sysMode = window.matchMedia('(prefers-color-scheme: light)').matches; + const useSystem = mode === 'system' || (!userMode && mode === 'auto'); + const modeChosen = useSystem ? 'system' : mode === 'dark' || mode === 'light' ? mode : userMode; + + if (useSystem) { + localStorage.removeItem('bs-theme'); + } else { + localStorage.setItem('bs-theme', modeChosen); + } + + document.documentElement.setAttribute('data-bs-theme', useSystem ? (sysMode ? 'light' : 'dark') : modeChosen); + document.querySelectorAll('.mode-switch .btn').forEach(e => e.classList.remove('text-body')); + document.getElementById(modeChosen).classList.add('text-body'); +} + +setTheme(); +document.querySelectorAll('.mode-switch .btn').forEach(e => e.addEventListener('click', () => setTheme(e.id))); +window.matchMedia('(prefers-color-scheme: light)').addEventListener('change', () => setTheme()); \ No newline at end of file diff --git a/templates/_base.html b/templates/_base.html index 81a71401a..21ec88bef 100644 --- a/templates/_base.html +++ b/templates/_base.html @@ -1,6 +1,6 @@ {% load static %} - + @@ -15,6 +15,7 @@ + {% endblock %} @@ -56,7 +57,13 @@ - {% else %} + {% endif %} +
+ + + +
+ {% if not user.is_authenticated %}
Log in From 6669f3fc9a16613477720cc485fbe0b850394e66 Mon Sep 17 00:00:00 2001 From: Roman Romanenko Date: Sat, 26 Oct 2024 19:06:14 +0000 Subject: [PATCH 2/3] Prettied up the forms. --- django_project/settings.py | 2 +- templates/_base.html | 55 +++++++++---------- templates/account/login.html | 21 +++++-- templates/account/logout.html | 25 +++++---- templates/account/password_change.html | 20 +++++-- templates/account/password_reset.html | 20 +++++-- templates/account/password_reset_done.html | 13 ++++- .../account/password_reset_from_key.html | 41 +++++++++----- .../account/password_reset_from_key_done.html | 12 +++- templates/account/password_set.html | 20 ++++--- templates/account/signup.html | 20 +++++-- templates/pages/home.html | 2 +- 12 files changed, 161 insertions(+), 90 deletions(-) diff --git a/django_project/settings.py b/django_project/settings.py index 063c8fd5d..86da3eb89 100644 --- a/django_project/settings.py +++ b/django_project/settings.py @@ -16,7 +16,7 @@ DEBUG = True # https://docs.djangoproject.com/en/dev/ref/settings/#allowed-hosts -ALLOWED_HOSTS = ["localhost", "0.0.0.0", "127.0.0.1"] +ALLOWED_HOSTS = ["localhost", "0.0.0.0", "127.0.0.1", 'scds-ai.syndevops.com'] # Application definition diff --git a/templates/_base.html b/templates/_base.html index 21ec88bef..3cfc860f3 100644 --- a/templates/_base.html +++ b/templates/_base.html @@ -6,7 +6,7 @@ - {% block title %}DjangoX{% endblock title %} + DjangoX | {% block title %}{% endblock title %} @@ -24,7 +24,7 @@
diff --git a/templates/account/login.html b/templates/account/login.html index 10fe7bf25..b53a699a5 100644 --- a/templates/account/login.html +++ b/templates/account/login.html @@ -4,10 +4,19 @@ {% block title %}Log in{% endblock %} {% block content %} -

Log in

-
- {% csrf_token %} - {{ form|crispy }} - -
+
+
+
+
+

Login

+
+ {% csrf_token %} + {{ form|crispy }} + +
+
+
+
+
+ {% endblock content %} diff --git a/templates/account/logout.html b/templates/account/logout.html index 5eb974791..883eff480 100644 --- a/templates/account/logout.html +++ b/templates/account/logout.html @@ -5,14 +5,19 @@ {% block content %} -

Sign Out

- -

Are you sure you want to sign out?

- -
- {% csrf_token %} - {{ form|crispy }} - -
- +
+
+
+
+

Sign Out

+
Are you sure you want to sign out?
+
+ {% csrf_token %} + {{ form|crispy }} + +
+
+
+
+ {% endblock content %} \ No newline at end of file diff --git a/templates/account/password_change.html b/templates/account/password_change.html index 937c99a0f..7ee3ad1fe 100644 --- a/templates/account/password_change.html +++ b/templates/account/password_change.html @@ -4,10 +4,18 @@ {% block title %}Change Password{% endblock %} {% block content %} -

Change Password

-
- {% csrf_token %} - {{ form|crispy }} - -
+
+
+
+
+

Change Password

+
+ {% csrf_token %} + {{ form|crispy }} + +
+
+
+
+ {% endblock content %} diff --git a/templates/account/password_reset.html b/templates/account/password_reset.html index be2c91d1b..e2257c7b5 100644 --- a/templates/account/password_reset.html +++ b/templates/account/password_reset.html @@ -4,10 +4,18 @@ {% block title %}Password Reset{% endblock %} {% block content %} -

Forgot your password?

-
- {% csrf_token %} - {{ form | crispy }} - -
+
+
+
+
+

Password Reset

+
+ {% csrf_token %} + {{ form | crispy }} + +
+
+
+
+
{% endblock content %} diff --git a/templates/account/password_reset_done.html b/templates/account/password_reset_done.html index 2e6f3d3ab..ab8065cc2 100644 --- a/templates/account/password_reset_done.html +++ b/templates/account/password_reset_done.html @@ -4,6 +4,15 @@ {% block title %}Password Reset Done{% endblock %} {% block content %} -

Password Reset

-

We have sent you an e-mail. Please contact us if you do not receive it in a few minutes.

+
+
+
+
+

Password Reset

+
We have sent you an e-mail. Please contact us if you do not receive it in a few minutes.
+
+
+
+
+ {% endblock content %} diff --git a/templates/account/password_reset_from_key.html b/templates/account/password_reset_from_key.html index fb9eeb38a..49588eddb 100644 --- a/templates/account/password_reset_from_key.html +++ b/templates/account/password_reset_from_key.html @@ -4,19 +4,30 @@ {% block title %}Change Password{% endblock title %} {% block content %} -

{% if token_fail %}Bad Token{% else %}Change Password{% endif %}

- - {% if token_fail %} -

The password reset link was invalid. Perhaps it has already been used? Please request a new password reset.

- {% else %} - {% if form %} -
- {% csrf_token %} - {{ form|crispy }} - -
- {% else %} -

Your password is now changed.

- {% endif %} - {% endif %} +
+
+
+
+

Password Reset

+ {% if token_fail %} +
+ The password reset link was invalid. Perhaps it has already been used? + Please request a new password reset. +
+ {% else %} + {% if form %} +
+ {% csrf_token %} + {{ form|crispy }} + +
+ {% else %} +

Your password is now changed.

+ {% endif %} + {% endif %} +
+
+
+
+ {% endblock content%} diff --git a/templates/account/password_reset_from_key_done.html b/templates/account/password_reset_from_key_done.html index 58c40944c..6ec7458fc 100644 --- a/templates/account/password_reset_from_key_done.html +++ b/templates/account/password_reset_from_key_done.html @@ -4,6 +4,14 @@ {% block title %}Change Password Done{% endblock title %} {% block content %} -

Password Change Done

-

Your password has been changed.

+
+
+
+
+

Password Reset

+
Your password has been changed.
+
+
+
+
{% endblock content %} \ No newline at end of file diff --git a/templates/account/password_set.html b/templates/account/password_set.html index a46b8f1c1..b7194f410 100644 --- a/templates/account/password_set.html +++ b/templates/account/password_set.html @@ -4,12 +4,18 @@ {% block title %}Set Password{% endblock title %} {% block content %} -
- {% csrf_token %} - {{ form | crispy }} -
- +
+
+
+
+

Set Password

+ + {% csrf_token %} + {{ form|crispy }} + + +
+
- +
{% endblock content %} diff --git a/templates/account/signup.html b/templates/account/signup.html index da021a99c..a16beb34f 100644 --- a/templates/account/signup.html +++ b/templates/account/signup.html @@ -4,10 +4,18 @@ {% block title %}Sign up{% endblock %} {% block content %} -

Sign up

-
- {% csrf_token %} - {{ form|crispy }} - -
+
+
+
+
+

Sign Up

+
+ {% csrf_token %} + {{ form|crispy }} + +
+
+
+
+
{% endblock content %} \ No newline at end of file diff --git a/templates/pages/home.html b/templates/pages/home.html index 2169f640a..dbd73297b 100644 --- a/templates/pages/home.html +++ b/templates/pages/home.html @@ -5,7 +5,7 @@ {% block content %}
- DjangoX logo + DjangoX logo

A Django starter project with batteries.

{% endblock content %} From bdff5beea43abad09b6227fb4085f1dd39d74409 Mon Sep 17 00:00:00 2001 From: Roman Romanenko Date: Sat, 26 Oct 2024 19:08:05 +0000 Subject: [PATCH 3/3] Removed URL. --- django_project/settings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/django_project/settings.py b/django_project/settings.py index 86da3eb89..063c8fd5d 100644 --- a/django_project/settings.py +++ b/django_project/settings.py @@ -16,7 +16,7 @@ DEBUG = True # https://docs.djangoproject.com/en/dev/ref/settings/#allowed-hosts -ALLOWED_HOSTS = ["localhost", "0.0.0.0", "127.0.0.1", 'scds-ai.syndevops.com'] +ALLOWED_HOSTS = ["localhost", "0.0.0.0", "127.0.0.1"] # Application definition