def PerfilView(request): template_name = 'accounts_perfil.html' user = request.user edit = False if request.method == 'POST': form = MyUserForm(request.POST) if form.is_valid(): user.set_datos(first_name=form.cleaned_data['first_name'], last_name=form.cleaned_data['last_name'], photo=form.cleaned_data['photo']) email = form.cleaned_data['email'] if email != None and user.email != email: user = MyUser.objects.filter(email=email) if len(user) == 0: user.set_email(email) user.set_verify_email(False) code = CodeValidator(code=_generate_code(), user=user) code.save() email_verify_password(code, user) else: form.add_error("email", "El email ya se encuentra registrado") edit = True user.save() else: form = MyUserForm(instance=user) return render(request, template_name, {'form': form, 'edit': edit})
def profile_edit(request): if request.method == 'POST': user_form = MyUserForm(request.POST, instance=request.user) profile_form = ProfileForm(request.POST, files=request.FILES, instance=request.user.profile) if user_form.is_valid() and profile_form.is_valid(): user_form.save() profile_form.save() return HttpResponseRedirect(reverse('accounts:profile_details')) else: user_form = MyUserForm(instance=request.user) profile_form = ProfileForm(instance=request.user.profile) context = {'user_form': user_form, 'profile_form': profile_form} return render(request, 'accounts/profile_edit.html', context)
def profile_edit(request): # if 'profile_picture' in request.POST: # del request.POST['profile_picture'] user_form = MyUserForm(instance=request.user) profile_form = ProfileForm(instance=request.user.profile) if request.method == 'POST': user_form = MyUserForm(data=request.POST, instance=request.user) profile_form = ProfileForm(data=request.POST, files=request.FILES, instance=request.user.profile) if user_form.is_valid() and profile_form.is_valid(): user_form.save() profile_form.save() return HttpResponseRedirect(reverse('accounts:show_profile')) else: print(user_form.is_valid(), profile_form.is_valid()) context = { 'user_form': user_form, 'profile_form': profile_form } return render(request, 'accounts/profile_edit.html', context)
def profile_edit(request): if request.method == "POST": profile_form = ProfileForm(request.POST, files=request.FILES, instance=request.user.profile) user_form = MyUserForm(request.POST, instance=request.user) if profile_form.is_valid() and user_form.is_valid(): profile_form.save() user_form.save() return HttpResponseRedirect(reverse("accounts:profile_details")) else: profile_form = ProfileForm(instance=request.user.profile) user_form = MyUserForm(instance=request.user) context = {"user_form": user_form, "profile_form": profile_form} return render(request, "accounts/profile_edit.html", context)