Skip to content

Commit 33633ec

Browse files
committed
增加未完成任务提醒
1 parent b6f7bfd commit 33633ec

14 files changed

Lines changed: 99 additions & 107 deletions

File tree

-16 Bytes
Binary file not shown.

Ops/views.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
# -*- coding: utf-8 -*-
2-
import json
32
import random
43
from django.contrib import auth
54
from django.http import HttpResponseRedirect, HttpResponseForbidden, HttpResponse

assets/templatetags/custom_tags.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,16 @@ def intranet_ip(ip):
3030
@register.filter
3131
def get_file_name(name):
3232
return name.split('/')[-1]
33+
34+
35+
@register.filter
36+
def union_user_plan(self_plan, attention_plan):
37+
user_plans = self_plan | attention_plan
38+
plan_list = [user_plan for user_plan in user_plans if user_plan.status == 0]
39+
40+
return plan_list
41+
42+
43+
@register.filter
44+
def user_plan_count(plan_list):
45+
return len(plan_list)

assets/views.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ def server_facts(request):
179179
"password": CryptPwd().decrypt_pwd(server_obj.password)}]
180180

181181
try:
182-
ans = ANSRunner(resource)
182+
ans = ANSRunner(resource, become='yes', become_method='sudo', become_user='root')
183183
ans.run_module(host_list=[server_obj.assets.asset_management_ip], module_name=module, module_args="")
184184

185185
for data in ans.get_module_results:

logs/all.log

Lines changed: 10 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,10 @@
1-
INFO 2019-03-25 11:58:28 _log Connected (version 2.0, client OpenSSH_5.3)
2-
INFO 2019-03-25 11:58:28 _log Authentication (publickey) successful!
3-
INFO 2019-03-25 11:59:55 _log Connected (version 2.0, client OpenSSH_7.4)
4-
INFO 2019-03-25 11:59:56 _log Authentication (publickey) successful!
5-
INFO 2019-03-25 12:11:30 _log Connected (version 2.0, client OpenSSH_5.3)
6-
INFO 2019-03-25 12:11:30 _log Authentication (publickey) successful!
7-
INFO 2019-03-25 12:19:48 _log Connected (version 2.0, client OpenSSH_5.3)
8-
INFO 2019-03-25 12:19:48 _log Authentication (publickey) successful!
9-
INFO 2019-03-25 12:19:52 _log Connected (version 2.0, client OpenSSH_5.3)
10-
INFO 2019-03-25 12:19:52 _log Authentication (publickey) successful!
11-
INFO 2019-03-25 12:23:00 _log Connected (version 2.0, client OpenSSH_5.3)
12-
INFO 2019-03-25 12:23:00 _log Authentication (publickey) successful!
13-
INFO 2019-03-25 13:53:10 _log Connected (version 2.0, client OpenSSH_7.4)
14-
INFO 2019-03-25 13:53:10 _log Authentication (publickey) successful!
15-
INFO 2019-03-25 13:53:15 _log Connected (version 2.0, client OpenSSH_7.4)
16-
INFO 2019-03-25 13:53:15 _log Authentication (publickey) successful!
17-
INFO 2019-03-25 13:53:21 _log Connected (version 2.0, client OpenSSH_7.4)
18-
INFO 2019-03-25 13:53:21 _log Authentication (publickey) successful!
19-
INFO 2019-03-25 13:53:24 _log Connected (version 2.0, client OpenSSH_7.4)
20-
INFO 2019-03-25 13:53:24 _log Authentication (publickey) successful!
21-
INFO 2019-03-25 14:05:17 _log Connected (version 2.0, client OpenSSH_7.4)
22-
INFO 2019-03-25 14:05:17 _log Authentication (publickey) successful!
23-
INFO 2019-03-25 14:05:28 _log Connected (version 2.0, client OpenSSH_7.4)
24-
INFO 2019-03-25 14:05:28 _log Authentication (publickey) successful!
25-
INFO 2019-03-25 17:44:05 _log Connected (version 2.0, client OpenSSH_7.4)
26-
INFO 2019-03-25 17:44:05 _log Authentication (publickey) successful!
27-
INFO 2019-03-25 17:44:06 _log [chan 2] Opened sftp connection (server version 3)
28-
INFO 2019-03-25 17:44:09 _log [chan 2] sftp session closed.
29-
INFO 2019-03-25 17:45:49 _log Connected (version 2.0, client OpenSSH_7.4)
30-
INFO 2019-03-25 17:45:49 _log Authentication (publickey) successful!
31-
INFO 2019-03-25 17:45:49 _log Connected (version 2.0, client OpenSSH_5.3)
32-
INFO 2019-03-25 17:45:50 _log Authentication (publickey) successful!
33-
INFO 2019-03-25 17:45:50 _log [chan 2] Opened sftp connection (server version 3)
34-
INFO 2019-03-25 17:45:50 _log [chan 2] sftp session closed.
35-
INFO 2019-03-25 17:45:52 _log [chan 2] Opened sftp connection (server version 3)
36-
INFO 2019-03-25 17:45:54 _log [chan 2] sftp session closed.
37-
INFO 2019-03-26 10:23:05 _log Connected (version 2.0, client OpenSSH_7.4)
38-
INFO 2019-03-26 10:23:05 _log Authentication (publickey) successful!
39-
INFO 2019-03-26 10:23:21 _log Connected (version 2.0, client OpenSSH_7.4)
40-
INFO 2019-03-26 10:23:21 _log Authentication (publickey) successful!
1+
INFO 2019-04-01 16:36:27 _log Connected (version 2.0, client OpenSSH_7.4)
2+
INFO 2019-04-01 16:36:27 _log Authentication (publickey) successful!
3+
INFO 2019-04-01 16:36:27 _log [chan 2] Opened sftp connection (server version 3)
4+
INFO 2019-04-01 16:36:28 _log [chan 3] Opened sftp connection (server version 3)
5+
INFO 2019-04-01 16:36:28 _log [chan 3] sftp session closed.
6+
INFO 2019-04-01 17:20:53 _log Connected (version 2.0, client OpenSSH_7.4)
7+
INFO 2019-04-01 17:20:53 _log Authentication (publickey) successful!
8+
INFO 2019-04-01 17:20:54 _log [chan 2] Opened sftp connection (server version 3)
9+
INFO 2019-04-01 17:20:54 _log [chan 3] Opened sftp connection (server version 3)
10+
INFO 2019-04-01 17:20:54 _log [chan 3] sftp session closed.

task/utils/ansible_api_v2.py

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,11 @@ def v2_runner_on_unreachable(self, result):
4040
if 'msg' in result._result:
4141
data = '<code style="color: #FF0000">\n{host} | unreachable | rc={rc} >> \n{stdout}\n</code>'.format(
4242
host=result._host.name, rc=result._result.get('rc'),
43-
stdout=result._result.get('msg'))
43+
stdout=result._result.get('msg').encode().decode('utf-8'))
4444
else:
4545
data = '<code style="color: #FF0000">\n{host} | unreachable >> \n{stdout}\n</code>'.format(
4646
host=result._host.name,
47-
stdout=json.dumps(
48-
result._result,
49-
indent=4))
47+
stdout=json.dumps(result._result, indent=4))
5048
if self.sock:
5149
self.sock.send(data)
5250
self.module_results.append(data)
@@ -63,15 +61,11 @@ def v2_runner_on_ok(self, result, *args, **kwargs):
6361
elif 'module_stdout' in result._result and 'rc' in result._result:
6462
data = '<code style="color: #008000">\n{host} | success | rc={rc} >> \n{stdout}\n</code>'.format(
6563
host=result._host.name, rc=result._result.get('rc'),
66-
stdout=result._result.get(
67-
'module_stdout').encode().decode(
68-
'utf-8'))
64+
stdout=result._result.get('module_stdout').encode().decode('utf-8'))
6965
else:
7066
data = '<code style="color: #008000">\n{host} | success >> \n{stdout}\n</code>'.format(
7167
host=result._host.name,
72-
stdout=json.dumps(
73-
result._result,
74-
indent=4))
68+
stdout=json.dumps(result._result, indent=4))
7569
if self.sock:
7670
self.sock.send(data)
7771
self.module_results.append(data)
@@ -80,17 +74,17 @@ def v2_runner_on_failed(self, result, *args, **kwargs):
8074
if 'stderr' in result._result:
8175
data = '<code style="color: #FF0000">\n{host} | failed | rc={rc} >> \n{stdout}\n</code>'.format(
8276
host=result._host.name,
83-
rc=result._result.get(
84-
'rc'),
85-
stdout=result._result.get(
86-
'stderr').encode().decode(
87-
'utf-8'))
77+
rc=result._result.get('rc'),
78+
stdout=result._result.get('stderr').encode().decode('utf-8'))
79+
elif 'module_stdout' in result._result:
80+
data = '<code style="color: #FF0000">\n{host} | failed | rc={rc} >> \n{stdout}\n</code>'.format(
81+
host=result._host.name,
82+
rc=result._result.get('rc'),
83+
stdout=result._result.get('module_stdout').encode().decode('utf-8'))
8884
else:
8985
data = '<code style="color: #FF0000">\n{host} | failed >> \n{stdout}\n</code>'.format(
9086
host=result._host.name,
91-
stdout=json.dumps(
92-
result._result,
93-
indent=4))
87+
stdout=json.dumps(result._result, indent=4))
9488
if self.sock:
9589
self.sock.send(data)
9690
self.module_results.append(data)

templates/base.html

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{% load staticfiles %}
2+
{% load custom_tags %}
23
<!DOCTYPE html>
34
<!--
45
This is a starter template page. Use this page to start your new project from
@@ -93,6 +94,37 @@
9394
<div class="navbar-custom-menu">
9495
<ul class="nav navbar-nav">
9596
<!-- User Account Menu -->
97+
<li class="dropdown tasks-menu">
98+
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
99+
<i class="fa fa-flag-o"></i>
100+
<span class="label label-danger">{{ user.self_user.all|union_user_plan:user.attention_user.all|user_plan_count }}</span>
101+
</a>
102+
<ul class="dropdown-menu">
103+
<li class="header">
104+
你有 {{ user.self_user.all|union_user_plan:user.attention_user.all|user_plan_count }}
105+
个任务计划未完成
106+
</li>
107+
<li>
108+
<!-- inner menu: contains the actual data -->
109+
<ul class="menu">
110+
{% for foo in user.self_user.all|union_user_plan:user.attention_user.all %}
111+
<li><!-- Task item -->
112+
<a href="javascript:void(0)">
113+
<h3>
114+
{{ foo.title }}
115+
<small class="pull-right">
116+
截止日期:{{ foo.end_time|date:"Y-m-d H:i:s" }}</small>
117+
</h3>
118+
</a>
119+
</li>
120+
{% endfor %}
121+
</ul>
122+
</li>
123+
<li class="footer">
124+
<a href="{% url 'user_center' %}">查看所有</a>
125+
</li>
126+
</ul>
127+
</li>
96128
<li class="dropdown user user-menu">
97129
<!-- Menu Toggle Button -->
98130
<a href="#" class="dropdown-toggle" data-toggle="dropdown">

templates/users/base-layer.html

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@
1212
<link rel="stylesheet" href="{% static 'AdminLTE/bower_components/select2/dist/css/select2.min.css' %}">
1313
<link rel="stylesheet" href="{% static 'css/bootstrap-datetimepicker.min.css' %}">
1414
<link rel="stylesheet" href="{% static 'AdminLTE/dist/css/AdminLTE.min.css' %}">
15+
<link rel="stylesheet" href="{% static 'AdminLTE/plugins/iCheck/all.css' %}">
1516
<link rel="stylesheet" href="{% static 'jquery-confirm/dist/jquery-confirm.min.css' %}">
17+
{% block header %}
18+
19+
{% endblock %}
1620
</head>
1721

1822
<body>
@@ -23,6 +27,7 @@
2327
<script src="{% static 'layer/layer.js' %}"></script>
2428
<script src="{% static 'AdminLTE/bower_components/select2/dist/js/select2.full.min.js' %}"></script>
2529
<script src="{% static 'js/bootstrap-datetimepicker.js' %}"></script>
30+
<script src="{% static 'AdminLTE/plugins/iCheck/icheck.min.js' %}"></script>
2631

2732
<script type="text/javascript">
2833
$(function () {
@@ -41,6 +46,10 @@
4146
});
4247

4348
$(".select2").select2();
49+
50+
$('input[type="checkbox"].minimal').iCheck({
51+
checkboxClass: 'icheckbox_minimal-blue',
52+
})
4453
})
4554
</script>
4655

templates/users/create_plan.html

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -90,27 +90,6 @@
9090
window.location.reload();
9191

9292
});
93-
94-
/*input 时间输入选择*/
95-
$(".form_datetime").datetimepicker({
96-
language: 'zh',
97-
//minView: 'month',
98-
weekStart: 1,
99-
todayBtn: 1,
100-
autoclose: 1,
101-
todayHighlight: 1,
102-
startView: 2,
103-
forceParse: 0,
104-
//format: 'yyyy-mm-dd hh:ss'
105-
}).on('changeDate', function () {
106-
$(this).datetimepicker('hide');
107-
});
108-
109-
// select2
110-
$(function () {
111-
//Initialize Select2 Elements
112-
$(".select2").select2();
113-
});
11493
</script>
11594

11695
{% endblock %}

templates/users/plan_info.html

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{% extends 'users/base-layer.html' %}
22
{% load staticfiles %}
3+
34
{% block main %}
45
<div class="box box-danger">
56
<div class="box-header with-border">
@@ -68,6 +69,13 @@
6869
</div>
6970
<span><small class="text-danger margin-l-5">* 关注人可以查看本条内容</small></span>
7071
</div>
72+
73+
<div class="form-group has-feedback">
74+
<label class="col-sm-2 control-label" for="status">是否完成</label>
75+
<div class="col-sm-3" style="padding-top: 7px; margin-bottom: 0">
76+
<input type="checkbox" class="form-control pull-right minimal" name="status" id="status">
77+
</div>
78+
</div>
7179
</fieldset>
7280
</div>
7381
<div class="box-footer ">
@@ -88,8 +96,14 @@
8896
{% block javascripts %}
8997
<script src="{% static 'jquery-confirm/dist/jquery-confirm.min.js' %}"></script>
9098
<script type="text/javascript">
99+
$(function () {
100+
{% if user_plan.status == 1 %}
101+
$('#status').iCheck('check');
102+
{% endif %}
103+
});
91104
$("#btnSave").click(function () {
92105
let data = $("#addForm").serialize();
106+
93107
$.ajax({
94108
type: 'POST',
95109
url: "{% url 'plan_info' pk %}",
@@ -107,6 +121,7 @@
107121
}
108122
}
109123
});
124+
110125
});
111126

112127
$('#btnDelete').on('click', function () {
@@ -148,27 +163,6 @@
148163
window.location.reload();
149164

150165
});
151-
152-
/*input 时间输入选择*/
153-
$(".form_datetime").datetimepicker({
154-
language: 'zh',
155-
//minView: 'month',
156-
weekStart: 1,
157-
todayBtn: 1,
158-
autoclose: 1,
159-
todayHighlight: 1,
160-
startView: 2,
161-
forceParse: 0,
162-
//format: 'yyyy-mm-dd hh:ss'
163-
}).on('changeDate', function () {
164-
$(this).datetimepicker('hide');
165-
});
166-
167-
// select2
168-
$(function () {
169-
//Initialize Select2 Elements
170-
$(".select2").select2();
171-
});
172166
</script>
173167

174168
{% endblock %}

0 commit comments

Comments
 (0)