def manage_user(request): if not request.user.is_authenticated(): return HttpResponseRedirect("/comptes/login") if request.method == "POST": form = EditUserForm(request.POST, instance=request.user) if form.is_valid(): form.save() address = form.cleaned_data.get("address") telephone = form.cleaned_data.get("telephone") message_connection = """Vos informations ont été sauvegardées. Voici les informations saisies:""" messages.success(request, message_connection) messages.info(request, "Adresse: " + address) messages.info(request, u"Numéro de téléphone: " + telephone) return HttpResponseRedirect('/comptes/manage') else: form = EditUserForm(instance=request.user) return render(request, 'manageuser.html', {'form': form })
def edit_client(request): form_client = EditClientForm(request.POST or None, instance = client_instance(request.user) ) form_user = EditUserForm(request.POST or None, instance= request.user) if request.method == 'POST': if form_client.is_valid() and form_user.is_valid(): form_user.save() form_client.save() messages.success(request, 'Datos actualizados correctamente') return render(request, 'client/edit.html', {'form_client' : form_client, 'form_user': form_user})
def user_edit(request,id): temp_name = "accounts/accounts-header.html" user = auth.get_user_model().objects.get(id=id) if request.method == 'POST': form = EditUserForm(request.POST,instance=user) if form.is_valid(): form.save() return redirect('user_list') else: form = EditUserForm(instance=user) return render(request, 'accounts/user_edit.html', locals())
def user_edit(request, ids): user = get_user_model().objects.get(id=ids) if request.method == 'POST': form = EditUserForm(request.POST, instance=user) if form.is_valid(): form.save() status = 1 else: status = 2 else: form = EditUserForm(instance=user) return render(request, 'accounts/user_edit.html', locals())
def user_edit(request, ids): user = get_user_model().objects.get(id=ids) if request.method == 'POST': form = EditUserForm(request.POST, instance=user) if form.is_valid(): form.save() status = 1 else: status = 2 else: form = EditUserForm(instance=user) return render(request, 'accounts/user_edit.html', locals())
def user_edit(request, ids): user = auth.get_user_model().objects.filter(id=ids).first() # print user.has_perm('accounts.add_userinfo') if request.method == 'POST': form = EditUserForm(request.POST, instance=user) if form.is_valid(): form.save() return render(request, 'response_con.html', {'msg': u'保存成功'}) return render(request, 'response_con.html', {'msg': form.errors}) else: form = EditUserForm(instance=user) return render(request, 'accounts/user_edit.html', locals())
def post(self, request): if request.POST['form-name'] == 'edit-user-form': add_email_form = AddEmailForm() edit_user_form = EditUserForm(request.POST, instance=request.user) if edit_user_form.is_valid(): edit_user_form.save() return redirect('/profile/') if request.POST['form-name'] == 'add-email-form': edit_user_form = EditUserForm(instance=request.user) add_email_form = AddEmailForm(request.POST) if add_email_form.is_valid(): add_email_form.save() return redirect('/profile/') page_title = 'Profile' return render_to_response('profile.html', locals(), context_instance=RequestContext(request))
def post(self, request): if request.POST['form-name'] == 'edit-user-form': add_email_form = AddEmailForm() edit_user_form = EditUserForm(request.POST, instance=request.user) if edit_user_form.is_valid(): edit_user_form.save() return redirect('/profile/') if request.POST['form-name'] == 'add-email-form': edit_user_form = EditUserForm(instance=request.user) add_email_form = AddEmailForm(request.POST) if add_email_form.is_valid(): add_email_form.save() return redirect('/profile/') page_title = 'Profile' return render_to_response('profile.html', locals(), context_instance=RequestContext(request))
def user_edit(request, pk, template_name='accounts/user_edit.html'): user = get_object_or_404(User, pk=pk) uid = pk print uid username = request.session['username'] permission = 'auth.change_user' if current_user_permissions(username, permission): form = EditUserForm(request.POST or None, instance=user) if form.is_valid(): form.save() return redirect('user_list') return render(request, template_name, { 'form': form, 'username': username, 'uid': pk }) else: return HttpResponse("权限不够")
def _update(request, pk): user = get_object_or_404(User, pk=pk) if user != request.user and not request.user.is_superuser: return HttpResponseForbidden() form = EditUserForm(request.POST) if form.is_valid(): updated_user = form.save() messages.success(request, "User edit successful.") return redirect(updated_user) return edit(request, pk, form)
def edit_profile(request): """Edit profile view.""" user = User.objects.get(pk=request.user.id) if request.method == 'POST': prof_form = EditProfileForm(request.POST, instance=user.profile) usr_form = EditUserForm(request.POST, instance=user) if prof_form.is_valid() and usr_form.is_valid(): prof_form.save() usr_form.save() return redirect("/accounts/profile") elif request.method == 'GET': profile_edit = EditProfileForm(instance=request.user.profile) user_edit = EditUserForm(instance=request.user) return render(request, 'profile_edit.html', context={ 'profile_edit': profile_edit, 'user_edit': user_edit })
def edit_user(request, org_url, user_id): organization = request.organization user = settings.AUTH_USER_MODEL.objects.get(id=user_id) form = EditUserForm(request.POST or None, instance=user) if form.is_valid(): form.save() return redirect( "set_organization_group", [org_url, "staff_group"] ) return render( request, "organizations/user_new.html", dict( form=form, org=organization, org_url=org_url, ) )
def user_edit(request, ids): user = get_user_model().objects.get(id=ids) if request.method == 'POST': form = EditUserForm(request.POST, instance=user) if form.is_valid(): form.save() status = 1 else: status = 3 else: form = EditUserForm(instance=user) # ids = ids # kwvars = { # 'ids': ids, # 'form': form, # 'request': request, # } return render_to_response('skaccounts/user_edit.html', locals(), RequestContext(request))
def user_profile(request, user_id=None, template="users/user_profile.html"): context = {} user = OperationsUser.objects.get(pk=user_id) if user_id else None user_form = EditUserForm(request.POST or None, instance=user) if u'save' in request.POST and user_form.is_valid(): user = user_form.save() next = request.POST.get('next', '/') return HttpResponseRedirect(next) if u'cancel' in request.POST: next = request.POST.get('next', '/') return HttpResponseRedirect(next) context['form'] = user_form context['user'] = user return render(request, template, context)