def profile(request): """ 编辑账号 VIEW """ current_admin = get_current_admin(request) if not current_admin: jump_view = 'login' message = '对不起, 您还没有登陆' return render_to_response('error.html', locals()) pk_id = current_admin.id admin = Admin.objects.get(id=pk_id) org_role_id = admin.role_id if request.method == 'POST': form = ProfileEditForm(request.POST, instance=admin) if form.is_valid(): admin = form.save(commit=False) pwd = request.POST.get('pwd') if pwd: admin.pwd = md5(pwd) admin.save() form.save_m2m() return redirect('index') else: emg = u'账号: 修改个人信息失败' roles = Role.objects.all() return render_to_response('profile.html', locals(), request)
def index(request): current_admin = get_current_admin(request) project_count = eproject.objects.all().count() server_count = eserver.objects.all().count() # server_count = Server.objects.filter(projectenv__project__leader_id=current_admin.id).count() # auth_count = OsAuth.objects.filter(admin_id=current_admin.id).count() login_count = Admin.objects.get(id=current_admin.id).last_login_time return render_to_response('index.html', locals())
def index(request): current_admin = get_current_admin(request) project_count = eproject.objects.all().count() # 所有操作环境总数 server_count = eserver.objects.all().count() # 主机总数 # server_count = Server.objects.filter(projectenv__project__leader_id=current_admin.id).count() # auth_count = OsAuth.objects.filter(admin_id=current_admin.id).count() login_count = Admin.objects.get(id=current_admin.id).last_login_time opertop = OperationLog.objects.filter( admin_id=current_admin.id).order_by('-create_at')[0:5] if request.method == 'GET' and request.GET.get('data') == '1': msgS = OperationLog.objects.values_list('admin_name').annotate( Count('id')) data = {} ulist = [] vlist = {} tmp = [] for i in msgS: ulist.append(i[0]) data['categories'] = ulist for j in msgS: vlist['value'] = j[1] vlist['name'] = j[0] tmp.append(copy(vlist)) data['data'] = tmp # data = {'data': [ # {'value': 335, 'name': 'admin'}, # {'value': 310, 'name': 'tomcat'}, # {'value': 234, 'name': 'lili'}, # {'value': 135, 'name': 'guest'}, # {'value': 1548, 'name': 'timi'} # ], # 'categories': ['admin', 'tomcat', 'lili', 'guest', 'timi']} return JsonResponse(data) if request.method == 'GET' and request.GET.get('data') == '3': msgS = OperationLog.objects.values_list('ip').annotate(Count('id')) data3 = {} ulist = [] vlist = {} tmp = [] for i in msgS: ulist.append(i[0]) data3['categories'] = ulist for j in msgS: vlist['value'] = j[1] vlist['name'] = j[0] tmp.append(copy(vlist)) data3['data'] = tmp return JsonResponse(data3) return render_to_response('index.html', locals())
def check_privilege(request, view_name): # try: # privilege = Privilege.objects.get(view_func=view_name) # current_admin = get_current_admin(request) # privileges = current_admin.role.privileges.all() # # for item in privileges: # if privilege.id == item.id: # return True # except: # return False privilege = Privilege.objects.get(view_func=view_name) current_admin = get_current_admin(request) if current_admin.role.id == Role.ROLE_SUPPER: return True privileges = current_admin.role.privileges.filter( status=Privilege.STATUS_OPEN) for item in privileges: if privilege.id == item.id: return True return False
def get_current_admin_info(request): current_admin = get_current_admin(request) return current_admin