def profileupdate(request): ## profile update form if request.method == 'POST' and 'profileupdate' in request.POST: profileform = ProfileUpdateForm(request.POST, request.FILES, instance=request.user) if profileform.is_valid(): profileform.save() messages.success(request, 'Profile details updated') return HttpResponseRedirect(reverse('profile-update')) else: profileform = ProfileUpdateForm(instance=request.user) ## password change form if request.method == 'POST' and 'passwordchange' in request.POST: passwordform = SetPasswordForm(request.user, request.POST) if passwordform.is_valid(): passwordform.save() messages.success(request, 'Password changed') return HttpResponseRedirect(reverse('profile-update') + '#body') else: passwordform = SetPasswordForm(request.user) return render(request, 'accounts/update.html', { 'profileform': profileform, 'passwordform': passwordform, })
def post(self): obj = User.query.filter(User.username==current_identity.username).first() update_form = ProfileUpdateForm(request.form, csrf_enabled=False) if update_form.validate(): update_form.save(obj) return {"status": "success, Profile updated!"} return update_form.errors
def put(self): data = ImmutableMultiDict(request.json) obj = User.query.filter(User.username==current_identity.username).first() update_form = ProfileUpdateForm(data, csrf_enabled=False) if update_form.validate(): profile = update_form.save(obj) return jsonify({"status": "success","data": BaseUserSerializer().dump(profile).data}) return update_form.errors