2017-02-09 21:04:32 +01:00
|
|
|
from django.shortcuts import render
|
2017-02-10 23:12:12 +01:00
|
|
|
from django.contrib.auth.decorators import login_required
|
2017-02-09 21:04:32 +01:00
|
|
|
|
2017-02-10 23:12:12 +01:00
|
|
|
from .forms import ProfileForm, UserForm
|
|
|
|
|
|
|
|
|
|
|
|
@login_required
|
|
|
|
def profile(request):
|
|
|
|
success = False
|
|
|
|
if request.method == "POST":
|
2017-02-12 04:24:33 +01:00
|
|
|
user_form = UserForm(request.POST, instance=request.user)
|
|
|
|
if user_form.is_valid():
|
|
|
|
user = user_form.save()
|
|
|
|
profile_form = ProfileForm(request.POST, instance=user.profile)
|
|
|
|
if profile_form.is_valid():
|
|
|
|
profile_form.save()
|
|
|
|
success = True
|
2017-02-10 23:12:12 +01:00
|
|
|
else:
|
2017-02-12 04:24:33 +01:00
|
|
|
user = request.user
|
2017-02-10 23:12:12 +01:00
|
|
|
user_form = UserForm(instance=user)
|
|
|
|
profile_form = ProfileForm(instance=user.profile)
|
|
|
|
return render(request, "gestion/profile.html",
|
|
|
|
{"user_form": user_form, "profile_form": profile_form,
|
|
|
|
"success": success})
|