From f68e40ef4e34358ef4f85b1f92db0ee97b712ed8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20H=C3=A4ttasch?= Date: Thu, 17 Sep 2020 00:09:14 +0200 Subject: [PATCH] Introduce language picking Activate language middleware Add middleware URLs Add new dropdown menu to navbar containing language links and move logout link there Add script to prevent language changes for pages with unsaved content Add class to all forms that should get that protection Fix formatting of some templates --- collab_coursebook/settings.py | 1 + collab_coursebook/urls.py | 1 + frontend/templates/frontend/base.html | 55 +++++++++++++------ frontend/templates/frontend/comment/edit.html | 2 +- .../frontend/content/addcontent.html | 2 +- .../templates/frontend/content/detail.html | 2 +- .../templates/frontend/course/create.html | 2 +- .../templates/frontend/course/duplicate.html | 2 +- frontend/templates/frontend/course/edit.html | 2 +- frontend/templates/frontend/navbar.html | 32 ++++++++++- .../frontend/profile/profile_edit.html | 2 +- 11 files changed, 75 insertions(+), 28 deletions(-) diff --git a/collab_coursebook/settings.py b/collab_coursebook/settings.py index 76b6da21..93795db5 100644 --- a/collab_coursebook/settings.py +++ b/collab_coursebook/settings.py @@ -51,6 +51,7 @@ MIDDLEWARE = [ 'django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.middleware.locale.LocaleMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', diff --git a/collab_coursebook/urls.py b/collab_coursebook/urls.py index ab6b4a71..fb970428 100644 --- a/collab_coursebook/urls.py +++ b/collab_coursebook/urls.py @@ -27,4 +27,5 @@ path('accounts/logout/', django_cas_ng.views.LogoutView.as_view(), name='cas_ng_logout'), path('accounts/callback/', django_cas_ng.views.CallbackView.as_view(), name='cas_ng_proxy_callback'), path('', include('frontend.urls', namespace='frontend')), + path('i18n/', include('django.conf.urls.i18n')), ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) diff --git a/frontend/templates/frontend/base.html b/frontend/templates/frontend/base.html index f1358622..d71a8847 100644 --- a/frontend/templates/frontend/base.html +++ b/frontend/templates/frontend/base.html @@ -17,30 +17,49 @@ + + {% block imports %}{% endblock %} -{% block general_content %} + {% block general_content %} + {% endblock %} -{% endblock %} +
+ {% block footer_custom %} + {% endblock %} + {% footer_info as FI %} + {% if FI.impress_text %} + {{ FI.impress_text }} · + {% endif %} + {% if FI.impress_url %} + {% trans "Impress" %} · + {% endif %} + {% if FI.repo_url %} + {% trans "This software is open source" %} + {% endif %} +
-
- {% block footer_custom %} - {% endblock %} - {% footer_info as FI %} - {% if FI.impress_text %} - {{ FI.impress_text }} · - {% endif %} - {% if FI.impress_url %} - {% trans "Impress" %} · - {% endif %} - {% if FI.repo_url %} - {% trans "This software is open source" %} - {% endif %} -
- -{% block bottom_script %}{% endblock %} + {% block bottom_script %}{% endblock %} diff --git a/frontend/templates/frontend/comment/edit.html b/frontend/templates/frontend/comment/edit.html index c067b7af..a514a371 100644 --- a/frontend/templates/frontend/comment/edit.html +++ b/frontend/templates/frontend/comment/edit.html @@ -8,7 +8,7 @@ {% block content %}

Edit comment

-
+ {% csrf_token %} {% bootstrap_form form %} diff --git a/frontend/templates/frontend/content/addcontent.html b/frontend/templates/frontend/content/addcontent.html index 82829c85..39ff174a 100644 --- a/frontend/templates/frontend/content/addcontent.html +++ b/frontend/templates/frontend/content/addcontent.html @@ -12,7 +12,7 @@ {% endblock %} {% block content %} - + {% csrf_token %} {% bootstrap_form form %} {% bootstrap_form content_type_form %} diff --git a/frontend/templates/frontend/content/detail.html b/frontend/templates/frontend/content/detail.html index ce4875c2..86f3d402 100644 --- a/frontend/templates/frontend/content/detail.html +++ b/frontend/templates/frontend/content/detail.html @@ -114,7 +114,7 @@
{% trans "Rating" %}
{% trans "Comments" %}
{% if user.is_authenticated %} - + {% csrf_token %} {% bootstrap_form comment_form %} diff --git a/frontend/templates/frontend/course/create.html b/frontend/templates/frontend/course/create.html index 1e7d2c6b..64dc1937 100644 --- a/frontend/templates/frontend/course/create.html +++ b/frontend/templates/frontend/course/create.html @@ -18,7 +18,7 @@ {% block content %}

Create a new Course

- + {% csrf_token %} {% bootstrap_form form %} diff --git a/frontend/templates/frontend/course/duplicate.html b/frontend/templates/frontend/course/duplicate.html index 3eef5d40..4737dd75 100644 --- a/frontend/templates/frontend/course/duplicate.html +++ b/frontend/templates/frontend/course/duplicate.html @@ -18,7 +18,7 @@ {% block content %}

{% trans "Duplicate Course" %}

- + {% csrf_token %} {% bootstrap_form form %} diff --git a/frontend/templates/frontend/course/edit.html b/frontend/templates/frontend/course/edit.html index 66e69c96..a4bf0444 100644 --- a/frontend/templates/frontend/course/edit.html +++ b/frontend/templates/frontend/course/edit.html @@ -18,7 +18,7 @@ {% block content %}

Edit Course

- + {% csrf_token %} {% bootstrap_form form %} diff --git a/frontend/templates/frontend/navbar.html b/frontend/templates/frontend/navbar.html index 78d212e2..769fd64a 100644 --- a/frontend/templates/frontend/navbar.html +++ b/frontend/templates/frontend/navbar.html @@ -15,9 +15,35 @@   {% endif %} {{ user.get_username }} -   - {% trans "Logout" %} + +
+
+ + +
+
{% endif %} -

Collab Coursebook

+

Collab Coursebook

diff --git a/frontend/templates/frontend/profile/profile_edit.html b/frontend/templates/frontend/profile/profile_edit.html index ad106716..ef1f1d4b 100644 --- a/frontend/templates/frontend/profile/profile_edit.html +++ b/frontend/templates/frontend/profile/profile_edit.html @@ -8,7 +8,7 @@ {% block content %}

{% trans "Edit your profile" %}

-
{% csrf_token %} + {% csrf_token %} {% bootstrap_form form %} {% buttons %}