def delete(request): roleid = request.GET.get('roleid',0) if not roleid: return showmessage(request,"无法删除") try: Role.objects.get(roleid=roleid).delete() return showmessage(request,"角色删除成功",'/admin/role/init/',2000) except: return showmessage(request,"角色删除失败",'/admin/role/init/',2000)
def change_status(request): roleid = request.GET.get('roleid','') disabled = request.GET.get('disabled') catid = request.GET.get('catid') try: obj = Role.objects.get(roleid=roleid) obj.disabled = disabled obj.save() return showmessage(request,"操作成功","/admin/role/?catid=%s" % catid,2000) except: return showmessage(request,"操作失败","/admin/role/?catid=%s" % catid,2000)
def add(request): if request.method == "POST": rolename = request.POST.get('rolename') description = request.POST.get('description') disabled = request.POST.get('disabled',0) listorder = request.POST.get('listorder',0) try: Role.objects.create(rolename=rolename,description=description,disabled=disabled, listorder=listorder) return showmessage(request,"添加角色成功",'/admin/role/',2000) except: return showmessage(request,"添加角色失败",'/admin/role/',2000) else: return render_to_response('admin/role_add.html')
def role_priv(request): if request.method == "POST": info = dict(request.POST) Rinfo = '' if 'menuid[]' in info: Rinfo = info['menuid[]'] roleid = request.POST.get('roleid') siteid = request.POST.get('siteid') menuinfo = Menu.objects.all().values('id','m','a','c','data') list_info = {} for item in menuinfo: kid =item['id'] list_info[kid] = item M = Rolecat() if len(Rinfo) > 0: try: RolePriv.objects.filter(roleid=roleid,siteid=siteid).delete() except: print 'no data delete' pass for val in Rinfo: val = int(val) da = M.get_menuinfo(val,list_info) RolePriv.objects.create(roleid=roleid,m=da['m'],c=da['c'],a=da['a'],siteid=siteid, data=da['data'],menuid=da['id']) else: try: RolePriv.objects.filter(roleid=roleid,siteid=siteid).delete() except: pass return showmessage(request,"操作成功"); else: roleid = int(request.GET.get('roleid',0)) catid = request.GET.get('catid',0) rolearr = RolePriv.objects.filter(roleid=roleid) result = Menu.objects.all() m = Rolecat() menuarr =[] info = '' for item in result: listinfo = {} listinfo['id'] = item.id listinfo['parentid'] = item.parentid listinfo['name'] = item.name listinfo['checked'] = m.is_checked(item,roleid,1,rolearr); listinfo['parentid_node'] = "class='child-of-node-%s'" % item.parentid if item.parentid else '' listinfo['level'] = m.get_level(item.id,result); menuarr.append(listinfo) t = Tree() t.icon = ('│ ','├─ ','└─ ') t.nbsp = ' ' t.arr = menuarr info = t.get_tree2(0,'') siteid = request.GET.get('siteid','') return render_to_response('admin/role_priv.html',{'plist':info,'siteid':siteid, 'roleid':roleid,'catid':catid})
def edit(request): if request.method == "POST": roleid = request.POST.get('roleid','') rolename = request.POST.get('rolename') description = request.POST.get('description') disabled = request.POST.get('disabled',0) listorder = request.POST.get('listorder') try: obj = Role.objects.get(roleid=roleid) obj.rolename = rolename obj.description = description obj.disabled = disabled obj.listorder = listorder obj.save() return showmessage(request,"角色编辑成功",'/admin/role/',2000) except: return showmessage(request,"角色编辑失败",'/admin/role/',2000) else: roleid = request.GET.get('roleid','') try: info = Role.objects.get(roleid=roleid) return render_to_response('admin/role_edit.html',{'info':info}) except: return showmessage(request,"参数错误,无法操作")
def listorder(request): listorder = request.POST arr = dict(listorder) catid = request.GET.get('catid') for item in arr: if item != 'dosubmit': roleid = item.replace('listorders-','') order = arr[item][0] try: obj = Role.objects.get(roleid=roleid) obj.listorder = order obj.save() except: pass return showmessage(request,"已成功排序",'/admin/role/init/?catid=%s' % catid,3000)