From 5dda5f662838f212d4638b56b805240a0ee573a2 Mon Sep 17 00:00:00 2001 From: Pavel 'LEdoian' Turinsky Date: Fri, 13 Dec 2019 16:38:56 +0100 Subject: [PATCH] =?UTF-8?q?Built-in=20login=20formul=C3=A1=C5=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- seminar/templates/seminar/login.html | 11 +---------- seminar/urls.py | 2 +- seminar/views.py | 12 ++++++++++++ 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/seminar/templates/seminar/login.html b/seminar/templates/seminar/login.html index 88cd364f..eee1303c 100644 --- a/seminar/templates/seminar/login.html +++ b/seminar/templates/seminar/login.html @@ -8,19 +8,10 @@ Přihlášení {% endblock %}{% endblock %} -{% if login_error %} -{{login_error}} -{% endif %}
{% csrf_token %} - {{form.non_field_errors}}
    -
  • - {% include "seminar/prihlaska_field.html" with field=form.username %} -
  • -
  • - {% include "seminar/prihlaska_field.html" with field=form.password %} -
  • + {{ form.as_ul }}
diff --git a/seminar/urls.py b/seminar/urls.py index 9d2c158a..5f534020 100644 --- a/seminar/urls.py +++ b/seminar/urls.py @@ -99,7 +99,7 @@ urlpatterns = [ name='seminar_tex_upload' ), path('auth/prihlaska/',views.prihlaskaView, name='seminar_prihlaska'), - path('auth/login/', views.loginView, name='login'), + path('auth/login/', views.LoginView.as_view(), name='login'), path('auth/logout/', views.logoutView, name='logout'), path('auth/resitel/', views.ResitelView.as_view(), name='seminar_resitel'), path('autocomplete/skola/',views.SkolaAutocomplete.as_view(), name='autocomplete_skola'), diff --git a/seminar/views.py b/seminar/views.py index bb580c08..46571927 100644 --- a/seminar/views.py +++ b/seminar/views.py @@ -10,6 +10,7 @@ from django.http import Http404,HttpResponseBadRequest,HttpResponseRedirect from django.db.models import Q from django.views.decorators.csrf import ensure_csrf_cookie from django.contrib.auth import authenticate, login, get_user_model, logout +from django.contrib.auth import views as auth_views from django.contrib.auth.models import User from django.contrib.auth.mixins import LoginRequiredMixin from django.db import transaction @@ -1154,3 +1155,14 @@ class SkolaAutocomplete(autocomplete.Select2QuerySetView): # Q(user__last_name__isstartswith=query)) # # return qs + +# FIXME: Tohle asi vlastně vůbec nepatří do aplikace 'seminar' +class LoginView(auth_views.LoginView): + # Jen vezmeme vestavěný a dáme mu vhodný template a přesměrovací URL + template_name = 'seminar/login.html' + + # Přesměrovací URL má být v kontextu: + def get_context_data(self, **kwargs): + ctx = super().get_context_data(**kwargs) + ctx['next'] = reverse('titulni_strana') + return ctx