From 27d6df7a38dc3d3b040db4406b0684007fb9ccf7 Mon Sep 17 00:00:00 2001 From: halcyon <864072399@qq.com> Date: Tue, 21 Apr 2015 14:45:38 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E8=A7=A3=E5=86=B3django=E4=BD=8E=E7=89=88?= =?UTF-8?q?=E6=9C=AC=E4=B8=8D=E6=94=AF=E6=8C=81first()=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- jasset/views.py | 13 ++++++------- jlog/views.py | 4 ++-- jumpserver/api.py | 2 +- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/jasset/views.py b/jasset/views.py index a62aaca00..1e9fcb9ef 100644 --- a/jasset/views.py +++ b/jasset/views.py @@ -167,7 +167,7 @@ def db_idc_delete(request, idc_id): idc = IDC.objects.filter(id=idc_id) if idc: - idc_class = idc.first() + idc_class = idc[0] idc_class.asset_set.update(idc=default_idc) idc.delete() else: @@ -330,7 +330,7 @@ def host_edit_common_batch(request): asset_alias.save() else: AssetAlias.objects.create(user=u, host=a, alias=j_alias) - return my_render('jasset/host_list_common.html') + return my_render('jasset/host_list_common.html', locals(), request) @require_login @@ -539,7 +539,7 @@ def host_detail(request): post = Asset.objects.filter(id=host_id) if not post: return httperror(request, '没有此主机!') - post = post.first() + post = post[0] if is_group_admin(request) and not validate(request, asset=[host_id]): return httperror(request, '您无权查看!') @@ -697,7 +697,7 @@ def group_add(request): pass else: - j_dept = DEPT.objects.filter(id=j_dept).first() + j_dept = DEPT.objects.filter(id=j_dept)[0] group = BisGroup.objects.create(name=j_group, dept=j_dept, comment=j_comment) for host in j_hosts: g = Asset.objects.get(id=host) @@ -772,7 +772,7 @@ def group_edit(request): group_id = request.GET.get('id', '') group = BisGroup.objects.filter(id=group_id) if group: - group = group.first() + group = group[0] else: httperror(request, u'没有这个主机组!') @@ -918,10 +918,9 @@ def host_search(request): posts = post_all.filter(dept=dept) elif is_common_user(request): - username = get_session_user_info(request)[2] + user_id, username = get_session_user_info(request)[0:2] post_perm = user_perm_asset_api(username) posts = list(set(post_all) & set(post_perm)) - contact_list, p, contacts, page_range, current_page, show_first, show_end = pages(posts, request) return my_render('jasset/host_search.html', locals(), request) \ No newline at end of file diff --git a/jlog/views.py b/jlog/views.py index 85a937028..29fc3e38d 100644 --- a/jlog/views.py +++ b/jlog/views.py @@ -71,7 +71,7 @@ def log_kill(request): pid = request.GET.get('id', '') log = Log.objects.filter(pid=pid) if log: - log = log.first() + log = log[0] dept_name = log.dept_name deptname = get_session_user_info(request)[4] if is_group_admin(request) and dept_name != deptname: @@ -89,7 +89,7 @@ def log_history(request): log_id = request.GET.get('id', 0) log = Log.objects.filter(id=int(log_id)) if log: - log = log.first() + log = log[0] dept_name = log.dept_name deptname = get_session_user_info(request)[4] if is_group_admin(request) and dept_name != deptname: diff --git a/jumpserver/api.py b/jumpserver/api.py index 7c416925a..50461810e 100644 --- a/jumpserver/api.py +++ b/jumpserver/api.py @@ -254,7 +254,7 @@ def get_session_user_info(request): user_id = request.session.get('user_id', 0) user = User.objects.filter(id=user_id) if user: - user = user.first() + user = user[0] dept = user.dept return [user.id, user.username, user, dept.id, dept.name, dept] From b7aa1ab3dcdc3137d243b015998c7f871e7c557a Mon Sep 17 00:00:00 2001 From: halcyon <864072399@qq.com> Date: Wed, 22 Apr 2015 17:50:46 +0800 Subject: [PATCH 2/3] =?UTF-8?q?jperm=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- jperm/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jperm/views.py b/jperm/views.py index d6d6bf2c3..ed633a763 100644 --- a/jperm/views.py +++ b/jperm/views.py @@ -700,7 +700,7 @@ def perm_apply_exec(request): smg = '此权限已经审批完成, 请勿重复审批, 十秒钟后返回首页' return render_to_response('jperm/perm_apply_exec.html', locals(), context_instance=RequestContext(request)) else: - user = User.objects.get(username=q_apply.applyer) + user = User.objects.get(name=q_apply.applyer) mail_address = user.email time_now = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') p_apply.update(status=1, approver=approver, date_end=time_now) From 8a8f68d908823d1226c582158704578bacfb04d8 Mon Sep 17 00:00:00 2001 From: halcyon <864072399@qq.com> Date: Wed, 22 Apr 2015 18:04:23 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E4=BD=BF=E7=94=A8username=20=20=E5=8E=BB?= =?UTF-8?q?=E6=8E=89log=5Fha=E9=87=8C=E7=9A=84print?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- jperm/views.py | 4 ++-- log_handler.py | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/jperm/views.py b/jperm/views.py index ed633a763..57559444e 100644 --- a/jperm/views.py +++ b/jperm/views.py @@ -634,7 +634,7 @@ def perm_apply(request): """ 权限申请 """ header_title, path1, path2 = u'主机权限申请', u'权限管理', u'申请主机' user_id, username = get_session_user_info(request)[0:2] - name = User.objects.get(id=user_id).name + name = User.objects.get(id=user_id).username dept_id, deptname, dept = get_session_user_info(request)[3:6] perm_host = user_perm_asset_api(username) all_host = Asset.objects.filter(dept=dept) @@ -700,7 +700,7 @@ def perm_apply_exec(request): smg = '此权限已经审批完成, 请勿重复审批, 十秒钟后返回首页' return render_to_response('jperm/perm_apply_exec.html', locals(), context_instance=RequestContext(request)) else: - user = User.objects.get(name=q_apply.applyer) + user = User.objects.get(username=q_apply.applyer) mail_address = user.email time_now = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') p_apply.update(status=1, approver=approver, date_end=time_now) diff --git a/log_handler.py b/log_handler.py index 0d8b91e77..601237b0d 100755 --- a/log_handler.py +++ b/log_handler.py @@ -66,7 +66,6 @@ def run(): log_hanler(pid_id) for pid_id, pid, log_path, is_finished, log_finished, start_time in pids1: - print pid_id, start_time, type(start_time) try: file_time = int(os.stat(log_path).st_ctime) now_time = int(time.time())