def test_not_user_name(self): """ユーザ名の空白で更新は不可能""" from users.forms import ProfileEditForm form_data = {'user_name': '', 'hobby': 'Programming'} form = ProfileEditForm(data=form_data) self.assertFalse(form.is_valid())
def edit_comment_sign_up(request, slug, comment_id): comment = get_object_or_404(PageComment, page__project__slug=slug, page__slug='sign-up', id=comment_id) if not comment.can_edit(request.user): return http.HttpResponseForbidden(_("You can't edit this comment")) abs_reply_to = comment while abs_reply_to.reply_to: abs_reply_to = abs_reply_to.reply_to if abs_reply_to == comment: abs_reply_to = reply_to = None else: reply_to = comment.reply_to preview = False profile = comment.author if request.method == 'POST': form = CommentForm(request.POST, instance=comment) profile_form = ProfileEditForm(request.POST, instance=profile) profile_image_form = ProfileImageForm() if form.is_valid() and (reply_to or profile_form.is_valid()): if not reply_to: profile = profile_form.save(commit=False) comment = form.save(commit=False) if 'show_preview' in request.POST: preview = True comment.content = bleach.clean(comment.content, tags=settings.RICH_ALLOWED_TAGS, attributes=settings.RICH_ALLOWED_ATTRIBUTES, styles=settings.RICH_ALLOWED_STYLES, strip=True) if not reply_to: profile.bio = bleach.clean(profile.bio, tags=settings.REDUCED_ALLOWED_TAGS, attributes=settings.REDUCED_ALLOWED_ATTRIBUTES, strip=True) else: if not reply_to: profile.save() comment.save() if reply_to: success_msg = _('Comment updated!') else: success_msg = _('Answer updated!') messages.success(request, success_msg) return http.HttpResponseRedirect(comment.get_absolute_url()) else: messages.error(request, _('Please correct errors bellow.')) else: profile_form = ProfileEditForm(instance=comment.author) profile_image_form = ProfileImageForm() form = CommentForm(instance=comment) return render_to_response('content/comment_sign_up.html', { 'profile_image_form': profile_image_form, 'profile_form': profile_form, 'profile': profile, 'form': form, 'project': comment.page.project, 'page': comment.page, 'reply_to': reply_to, 'comment': comment, 'preview': preview, }, context_instance=RequestContext(request))
def edit_answer_sign_up(request, slug, answer_id): sign_up = get_object_or_404(Signup, project__slug=slug) answer = get_object_or_404(sign_up.answers, id=answer_id) if not answer.can_edit(request.user): return http.HttpResponseForbidden(_("You can't edit this answer")) profile = answer.author if request.method == 'POST': form = SignupAnswerForm(request.POST, instance=answer) profile_form = ProfileEditForm(request.POST, instance=profile) profile_image_form = ProfileImageForm() if form.is_valid() and profile_form.is_valid(): profile = profile_form.save(commit=False) answer = form.save(commit=False) if 'show_preview' not in request.POST: profile.save() answer.save() messages.success(request, _('Answer updated!')) return http.HttpResponseRedirect(answer.get_absolute_url()) else: messages.error(request, _('Please correct errors below.')) else: profile_form = ProfileEditForm(instance=profile) profile_image_form = ProfileImageForm() form = SignupAnswerForm(instance=answer) return render_to_response('signups/answer_sign_up.html', { 'profile_image_form': profile_image_form, 'profile_form': profile_form, 'profile': profile, 'form': form, 'project': sign_up.project, 'sign_up': sign_up, 'answer': answer, 'preview': ('show_preview' in request.POST), }, context_instance=RequestContext(request))
def test_no_data(self): """データ無し""" from users.forms import ProfileEditForm form_data = {} form = ProfileEditForm(data=form_data) self.assertFalse(form.is_valid())
def test_with_user_name(self): """更新可能""" from users.forms import ProfileEditForm form_data = {'user_name': 'Taro-Tanaka', 'hobby': 'Programming'} form = ProfileEditForm(data=form_data) self.assertTrue(form.is_valid())
def sign_up(request, edit=False): if request.method == 'GET': if edit and request.user.is_authenticated(): form = ProfileEditForm(instance=request.user) else: form = SignUpForm() else: if edit and request.user.is_authenticated(): form = ProfileEditForm(request.POST, request.FILES, instance=request.user) if form.is_valid(): form.save() update_session_auth_hash(request, request.user) return HttpResponseRedirect('/') else: form = SignUpForm(request.POST, request.FILES) if form.is_valid(): form.save() return render(request, 'registration_success.html', { 'username': form.cleaned_data['username'] }) return render(request, 'sign_up.html', { 'form': form })
def get_dashboard_profile_edit(request): if request.method == "POST": user_form = UserEditForm(request.POST, instance=request.user) profile_form = ProfileEditForm(request.POST, request.FILES, instance=request.user.profile) if user_form.is_valid() and profile_form.is_valid(): user_form.save() profile_form.save() return redirect("profile") else: user_form = UserEditForm(instance=request.user) profile_form = ProfileEditForm(instance=request.user.profile) context = {"u_form": user_form, "p_form": profile_form} return render(request, "dashboard/profile_edit.html", context)
def edit_profile_view(request): if request.method == 'POST': user_form = UserEditForm(data=request.POST or None, instance=request.user) profile_form = ProfileEditForm(data=request.POST or None, instance=request.user.profile, files=request.FILES) if user_form.is_valid() and profile_form.is_valid(): user_form.save() profile_form.save() else: user_form = UserEditForm(instance=request.user) profile_form = ProfileEditForm(instance=request.user.profile) context = { 'user_form': user_form, 'profile_form': profile_form, } return render(request, 'users/users_form.html', context)
def edit_view(request): if request.method == 'POST': user_form = UserEditForm(instance=request.user, data=request.POST) profile_form = ProfileEditForm(instance=request.user.profile, data=request.POST, files=request.FILES) if user_form.is_valid() and profile_form.is_valid(): change_user = user_form.save(commit=False) change_user.save() profile = Profile.objects.get(user=change_user) avatar = request.FILES.get('photo') if avatar: profile.photo = avatar profile_form.save() return redirect('users:account') return request(request, 'edit.html', {'user_form': user_form, 'profile_form': profile_form}) else: user_form = UserEditForm(instance=request.user) profile_form = ProfileEditForm(instance=request.user.profile) return render(request, 'edit.html', {'user_form': user_form, 'profile_form': profile_form})
def edit_profile(request): user_form = UserEditForm(request.POST or None, instance=request.user) profile_form = ProfileEditForm( request.POST or None, files=request.FILES or None, instance=request.user.profile) if user_form.is_valid() and profile_form.is_valid(): user_form.save() profile_form.save() # автоматический вход после редактирования профиля user = authenticate( username=user_form.cleaned_data['username'], password=user_form.cleaned_data['password1']) login(request, user) return HttpResponseRedirect(reverse('edit_profile')) return render( request, 'account/profile_edit.html', {'user_form': user_form, 'profile_form': profile_form})
def edit_comment_sign_up(request, slug, comment_id): comment = get_object_or_404(PageComment, page__project__slug=slug, page__slug='sign-up', id=comment_id) if not comment.can_edit(request.user): return HttpResponseForbidden(_("You can't edit this comment")) abs_reply_to = comment while abs_reply_to.reply_to: abs_reply_to = abs_reply_to.reply_to if abs_reply_to == comment: abs_reply_to = reply_to = None else: reply_to = comment.reply_to if request.method == 'POST': form = CommentForm(request.POST, instance=comment) profile_form = ProfileEditForm(request.POST, instance=comment.author) profile_image_form = ProfileImageForm() if form.is_valid() and (reply_to or profile_form.is_valid()): if not reply_to: profile_form.save() form.save() success_msg = _('Comment updated!') if reply_to else _('Answer updated!') messages.success(request, success_msg) return HttpResponseRedirect(comment.get_absolute_url()) else: error_msg = _('There was a problem updating your comment. Comments cannot be empty. ') if reply_to \ else _('There was a problem updating your answer. Answers cannot be empty. ') messages.error(request, error_msg) else: profile_form = ProfileEditForm(instance=comment.author) profile_image_form = ProfileImageForm() form = CommentForm(instance=comment) return render_to_response('content/comment_sign_up.html', { 'profile_image_form': profile_image_form, 'profile_form': profile_form, 'profile': comment.author, 'form': form, 'project': comment.page.project, 'page': comment.page, 'reply_to': reply_to, 'comment': comment, }, context_instance=RequestContext(request))
def profile_edit_view(request, id=None): instance = get_object_or_404(User, id=id) form = ProfileEditForm(request.POST or None, request.FILES or None, instance=instance) # data = {} if request.is_ajax(): if form.is_valid(): instance = form.save(commit=False) if instance.avatar is True: instance.avatar = request.FILES['avatar'] form.save() # data['first_name'] = form.cleaned_data.get('first_name') # data['status'] = 'ok' # return JsonResponse({'status': 'success'}) return HttpResponse("Profile updated successfully") context = {'form': form, "instance": instance} template_name = "users/profile_edit.html" return render(request, template_name, context)
def edit_answer_sign_up(request, slug, answer_id): sign_up = get_object_or_404(Signup, project__slug=slug) answer = get_object_or_404(sign_up.answers, id=answer_id) if not answer.can_edit(request.user): return http.HttpResponseForbidden(_("You can't edit this answer")) profile = answer.author if request.method == "POST": form = SignupAnswerForm(request.POST, instance=answer) profile_form = ProfileEditForm(request.POST, instance=profile) profile_image_form = ProfileImageForm() if form.is_valid() and profile_form.is_valid(): profile = profile_form.save(commit=False) answer = form.save(commit=False) if "show_preview" not in request.POST: profile.save() answer.save() messages.success(request, _("Answer updated!")) return http.HttpResponseRedirect(answer.get_absolute_url()) else: messages.error(request, _("Please correct errors below.")) else: profile_form = ProfileEditForm(instance=profile) profile_image_form = ProfileImageForm() form = SignupAnswerForm(instance=answer) return render_to_response( "signups/answer_sign_up.html", { "profile_image_form": profile_image_form, "profile_form": profile_form, "profile": profile, "form": form, "project": sign_up.project, "sign_up": sign_up, "answer": answer, "preview": ("show_preview" in request.POST), }, context_instance=RequestContext(request), )
def comment_sign_up(request, slug, comment_id=None): page = get_object_or_404(Page, project__slug=slug, slug='sign-up') project = page.project user = request.user.get_profile() is_organizing = project.organizers().filter(user=user).exists() is_participating = project.participants().filter(user=user).exists() reply_to = abs_reply_to = None if comment_id: reply_to = page.comments.get(pk=comment_id) abs_reply_to = reply_to while abs_reply_to.reply_to: abs_reply_to = abs_reply_to.reply_to if not is_organizing: if is_participating: if not project.is_participating(abs_reply_to.author.user): return HttpResponseForbidden(_("You can't see this page")) elif abs_reply_to.author != user: return HttpResponseForbidden(_("You can't see this page")) elif project.signup_closed or is_organizing or is_participating: return HttpResponseForbidden(_("You can't see this page")) else: answers = page.comments.filter(reply_to__isnull=True, deleted=False, author=user) if answers.exists(): return HttpResponseForbidden(_("There exists already an answer")) if request.method == 'POST': form = CommentForm(request.POST) profile_form = ProfileEditForm(request.POST, instance=user) profile_image_form = ProfileImageForm() if form.is_valid() and (reply_to or profile_form.is_valid()): if not reply_to: profile_form.save() new_rel = Relationship(source=user, target_project=project) try: new_rel.save() except IntegrityError: pass comment = form.save(commit=False) comment.page = page comment.author = user comment.reply_to = reply_to comment.abs_reply_to = abs_reply_to comment.save() success_msg = _('Reply posted!') if reply_to else _('Answer submitted!') messages.success(request, success_msg) return HttpResponseRedirect(comment.get_absolute_url()) else: error_msg = _('There was a problem posting your reply. Reply cannot be empty. ') if reply_to \ else _('There was a problem submitting your answer. Answer cannot be empty. ') messages.error(request, error_msg) else: profile_form = ProfileEditForm(instance=user) profile_image_form = ProfileImageForm() form = CommentForm() return render_to_response('content/comment_sign_up.html', { 'profile_image_form': profile_image_form, 'profile_form': profile_form, 'profile': user, 'form': form, 'project': project, 'page': page, 'reply_to': reply_to, }, context_instance=RequestContext(request))
def answer_sign_up(request, slug): sign_up = get_object_or_404(Signup, project__slug=slug) project = sign_up.project profile = request.user.get_profile() is_organizing = project.organizers().filter(user=profile).exists() is_participating = project.participants().filter(user=profile).exists() if is_organizing or is_participating: messages.error(request, _("You already joined this %s.") % project.kind) return http.HttpResponseRedirect(sign_up.get_absolute_url()) elif sign_up.status == Signup.CLOSED: msg = _("Sign-up is currently closed." \ "You can clone the %s if is full.") messages.error(request, msg % project.kind) return http.HttpResponseRedirect(sign_up.get_absolute_url()) else: answers = sign_up.answers.filter(deleted=False, accepted=False, author=profile) if answers.exists(): messages.error(request, _("You already posted an answer to the signup questions.")) return http.HttpResponseRedirect(answers[0].get_absolute_url()) answer = None if request.method == 'POST': form = SignupAnswerForm(request.POST) profile_form = ProfileEditForm(request.POST, instance=profile) profile_image_form = ProfileImageForm() if form.is_valid() and profile_form.is_valid(): profile = profile_form.save() answer = form.save(commit=False) answer.sign_up = sign_up answer.author = profile if 'show_preview' not in request.POST: profile.save() new_rel, created = Relationship.objects.get_or_create( source=profile, target_project=project) new_rel.deleted = False new_rel.save() answer.save() if sign_up.status == Signup.NON_MODERATED: answer.accept() messages.success(request, _('You are now a participant!')) else: messages.success(request, _('Answer submitted!')) return http.HttpResponseRedirect(answer.get_absolute_url()) else: messages.error(request, _('Please correct errors below.')) else: profile_form = ProfileEditForm(instance=profile) profile_image_form = ProfileImageForm() form = SignupAnswerForm() return render_to_response('signups/answer_sign_up.html', { 'profile_image_form': profile_image_form, 'profile_form': profile_form, 'profile': profile, 'form': form, 'project': project, 'sign_up': sign_up, 'answer': answer, 'create': True, 'preview': ('show_preview' in request.POST), }, context_instance=RequestContext(request))
def comment_sign_up(request, slug, comment_id=None): page = get_object_or_404(Page, project__slug=slug, slug='sign-up') project = page.project profile = request.user.get_profile() is_organizing = project.organizers().filter(user=profile).exists() is_participating = project.participants().filter(user=profile).exists() reply_to = abs_reply_to = None if comment_id: reply_to = page.comments.get(pk=comment_id) abs_reply_to = reply_to while abs_reply_to.reply_to: abs_reply_to = abs_reply_to.reply_to if not is_organizing: if is_participating: if not project.is_participating(abs_reply_to.author.user): return http.HttpResponseForbidden( _("You can't see this page")) elif abs_reply_to.author != profile: return http.HttpResponseForbidden(_("You can't see this page")) elif project.signup_closed or is_organizing or is_participating: return http.HttpResponseForbidden(_("You can't see this page")) else: answers = page.comments.filter(reply_to__isnull=True, deleted=False, author=profile) if answers.exists(): return http.HttpResponseForbidden( _("There exists already an answer")) preview = False comment = None if request.method == 'POST': form = CommentForm(request.POST) profile_form = ProfileEditForm(request.POST, instance=profile) profile_image_form = ProfileImageForm() if form.is_valid() and (reply_to or profile_form.is_valid()): if not reply_to: profile = profile_form.save() comment = form.save(commit=False) comment.page = page comment.author = profile comment.reply_to = reply_to comment.abs_reply_to = abs_reply_to if 'show_preview' in request.POST: preview = True comment.content = bleach.clean(comment.content, tags=settings.RICH_ALLOWED_TAGS, attributes=settings.RICH_ALLOWED_ATTRIBUTES, styles=settings.RICH_ALLOWED_STYLES, strip=True) if not reply_to: profile.bio = bleach.clean(profile.bio, tags=settings.REDUCED_ALLOWED_TAGS, attributes=settings.REDUCED_ALLOWED_ATTRIBUTES, strip=True) else: if not reply_to: profile.save() new_rel, created = Relationship.objects.get_or_create( source=profile, target_project=project) new_rel.deleted = False new_rel.save() comment.save() if reply_to: success_msg = _('Reply posted!') else: success_msg = _('Answer submitted!') messages.success(request, success_msg) return http.HttpResponseRedirect(comment.get_absolute_url()) else: messages.error(request, _('Please correct errors bellow.')) else: profile_form = ProfileEditForm(instance=profile) profile_image_form = ProfileImageForm() form = CommentForm() return render_to_response('content/comment_sign_up.html', { 'profile_image_form': profile_image_form, 'profile_form': profile_form, 'profile': profile, 'form': form, 'project': project, 'page': page, 'reply_to': reply_to, 'comment': comment, 'create': True, 'preview': preview, }, context_instance=RequestContext(request))
def edit_comment_sign_up(request, slug, comment_id): comment = get_object_or_404(PageComment, page__project__slug=slug, page__slug='sign-up', id=comment_id) if not comment.can_edit(request.user): return http.HttpResponseForbidden(_("You can't edit this comment")) abs_reply_to = comment while abs_reply_to.reply_to: abs_reply_to = abs_reply_to.reply_to if abs_reply_to == comment: abs_reply_to = reply_to = None else: reply_to = comment.reply_to preview = False profile = comment.author if request.method == 'POST': form = CommentForm(request.POST, instance=comment) profile_form = ProfileEditForm(request.POST, instance=profile) profile_image_form = ProfileImageForm() if form.is_valid() and (reply_to or profile_form.is_valid()): if not reply_to: profile = profile_form.save(commit=False) comment = form.save(commit=False) if 'show_preview' in request.POST: preview = True comment.content = bleach.clean( comment.content, tags=settings.RICH_ALLOWED_TAGS, attributes=settings.RICH_ALLOWED_ATTRIBUTES, styles=settings.RICH_ALLOWED_STYLES, strip=True) if not reply_to: profile.bio = bleach.clean( profile.bio, tags=settings.REDUCED_ALLOWED_TAGS, attributes=settings.REDUCED_ALLOWED_ATTRIBUTES, strip=True) else: if not reply_to: profile.save() comment.save() if reply_to: success_msg = _('Comment updated!') else: success_msg = _('Answer updated!') messages.success(request, success_msg) return http.HttpResponseRedirect(comment.get_absolute_url()) else: messages.error(request, _('Please correct errors bellow.')) else: profile_form = ProfileEditForm(instance=comment.author) profile_image_form = ProfileImageForm() form = CommentForm(instance=comment) return render_to_response('content/comment_sign_up.html', { 'profile_image_form': profile_image_form, 'profile_form': profile_form, 'profile': profile, 'form': form, 'project': comment.page.project, 'page': comment.page, 'reply_to': reply_to, 'comment': comment, 'preview': preview, }, context_instance=RequestContext(request))
def comment_sign_up(request, slug, comment_id=None): page = get_object_or_404(Page, project__slug=slug, slug='sign-up') project = page.project profile = request.user.get_profile() is_organizing = project.organizers().filter(user=profile).exists() is_participating = project.participants().filter(user=profile).exists() reply_to = abs_reply_to = None if comment_id: reply_to = page.comments.get(pk=comment_id) abs_reply_to = reply_to while abs_reply_to.reply_to: abs_reply_to = abs_reply_to.reply_to if not is_organizing: if is_participating: if not project.is_participating(abs_reply_to.author.user): return http.HttpResponseForbidden( _("You can't see this page")) elif abs_reply_to.author != profile: return http.HttpResponseForbidden(_("You can't see this page")) elif project.signup_closed or is_organizing or is_participating: return http.HttpResponseForbidden(_("You can't see this page")) else: answers = page.comments.filter(reply_to__isnull=True, deleted=False, author=profile) if answers.exists(): return http.HttpResponseForbidden( _("There exists already an answer")) preview = False comment = None if request.method == 'POST': form = CommentForm(request.POST) profile_form = ProfileEditForm(request.POST, instance=profile) profile_image_form = ProfileImageForm() if form.is_valid() and (reply_to or profile_form.is_valid()): if not reply_to: profile = profile_form.save() comment = form.save(commit=False) comment.page = page comment.author = profile comment.reply_to = reply_to comment.abs_reply_to = abs_reply_to if 'show_preview' in request.POST: preview = True comment.content = bleach.clean( comment.content, tags=settings.RICH_ALLOWED_TAGS, attributes=settings.RICH_ALLOWED_ATTRIBUTES, styles=settings.RICH_ALLOWED_STYLES, strip=True) if not reply_to: profile.bio = bleach.clean( profile.bio, tags=settings.REDUCED_ALLOWED_TAGS, attributes=settings.REDUCED_ALLOWED_ATTRIBUTES, strip=True) else: if not reply_to: profile.save() new_rel, created = Relationship.objects.get_or_create( source=profile, target_project=project) new_rel.deleted = False new_rel.save() comment.save() if reply_to: success_msg = _('Reply posted!') else: success_msg = _('Answer submitted!') messages.success(request, success_msg) return http.HttpResponseRedirect(comment.get_absolute_url()) else: messages.error(request, _('Please correct errors bellow.')) else: profile_form = ProfileEditForm(instance=profile) profile_image_form = ProfileImageForm() form = CommentForm() return render_to_response('content/comment_sign_up.html', { 'profile_image_form': profile_image_form, 'profile_form': profile_form, 'profile': profile, 'form': form, 'project': project, 'page': page, 'reply_to': reply_to, 'comment': comment, 'create': True, 'preview': preview, }, context_instance=RequestContext(request))
def comment_sign_up(request, slug, comment_id=None): page = get_object_or_404(Page, project__slug=slug, slug='sign-up') project = page.project user = request.user.get_profile() reply_to = abs_reply_to = None if comment_id: reply_to = page.comments.get(pk=comment_id) abs_reply_to = reply_to while abs_reply_to.reply_to: abs_reply_to = abs_reply_to.reply_to elif project.signup_closed: return HttpResponseForbidden() if user != project.created_by: participants = project.participants() author = abs_reply_to.author if abs_reply_to else user if participants.filter(user=user).exists(): if author != project.created_by and not participants.filter(user=author).exists(): return HttpResponseForbidden() elif author != user: return HttpResponseForbidden() if request.method == 'POST': form = CommentForm(request.POST) profile_form = ProfileEditForm(request.POST, instance=user) profile_image_form = ProfileImageForm() if form.is_valid() and (reply_to or profile_form.is_valid()): if not reply_to: profile_form.save() new_rel = Relationship(source=user, target_project=project) try: new_rel.save() except IntegrityError: pass comment = form.save(commit=False) comment.page = page comment.author = user comment.reply_to = reply_to comment.abs_reply_to = abs_reply_to comment.save() success_msg = _('Reply posted!') if reply_to else _('Answer submitted!') messages.success(request, success_msg) return HttpResponseRedirect(reverse('page_show', kwargs={ 'slug': slug, 'page_slug': page.slug, })) else: error_msg = _('There was a problem posting your reply. Reply cannot be empty. ') if reply_to \ else _('There was a problem submitting your answer. Answer cannot be empty. ') messages.error(request, error_msg) else: profile_form = ProfileEditForm(instance=user) profile_image_form = ProfileImageForm() form = CommentForm() return render_to_response('content/comment_sign_up.html', { 'profile_image_form': profile_image_form, 'profile_form': profile_form, 'profile': user, 'form': form, 'project': project, 'page': page, 'reply_to': reply_to, }, context_instance=RequestContext(request))
def edit_user_profile(request): user = request.user if request.method == "POST": form = ProfileEditForm(request.POST) if form.is_valid(): cd = form.cleaned_data # Datos del usuario user.first_name = cd["first_name"] user.last_name = cd["last_name"] user.email = cd["email"] # Perfil try: profile = user.get_profile() profile.datosFacturacion.first_name = (cd["billing_first_name"],) profile.datosFacturacion.last_name = (cd["billing_last_name"],) profile.datosFacturacion.cif_nif = (cd["billing_cif"],) profile.datosFacturacion.city = (cd["billing_city"],) profile.datosFacturacion.address = (cd["billing_address"],) profile.datosFacturacion.province = (cd["billing_province"],) profile.datosFacturacion.country = cd["billing_country"] except UserProfile.DoesNotExist: datos_facturacion = DatosFacturacion.objects.create( first_name=cd["billing_first_name"], last_name=cd["billing_last_name"], cif_nif=cd["billing_cif"], city=cd["billing_city"], address=cd["billing_address"], province=cd["billing_province"], country=cd["billing_country"], ) profile = UserProfile.objects.create( user=user, website=cd["website"], datosFacturacion=datos_facturacion ) user.save() profile.save() return HttpResponseRedirect("/profile/") else: try: profile = user.get_profile() form = ProfileEditForm( initial={ "first_name": profile.user.first_name, "last_name": profile.user.last_name, "email": profile.user.email, "website": profile.website, "billing_first_name": profile.datosFacturacion.first_name, "billing_last_name": profile.datosFacturacion.last_name, "billing_cif": profile.datosFacturacion.cif_nif, "billing_city": profile.datosFacturacion.city, "billing_address": profile.datosFacturacion.address, "billing_province": profile.datosFacturacion.province, "billing_country": profile.datosFacturacion.country, } ) except UserProfile.DoesNotExist: userProfile = None form = ProfileEditForm( initial={"first_name": user.first_name, "last_name": user.last_name, "email": user.email} ) return render(request, "users/profile-edit.html", {"form": form, "username": user.username})