* started workin on 'navbar' module * changed bootstrap theme to bootswatch/Simplex * big work on navbar logic * starting creating menus using navbar * converted app views to new Wepage decorator, updated navbar * reimplemented DernieresMaraudes as a dropdown instead of ContextMixin * reorganised static files, minor code cleanups * turned Link.href into lazy-evaluated property * collapsed 'navbar' module into 'website', dynamic building of ApplicationMenu subclasses * minor cleanup * blah blah blah * added way to add admin/non-admin links * minor style change : red border for active page instead of all dropdowns * deleted file * prepare adding removing menu templates files, being replaced by code * essayé de généraliser le code pour les modaux bootstrap, non testé git status * more preparation and thinking on navbar app_menus logic... * added LinkManager and DropdownManager, getting closer... * small fix in DropdownManager.__get__ * boosted up work: keep it simple so it can be merged fast, major layout changes * added month filter on maraudes:liste * added 'as_icon' filter to display boolean/null values as bootstrap icons * remove inactive user from planning selection * removed all unused 'menu' templates * set up django_select2 to use static files * small fix after review
49 lines
1.5 KiB
Python
49 lines
1.5 KiB
Python
from django.shortcuts import redirect
|
|
from django.urls import reverse
|
|
from django import views
|
|
from .mixins import WebsiteTemplateMixin
|
|
|
|
from django.contrib.auth import login, authenticate
|
|
from django.http import HttpResponseRedirect, HttpResponsePermanentRedirect
|
|
|
|
class Index(WebsiteTemplateMixin, views.generic.TemplateView):
|
|
|
|
template_name = "main.html"
|
|
app_menu = None
|
|
header = ('La Maraude ALSA', 'accueil')
|
|
class PageInfo:
|
|
title = "La maraude ALSA"
|
|
header = "La Maraude ALSA"
|
|
header_small = "accueil"
|
|
|
|
def get_context_data(self, **kwargs):
|
|
context = super().get_context_data(**kwargs)
|
|
context["next"] = self.request.GET.get("next", "")
|
|
return context
|
|
|
|
|
|
|
|
def _get_entry_point(user):
|
|
from utilisateurs.models import Maraudeur
|
|
|
|
if isinstance(user, Maraudeur):
|
|
return reverse('maraudes:index')
|
|
else:
|
|
return reverse('index')
|
|
|
|
def login_view(request):
|
|
if request.method == 'GET':
|
|
return HttpResponsePermanentRedirect('/')
|
|
elif request.method == 'POST':
|
|
username = request.POST['username']
|
|
password = request.POST['password']
|
|
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)
|
|
return HttpResponseRedirect(next)
|
|
else:
|
|
return HttpResponseRedirect('/')
|