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
|
|
|
|
user = request.user
|
|
|
|
if request.method == "POST":
|
|
|
|
user_form = UserForm(request.POST, instance=user)
|
|
|
|
profile_form = ProfileForm(request.POST, instance=user.profile)
|
|
|
|
if all(user_form.is_valid(), profile_form.is_valid()):
|
|
|
|
user_form.save()
|
|
|
|
profile_form.save()
|
|
|
|
success = True
|
|
|
|
else:
|
|
|
|
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})
|