ernestophone.ens.fr/gestion/views.py
2015-07-22 16:08:59 -04:00

69 lines
2.6 KiB
Python

from django.shortcuts import render, redirect
from django.contrib.auth.views import login as django_login_view
from django.contrib.auth.models import User
from django.contrib.auth.forms import AuthenticationForm
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from datetime import *
import smtplib
from gestion.forms import InscriptionMembreForm, RegistrationFormUser
from gestion.models import ErnestoUser
from propositions.utils import generer
from calendrier.views import calendar
def inscription_membre(request):
if request.method == 'POST':
requbis = request.POST.copy()
user_form = RegistrationFormUser(requbis)
comp_form = InscriptionMembreForm(requbis)
if user_form.is_valid() and comp_form.is_valid():
pseudo = user_form.cleaned_data['username']
if not (comp_form.cleaned_data['validation'] == "Pouet-ta-mere"):
error = "Le champ Validation ne correspond pas à celui attendu"
return render(request, "gestion/registration.html", locals())
member = user_form.save(commit=False)
temp = True
while temp:
code = generer()
try:
ErnestoUser.objects.get(slug=code)
except:
temp=False
member.save()
(profile, _) = ErnestoUser.objects.get_or_create(user = member)
comp_form = InscriptionMembreForm(requbis, instance = profile)
obj = comp_form.save(commit=False)
obj.slug=code
obj.save()
envoi = True
return render(request, 'gestion/thanks.html', locals())
else:
comp_form = InscriptionMembreForm()
user_form = RegistrationFormUser()
return render(request, 'gestion/registration.html', locals())
def home(request):
lToday = datetime.now()
return calendar(request, lToday.year, lToday.month)
def login(request):
if request.method == "POST" and "username" in request.POST:
try:
user = User.objects.get(username = request.POST["username"])
if not user.is_active:
error = "Votre compte n'est pas actif"
return render(request, "gestion/login.html", locals())
if not user.has_usable_password() or user.password in ("", "!"):
return render(request, "error.html", {"error_type": "no_password"})
except User.DoesNotExist:
pass
return django_login_view(request, template_name = 'login.html', )
def divers(request):
return render(request, "gestion/divers.html", locals())
# Create your views here.