def user_edit(request, user_id): """编辑ss_user的信息""" ss_user = Suser.objects.get(user_id=user_id) # 当为post请求时,修改数据 if request.method == "POST": # 对总流量部分进行修改,转换单GB data = request.POST.copy() data["transfer_enable"] = int(eval(data["transfer_enable"]) * settings.GB) ssform = SuserForm(data, instance=ss_user) userform = UserForm(data, instance=ss_user.user) if ssform.is_valid() and userform.is_valid(): ssform.save() userform.save() # 修改账户密码 passwd = request.POST.get("resetpass") if len(passwd) > 0: user = ss_user.user user.set_password(passwd) user.save() messages.success(request, "数据更新成功", extra_tags="修改成功") return HttpResponseRedirect(reverse("sspanel:user_list")) else: messages.error(request, "数据填写错误", extra_tags="错误") context = {"ssform": ssform, "userform": userform, "ss_user": ss_user} return render(request, "backend/useredit.html", context=context) # 当请求不是post时,渲染form else: # 特别初始化总流量字段 data = {"transfer_enable": ss_user.transfer_enable // settings.GB} ssform = SuserForm(initial=data, instance=ss_user) userform = UserForm(instance=ss_user.user) context = {"ssform": ssform, "userform": userform, "ss_user": ss_user} return render(request, "backend/useredit.html", context=context)
def post(self, request, pk): user = User.get_by_pk(pk) form = UserForm(request.POST, instance=user) if form.is_valid(): form.save() messages.success(request, "数据更新成功", extra_tags="修改成功") return HttpResponseRedirect(reverse("sspanel:admin_user_list")) else: messages.error(request, "数据填写错误", extra_tags="错误") context = {"form": form, "user": user} return render(request, "my_admin/user_detail.html", context=context)
def User_edit(request, pk): '''编辑ss_user的信息''' ss_user = SSUser.objects.get(pk=pk) # 当为post请求时,修改数据 if request.method == "POST": # 对总流量部分进行修改,转换单GB data = request.POST.copy() data['transfer_enable'] = int( eval(data['transfer_enable']) * settings.GB) ssform = SSUserForm(data, instance=ss_user) userform = UserForm(data, instance=ss_user.user) if ssform.is_valid() and userform.is_valid(): ssform.save() userform.save() # 修改账户密码 passwd = request.POST.get('resetpass') if len(passwd) > 0: ss_user.user.set_password(passwd) ss_user.user.save() registerinfo = { 'title': '修改成功', 'subtitle': '数据更新成功', 'status': 'success', } request.session['registerinfo'] = registerinfo return redirect('/sspanel/backend/userlist/') else: registerinfo = { 'title': '错误', 'subtitle': '数据填写错误', 'status': 'error', } context = { 'ssform': ssform, 'userform': userform, 'registerinfo': registerinfo, 'ss_user': ss_user, } return render(request, 'backend/useredit.html', context=context) # 当请求不是post时,渲染form else: # 特别初始化总流量字段 data = {'transfer_enable': ss_user.transfer_enable // settings.GB} ssform = SSUserForm(initial=data, instance=ss_user) userform = UserForm(instance=ss_user.user) context = { 'ssform': ssform, 'userform': userform, 'ss_user': ss_user, } return render(request, 'backend/useredit.html', context=context)
def User_edit(request, pk): '''编辑ss_user的信息''' ss_user = SSUser.objects.get(pk=pk) # 当为post请求时,修改数据 if request.method == "POST": # 对总流量部分进行修改,转换单GB data = request.POST.copy() data['transfer_enable'] = int( eval(data['transfer_enable']) * settings.GB) ssform = SSUserForm(data, instance=ss_user) userform = UserForm(data, instance=ss_user.user) if ssform.is_valid() and userform.is_valid(): ssform.save() userform.save() # 修改账户密码 passwd = request.POST.get('resetpass') if len(passwd) > 0: ss_user.user.set_password(passwd) ss_user.user.save() messages.success(request, "数据更新成功", extra_tags="修改成功") return HttpResponseRedirect(reverse("sspanel:user_list")) else: messages.error(request, "数据填写错误", extra_tags="错误") context = { 'ssform': ssform, 'userform': userform, 'ss_user': ss_user, } return render(request, 'backend/useredit.html', context=context) # 当请求不是post时,渲染form else: # 特别初始化总流量字段 data = {'transfer_enable': ss_user.transfer_enable // settings.GB} ssform = SSUserForm(initial=data, instance=ss_user) userform = UserForm(instance=ss_user.user) context = { 'ssform': ssform, 'userform': userform, 'ss_user': ss_user, } return render(request, 'backend/useredit.html', context=context)
def User_edit(request, pk): '''编辑ss_user的信息''' ss_user = SSUser.objects.get(pk=pk) # 当为post请求时,修改数据 if request.method == "POST": # 对总流量部分进行修改,转换单GB data = request.POST.copy() data['transfer_enable'] = int(eval( data['transfer_enable']) * settings.GB) ssform = SSUserForm(data, instance=ss_user) userform = UserForm(data, instance=ss_user.user) if ssform.is_valid() and userform.is_valid(): ssform.save() userform.save() # 修改账户密码 passwd = request.POST.get('resetpass') if len(passwd) > 0: ss_user.user.set_password(passwd) ss_user.user.save() messages.success(request, "数据更新成功", extra_tags="修改成功") return HttpResponseRedirect(reverse("sspanel:user_list")) else: messages.error(request, "数据填写错误", extra_tags="错误") context = { 'ssform': ssform, 'userform': userform, 'ss_user': ss_user, } return render(request, 'backend/useredit.html', context=context) # 当请求不是post时,渲染form else: # 特别初始化总流量字段 data = {'transfer_enable': ss_user.transfer_enable // settings.GB} ssform = SSUserForm(initial=data, instance=ss_user) userform = UserForm(instance=ss_user.user) context = { 'ssform': ssform, 'userform': userform, 'ss_user': ss_user, } return render(request, 'backend/useredit.html', context=context)