def rolerightmanage(request): ''' 列表中查看,编辑,删除的处理 :param request: :return: ''' try: if utils.Is_GET(request) and utils.GetData(request, "action") == "view": id = request.GET.get("id") content["editable"] = False content["data"] = userRole.objects.get(id=id) userrole = userRole.objects.get(id=id) uright = userrole.role_right.all() return render_to_response(urlconfig.roleright, content) elif utils.Is_GET(request) and utils.GetData(request, "action") == "edit": rid = utils.GetData(request, 'rid') roleinfo = role_DAC.getRoleInfoByRoleId(uuid.UUID(rid)) pass elif utils.Is_GET(request) and utils.GetData(request, "action") == "delete": pass else: content["role"] = role_DAC.getRole() return render_to_response(urlconfig.rolerightmanage, content) except Exception as err: return render_to_response(urlconfig.rolemanage, content)
def supplierManage(request): ''' 供应商列表管理 :param request: :return: ''' id = utils.GetData(request, "id") if utils.Is_GET(request) and utils.GetData(request, "action") == "viewDatails": viewmodel = supplier_DAC.getDetailsObjectById(int(id)) jsonResult = dict( Id=viewmodel.Id, Sales=viewmodel.Sales, SalesPhone=viewmodel.salesPhone, Enginner=viewmodel.Enginner, EnginnerPhone=viewmodel.EnginnerPhone, SupplierName=viewmodel.SupplierName, SysType=viewmodel.SysType, Address=viewmodel.Address, ) return JsonResponse(jsonResult) elif utils.Is_GET(request) and utils.GetData(request, "action") == "delete": try: supplier_DAC.deleteSupplierById(int(id)) return JsonResponse({"Msg": "删除成功"}) except Exception as err: msg = {"Msg": "删除失败", "reson": err.message} return JsonResponse(msg)
def supportRecord(request): ''' 支持记录 :param request: :return: ''' if utils.Is_GET(request): result = supplier_DAC.getRecordViewModel() supportType = control.getSupportTypeDropDownList() dropDownList = control.getDropdownList() start, end, link, totalCount = sysRecordPagging(request) return render_to_response( urlconfig.record, { 'data': result[start:end], "dropDownListData": dropDownList, "dropDownList": dropDownList, "supportType": supportType, "link": link if totalCount > 10 else "" }) elif utils.Is_POST(request): if utils.IS_AJAX(request): recordViewModel = Record() recordViewModel.SupportUser = utils.GetData(request, "supportUser") recordViewModel.SupportContent = utils.GetData(request, "content") recordViewModel.SuportType = utils.GetData(request, "selectValue") try: supplier_DAC.createSupportRecord(recordViewModel) return JsonResponse({"MSG": "添加成功"}) except Exception as e: return JsonResponse({"MSG": "添加失败,原因如下:%s" % e.message})
def login(request): global content content.update(csrf(request)) if utils.Is_GET(request): return render_to_response(urlconfig.login, content) elif utils.Is_POST(request): username = GetData(request, "username") pwd = GetData(request, "password") pwd = gethashCode(request, pwd) try: userobj = user.objects.get(loginName=username, pwd=pwd) if userobj: request.session["user"] = userobj.username content["user"] = request.session["user"] #locals:返回一个包含当前作用域里面的所有变量和它们的值的字典 # print(locals()) #以下代码等价于return render_to_response(urlconfig.index,locals()) return render_to_response(urlconfig.index, content) except Exception as e: raise e #return render_to_response(urlconfig.login,content) return render_to_response(urlconfig.login, content)
def index(request): """ 供应商首页及分页以及防止重复数据提交 :return: """ page_id = '' stringLink = '' dropDownList = control.getDropdownList() if utils.Is_GET(request): page_id = str(uuid.uuid4()) request.session["pageid"] = page_id stringLink, start, end = supplier_utils.pagging(request) return render_to_response( urlconfig.index, { 'form': SupplierForm(), 'data': supplier_DAC.getAllSupplierInfo()[start:end], 'pageId': page_id, 'paging_link': stringLink, 'dropdownlist': dropDownList }) elif utils.Is_POST(request): if utils.GetData(request, 'hid') == request.session["pageid"]: form_p = SupplierForm(request.POST) if SupplierForm.is_valid: stringLink, start, end = supplier_utils.pagging(request) page_id = str(uuid.uuid4()) request.session["pageid"] = page_id form_p.save() return render_to_response( urlconfig.index, { 'form': SupplierForm(), 'data': supplier_DAC.getAllSupplierInfo()[start:end], 'pageId': page_id, 'paging_link': stringLink, 'dropdownlist': dropDownList }) else: page_id = str(uuid.uuid4()) request.session["pageid"] = page_id stringLink, start, end = supplier_utils.pagging(request) return render_to_response( urlconfig.index, { 'form': SupplierForm(), 'data': supplier_DAC.getAllSupplierInfo()[start:end], 'pageId': page_id, 'paging_link': stringLink, 'dropdownlist': dropDownList }) return render_to_response( urlconfig.index, { 'form': SupplierForm(), 'data': supplier_DAC.getAllSupplierInfo(), 'pageId': page_id })
def roleright(request): ''' 角色权限对应的多表查询(难点) :param request: :return: ''' if request.method == "POST": try: if request.POST.get("url"): role_right = Right() role_right.id = uuid.uuid4() role_right.url = request.POST.get("url") roleid = str(request.POST.get("roleid")) role_right.queryRight = 1 if request.POST.get( "queryright", None) == u"on" else 0 role_right.updateRight = 1 if request.POST.get( "updateright", None) == u"on" else 0 role_right.editRight = 1 if request.POST.get( "addright", None) == u"on" else 0 role_right.deleteRight = 1 if request.POST.get( "deleteright", None) == u"on" else 0 if roleid != "-1" and roleid is not None: #多对多表的处理添加数据 role = userRole.objects.get(id=roleid) role_right.save() role.role_right.add(role_right) return render_to_response(urlconfig.rolerightmanage, content) else: role_right.save() return render_to_response(urlconfig.rolerightmanage, content) except Exception as err: raise ValueError("获取url错误{0}", err.message) content["role"] = role_DAC.getRole() return render_to_response(urlconfig.right, content) else: if utils.Is_GET(request) and utils.GetData( request, "type") == "assignroleright": uinfo = user_DAC.getAllUserInfo() contentdata = [] data = {} for item in uinfo: urinfo = getRightByRoleId(request, item.id, item.usrRole_id) contentdata.append(urinfo) data["datacontent"] = contentdata return render_to_response(urlconfig.assignroleRight, data) return render_to_response(urlconfig.right, content)
def rolemanage(request): if utils.Is_GET(request): if utils.GetData(request, "type") == "addrole": return render_to_response(urlconfig.rolemanage) else: try: rolecode = request.POST.get("rolecode") rolename = request.POST.get("rolename") if rolecode and rolename: role = userRole() role.id = uuid.uuid4() role.role_desc = rolename role.role_code = rolecode role.save() except: raise ValueError("出错了") return rolerightmanage(request)
def sysTypeManage(request): supplierList = supplier_DAC.getSupplier() if utils.Is_GET(request): render_to_response(urlconfig.systype, {"data": supplierList}) elif utils.IS_AJAX(request): if utils.Is_POST(request): try: model = SupplierBusinessInfo() model.name = utils.GetData(request, "supplierName") model.bus_info_desc = utils.GetData(request, "bisType") model.bus_info_isCore = utils.GetData(request, "isCore") model.supplier_phone = utils.GetData(request, "Phone") model.Zip_code = utils.GetData(request, "zipCode") model.Address = utils.GetData(request, "address") model.Manager = utils.GetData(request, "manager") supplier_DAC.CreateSupplier(model) return JsonResponse({"msg": "创建成功"}) except Exception as e: return JsonResponse({"msg": "添加失败,原因如下:%s" % e.message}) return render_to_response(urlconfig.systype, {"data": supplierList})
def usermanage(request): global content if "saveuser" in request.session: del request.session["saveuser"] content.update(csrf(request)) if "data" in content: del content["data"] return render_to_response(urlconfig.usermanage, content) if utils.Is_GET(request) and utils.GetData(request, "action") == "mainview": uinfo = user_DAC.getAllUserInfo() for user in uinfo: roleinfo = userRole.objects.get(id=user.usrRole_id) user.roleName = roleinfo.role_desc content["data"] = uinfo return render_to_response(urlconfig.usermanage, content) elif utils.Is_GET(request) and utils.GetData(request, "action") == "adduser": content["role"] = role_DAC.getRole() return render_to_response(urlconfig.useradd, content) elif utils.Is_GET(request) and utils.GetData(request, "action") == "deletealluser": pass elif utils.Is_GET(request) and utils.GetData(request, "action") == "view": userid = utils.GetData(request, "uid") u_info = user_DAC.getUserinfoById(uuid.UUID(userid)) r_into = role_DAC.getRoleInfoByRoleId(u_info.usrRole_id) data = dict(username=u_info.username, usercode=u_info.usercode, loginname=u_info.loginName, roleName=r_into.role_desc) return JsonResponse(data) elif request.method == "GET" and request.GET.get("action") == "edit": userid = utils.GetData(request, "uid") u_info = user_DAC.delUserByUid(uuid.UUID(userid)) r_into = role_DAC.getRoleInfoByRoleId(u_info.usrRole_id) data = dict(username=u_info.username, usercode=u_info.usercode, loginname=u_info.loginName, roleName=r_into.role_desc, roleid=r_into.id) return JsonResponse(data) elif request.method == "GET" and request.GET.get("action") == "delete": userid = uuid.UUID(utils.GetData(request, "uid")) result = user_DAC.delUserByUid(userid) if result: msg = {"MSG": "删除成功"} else: msg = {"MSG": "删除失败"} return JsonResponse(result) if utils.Is_POST(request): try: from models import user userinfo = user() userinfo.id = uuid.uuid4() userinfo.loginName = request.POST.get("loginname", None) userinfo.usercode = request.POST.get("usercode", None) userinfo.username = request.POST.get("username", None) id = uuid.UUID(request.POST.get("roleid", None)) userinfo.usrRole = userRole.objects.get(id=id) m = hashlib.md5() userinfo.pwd = request.POST.get("pwd", None) if userinfo.pwd is not None: m.update(userinfo.pwd) userinfo.pwd = m.hexdigest() userinfo.save() request.session["saveuser"] = True return HttpResponseRedirect(actionconfig.usermanage) except Exception as err: raise err.message