+{% blocktranslate trimmed %} + You are authenticated as {{ username }}, but are not authorized to + access this page. Would you like to login to a different account? +{% endblocktranslate %} +
+{% endif %} +diff --git a/container/views.py b/container/views.py index fdae1ef..a1eae54 100644 --- a/container/views.py +++ b/container/views.py @@ -2,11 +2,13 @@ from django.views import generic from .models import Container, ContainerType import logging, json, re from django.core.exceptions import ObjectDoesNotExist +from django.contrib.auth.decorators import login_required +from django.contrib.auth.mixins import LoginRequiredMixin logger = logging.getLogger(__name__) -class ContainerListView(generic.ListView): +class ContainerListView(LoginRequiredMixin, generic.ListView): model = Container template_name = 'container/container_list.html' context_object_name = 'container_list' @@ -19,7 +21,7 @@ class ContainerListView(generic.ListView): ''' -class ContainerCreateView(generic.CreateView): +class ContainerCreateView(LoginRequiredMixin, generic.CreateView): model = Container # template_name = 'container/detail.html' fields = ['named_id', 'description', 'color', 'container_type'] @@ -30,7 +32,7 @@ class ContainerCreateView(generic.CreateView): return super().form_valid(form) -class ContainerImportView(generic.TemplateView): +class ContainerImportView(LoginRequiredMixin, generic.TemplateView): template_name = 'container_import.html' def get_context_data(self, **kwargs): @@ -47,7 +49,7 @@ class ContainerImportView(generic.TemplateView): return super().render_to_response(self) -class ContainerUpdateView(generic.UpdateView): +class ContainerUpdateView(LoginRequiredMixin, generic.UpdateView): model = Container # template_name = 'container/detail.html' fields = ['named_id', 'description', 'color', 'container_type'] @@ -57,15 +59,15 @@ class ContainerUpdateView(generic.UpdateView): return super().form_valid(form) -class ContainerDetailView(generic.DetailView): +class ContainerDetailView(LoginRequiredMixin, generic.DetailView): model = Container -class ContainerDeleteView(generic.DetailView): +class ContainerDeleteView(LoginRequiredMixin, generic.DetailView): model = Container -class ContainerPrintLabelView(generic.DetailView): +class ContainerPrintLabelView(LoginRequiredMixin, generic.DetailView): model = Container template_name = 'container/container_print_label.html' @@ -160,7 +162,7 @@ class ContainerPrintLabelView(generic.DetailView): return context -class ContainerTypeListView(generic.ListView): +class ContainerTypeListView(LoginRequiredMixin, generic.ListView): template_name = 'container/container_type_list.html' context_object_name = 'container_type_list' paginate_by = 20 @@ -173,13 +175,13 @@ class ContainerTypeListView(generic.ListView): ''' -class ContainerTypeDetailView(generic.DetailView): +class ContainerTypeDetailView(LoginRequiredMixin, generic.DetailView): model = ContainerType context_object_name = 'container_type' template_name = 'container/container_type_detail.html' -class ContainerTypeCreateView(generic.CreateView): +class ContainerTypeCreateView(LoginRequiredMixin, generic.CreateView): model = ContainerType template_name = 'container/container_type_form.html' fields = ['named_id', 'description', 'width', 'length', 'height', 'inner_width', 'inner_length', 'inner_height', @@ -191,7 +193,7 @@ class ContainerTypeCreateView(generic.CreateView): return super().form_valid(form) -class ContainerTypeUpdateView(generic.UpdateView): +class ContainerTypeUpdateView(LoginRequiredMixin, generic.UpdateView): model = ContainerType # template_name = 'container/detail.html' template_name = 'container/container_type_form.html' @@ -203,11 +205,11 @@ class ContainerTypeUpdateView(generic.UpdateView): return super().form_valid(form) -class ContainerTypeDeleteView(generic.DetailView): +class ContainerTypeDeleteView(LoginRequiredMixin, generic.DetailView): model = ContainerType -class ContainerTypeImportView(generic.TemplateView): +class ContainerTypeImportView(LoginRequiredMixin, generic.TemplateView): template_name = 'container/container_type_import.html' def get_context_data(self, **kwargs): diff --git a/homelog/settings.py b/homelog/settings.py index 1bec30f..0f06615 100644 --- a/homelog/settings.py +++ b/homelog/settings.py @@ -132,3 +132,5 @@ DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' MEDIA_URL = '/media/' MEDIA_ROOT = os.path.join(BASE_DIR, 'media') + +LOGIN_URL = '/accounts/login/' diff --git a/homelog/templates/base.html b/homelog/templates/base.html index 9e05f2f..6f8077b 100644 --- a/homelog/templates/base.html +++ b/homelog/templates/base.html @@ -61,12 +61,11 @@ {% if request.user.is_authenticated %}
+{% if form.errors.items|length == 1 %}{% translate "Please correct the error below." %}{% else %}{% translate "Please correct the errors below." %}{% endif %} +
+{% endif %} + +{% if form.non_field_errors %} +{% for error in form.non_field_errors %} ++ {{ error }} +
+{% endfor %} +{% endif %} + ++{% blocktranslate trimmed %} + You are authenticated as {{ username }}, but are not authorized to + access this page. Would you like to login to a different account? +{% endblocktranslate %} +
+{% endif %} +