def profile_edit(request): """ GET: show profile edit form with current data POST: validate and store new data """ from profiles.forms import ProfileEditForm profile = get404(UserProfile, user=request.user) if request.method == 'POST': form = ProfileEditForm(request.POST) if form.is_valid(): user = request.user user.first_name = form.cleaned_data['first_name'] user.last_name = form.cleaned_data['last_name'] up = UserProfile.objects.get(user=user) up.country = form.cleaned_data['country'] up.state = form.cleaned_data['state'] up.about = form.cleaned_data['about'] user.save() up.save() messages.success(request, 'Perfil actualizado satisfactoriamente') return HttpResponseRedirect(reverse('my-profile')) else: context = {'status_message': form.errors} return HttpResponse(status=400, content=simplejson.dumps(context)) data = { 'first_name': request.user.first_name, 'last_name': request.user.last_name, 'email': request.user.email, 'country': profile.country, 'about': profile.about, 'state': profile.state, } context = {'form': ProfileEditForm(data)} return Render('profile_edit.html', RequestContext(request, context))
def edit_profile(id=None): user = User.objects.get(id=id) profile = Profile.objects.get(id=user.profile.id) form = ProfileEditForm(instance=profile) return {'form': form}