Browse Source

Built-in login formulář

export_seznamu_prednasek
Pavel 'LEdoian' Turinsky 5 years ago
parent
commit
5dda5f6628
  1. 11
      seminar/templates/seminar/login.html
  2. 2
      seminar/urls.py
  3. 12
      seminar/views.py

11
seminar/templates/seminar/login.html

@ -8,19 +8,10 @@
Přihlášení Přihlášení
{% endblock %}{% endblock %} {% endblock %}{% endblock %}
</h1> </h1>
{% if login_error %}
<span class="field_error">{{login_error}}<span>
{% endif %}
<form action="{% url 'login' %}" method="post"> <form action="{% url 'login' %}" method="post">
{% csrf_token %} {% csrf_token %}
{{form.non_field_errors}}
<ul class="form"> <ul class="form">
<li> {{ form.as_ul }}
{% include "seminar/prihlaska_field.html" with field=form.username %}
</li>
<li>
{% include "seminar/prihlaska_field.html" with field=form.password %}
</li>
</ul> </ul>
<input type="submit" value="Přihlásit"> <input type="submit" value="Přihlásit">
</form> </form>

2
seminar/urls.py

@ -99,7 +99,7 @@ urlpatterns = [
name='seminar_tex_upload' name='seminar_tex_upload'
), ),
path('auth/prihlaska/',views.prihlaskaView, name='seminar_prihlaska'), 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/logout/', views.logoutView, name='logout'),
path('auth/resitel/', views.ResitelView.as_view(), name='seminar_resitel'), path('auth/resitel/', views.ResitelView.as_view(), name='seminar_resitel'),
path('autocomplete/skola/',views.SkolaAutocomplete.as_view(), name='autocomplete_skola'), path('autocomplete/skola/',views.SkolaAutocomplete.as_view(), name='autocomplete_skola'),

12
seminar/views.py

@ -10,6 +10,7 @@ from django.http import Http404,HttpResponseBadRequest,HttpResponseRedirect
from django.db.models import Q from django.db.models import Q
from django.views.decorators.csrf import ensure_csrf_cookie 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 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.models import User
from django.contrib.auth.mixins import LoginRequiredMixin from django.contrib.auth.mixins import LoginRequiredMixin
from django.db import transaction from django.db import transaction
@ -1154,3 +1155,14 @@ class SkolaAutocomplete(autocomplete.Select2QuerySetView):
# Q(user__last_name__isstartswith=query)) # Q(user__last_name__isstartswith=query))
# #
# return qs # 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

Loading…
Cancel
Save