def user_reset_password(request, pk): """ 重置密码 :param request: :return: """ origin_url = reverse("rbac:rbac_user_list") # 定义需要返回的地址 前端可以通过此地址跳转 obj = models.UserInfo.objects.filter(id=pk).first() # 数据是否存在 if not obj: return HttpResponse('用户不存在!') # 如果不存在,返回错误信息 if request.method == 'GET': form = ResetPasswordUserModelForm() return render(request, 'rbac/user_change.html/', { 'form': form, "cancel": origin_url }) form = ResetPasswordUserModelForm( instance=obj, data=request.POST) # POST表示修改了 一定要加instance=obj 否则就是增加了 if form.is_valid(): # 验证信息 form.save() return redirect(reverse("rbac:rbac_user_list")) # 成功后返回列表页面 return render(request, 'rbac/user_change.html/', { 'form': form, "cancel": origin_url }) # 否则返回错误信息
def user_reset_pwd(request, pk): """重置密码""" obj = models.UserInfo.objects.filter(id=pk).first() if not obj: return HttpResponse('用户不存在') if request.method == 'GET': form = ResetPasswordUserModelForm() return render(request, 'rbac/user_add.html', context=locals()) form = ResetPasswordUserModelForm(instance=obj, data=request.POST) if form.is_valid(): form.save() return redirect(reverse('rbac:user_list')) return render(request, 'rbac/user_add.html', context=locals())
def user_reset_pwd(request, pk): """ 重置密码 :param request: :return: """ obj = models.UserInfo.objects.filter(id=pk).first() if not obj: return HttpResponse("用户不存在") if request.method == "GET": form = ResetPasswordUserModelForm() return render(request, 'rbac/change.html', {'form': form}) form = ResetPasswordUserModelForm(instance=obj, data=request.POST) if form.is_valid(): form.save() return redirect(reverse('rbac:user_list')) return render(request, 'rbac/change.html', {'form': form})
def reset_password(request, pk): user_obj = models.UserInfo.objects.filter(pk=pk).first() if not user_obj: return HttpResponse('请先选择用户,再操作!') if request.method == 'GET': form = ResetPasswordUserModelForm() return render(request, 'rbac/change.html', {'form': form}) form = ResetPasswordUserModelForm(instance=user_obj, data=request.POST) if form.is_valid(): form.save() return redirect(urls.memory_reverse(request, 'rbac:user_list')) return render(request, 'rbac/change.html', {'form': form})
def user_reset_pwd(request, id): """ 重置用户密码功能视图函数 :param request: :param id: :return: """ obj = models.UserInfo.objects.filter(uid=id).first() if not obj: return render(request, 'rbac/user_error.html') if request.method == 'GET': form = ResetPasswordUserModelForm() return render(request, 'rbac/change.html', {'form': form}) form = ResetPasswordUserModelForm(instance=obj, data=request.POST) if form.is_valid(): form.save() return redirect(reverse("user_list")) return render(request, 'rbac/change.html', {'form': form})
def user_reset_pwd(request, uid): """ 重置用户密码 :param request: :param uid: 用户id :return: """ user = UserInfo.objects.filter(id=uid).first() if not user: return HttpResponse('数据不存在') if request.method == 'GET': form = ResetPasswordUserModelForm(instance=user) return render(request, 'rbac/change.html', {'form': form}) form = ResetPasswordUserModelForm(instance=user, data=request.POST) if form.is_valid(): form.save() return redirect(reverse('rbac:user-list')) return render(request, 'rbac/change.html', {'form': form})
def user_reset_pwd(request, pk): ''' 重置密码 :param request: :return: ''' obj = models.UserInfo.objects.filter(id=pk).first() if not obj: return HttpResponse('用户不存在') if request.method == 'GET': form = ResetPasswordUserModelForm() #密码字段去掉默认值,去掉instance=obj return render(request, 'rbac/change.html', {'form': form}) #访问http://127.0.0.1:8000/rbac/role/edit/1/, 表单中有默认值 form = ResetPasswordUserModelForm(instance=obj, data=request.POST) #data=request.POST 表示提交过来的数据 if form.is_valid(): form.save() return redirect(reverse('rbac:user_list')) return render(request, 'rbac/change.html', {'form': form })
def user_reset_pwd(request, pk): """ 重置密码 :param request: :param pk: :return: """ obj = models.UserInfo.objects.filter(id=pk).first() if not obj: return HttpResponse('用户不存在') if request.method == 'GET': form = ResetPasswordUserModelForm() return render( request, 'rbac/change.html', { 'form': form, "users": request.session["show_permission"].get("user_name"), "rest_password": request.session.get("rest_password"), "user_edit_href": request.session.get("user_edit_href"), "queryset_count": request.session.get("queryset_count"), "queryset_count_all": request.session.get('queryset_count_all') }) form = ResetPasswordUserModelForm(instance=obj, data=request.POST) if form.is_valid(): form.save() return redirect(reverse('rbac:user_list')) return render( request, 'rbac/change.html', { 'form': form, "users": request.session["show_permission"].get("user_name"), "rest_password": request.session.get("rest_password"), "user_edit_href": request.session.get("user_edit_href"), "queryset_count": request.session.get("queryset_count"), "queryset_count_all": request.session.get('queryset_count_all') })