cleans up code of 'website' module, replaces hardcoded 'year_of_bilan' value
This commit is contained in:
@@ -1,17 +1,16 @@
|
||||
from django.urls import reverse
|
||||
from django import views
|
||||
|
||||
from django.urls import reverse
|
||||
from django.contrib.auth import login, authenticate
|
||||
from django.contrib import messages
|
||||
from django.http import HttpResponseRedirect, HttpResponsePermanentRedirect
|
||||
|
||||
class Index(views.generic.TemplateView):
|
||||
|
||||
class Index(views.generic.TemplateView):
|
||||
template_name = "index.html"
|
||||
app_menu = None
|
||||
header = ('La Maraude ALSA', 'accueil')
|
||||
|
||||
http_method_names = ['get',]
|
||||
http_method_names = ['get', ]
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
@@ -19,7 +18,6 @@ class Index(views.generic.TemplateView):
|
||||
return context
|
||||
|
||||
|
||||
|
||||
def _get_entry_point(user):
|
||||
from utilisateurs.models import Maraudeur
|
||||
if isinstance(user, Maraudeur):
|
||||
@@ -27,6 +25,7 @@ def _get_entry_point(user):
|
||||
else:
|
||||
return reverse('index')
|
||||
|
||||
|
||||
def login_view(request):
|
||||
if request.method == 'GET':
|
||||
return HttpResponsePermanentRedirect('/')
|
||||
@@ -36,12 +35,11 @@ def login_view(request):
|
||||
user = authenticate(username=username, password=password)
|
||||
if user is not None:
|
||||
login(request, user)
|
||||
next = request.POST.get('next', None)
|
||||
if not next:
|
||||
next = _get_entry_point(user)
|
||||
_next = request.POST.get('next', None)
|
||||
if not _next:
|
||||
_next = _get_entry_point(user)
|
||||
messages.success(request, "%s, vous êtes connecté !" % user)
|
||||
return HttpResponseRedirect(next)
|
||||
return HttpResponseRedirect(_next)
|
||||
else:
|
||||
messages.error(request, "Le nom d'utilisateur et/ou le mot de passe sont incorrects !")
|
||||
return HttpResponseRedirect('/')
|
||||
|
||||
|
||||
Reference in New Issue
Block a user