Skip to content

Commit

Permalink
所有历史工单展示
Browse files Browse the repository at this point in the history
  • Loading branch information
jly8866 committed Feb 20, 2017
1 parent 343a70d commit e63129f
Show file tree
Hide file tree
Showing 7 changed files with 131 additions and 132 deletions.
13 changes: 9 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,21 @@
* 工单DBA人工审核、sql执行
* 历史工单展示
* 回滚数据展示
* 提交工单发邮件功能
* OSC打通
* 主库集群配置
* 用户权限配置,工程师角色(engineer)与审核角色(review_man):工程师可以发起SQL上线,在通过了inception自动审核之后,需要由人工审核点击确认才能执行SQL
* 历史工单管理

### 安装步骤:
1. 安装python3:
tar -xzvf Python-3.4.1.tar.gz && cd Python-3.4.1 && ./configure --prefix=/path/to/python3 && make && make install
或者rpm、yum、binary等其他安装方式
2. 安装django:
tar -xzvf Django-1.8.17 && cd Django-1.8.17 && python3 setup.py install
3. 启动服务
bash startup.sh
3. 安装gunicorn
pip install gunicorn
4. 创建系统root用户(该用户可以使用django admin):
cd archer && python3 manage.py createsuperuser


10. 启动服务:
cd archer && bash startup.sh
7 changes: 6 additions & 1 deletion archer/settings.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# -*- coding: UTF-8 -*-

"""
Django settings for archer project.
Expand All @@ -23,7 +25,7 @@
SECRET_KEY = 'hfusaf2m4ot#7)fkw#di2bu6(cv0@opwmafx5n#6=3d%x^hpl6'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
DEBUG = False

ALLOWED_HOSTS = ['*']

Expand Down Expand Up @@ -77,6 +79,7 @@
# Database
# https://docs.djangoproject.com/en/1.8/ref/settings/#databases

#该项目本身的mysql数据库地址
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
Expand Down Expand Up @@ -108,9 +111,11 @@

STATIC_URL = '/static/'

#inception组件所在的地址
INCEPTION_HOST = '172.16.5.7'
INCEPTION_PORT = '6100'

#inception要备份数据到该远端mysql地址
INCEPTION_REMOTE_BACKUP_HOST='172.16.5.10'
INCEPTION_REMOTE_BACKUP_PORT=5621
INCEPTION_REMOTE_BACKUP_USER='inception'
Expand Down
3 changes: 3 additions & 0 deletions debug.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

python3 manage.py runserver 172.16.5.10:9123
180 changes: 61 additions & 119 deletions sql/static/allWorkflow.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,179 +2,121 @@

{% block content %}
<ul class="nav nav-tabs">
{% if navStatus == 'all' %}
<li class="active">
<a href="#">首页</a>
{% else %}
<li>
{% endif %}
<a href="/allworkflow/?pageNo=0&navStatus=all">全部工单</a>
</li>
<li>
<a href="#">简介</a>

{% if navStatus == 'waitingforme' %}
<li class="active">
{% else %}
<li>
{% endif %}
<a href="/allworkflow/?pageNo=0&navStatus=waitingforme">待我审核的</a>
</li>
<li class="disabled">
<a href="#">信息</a>

{% if navStatus == 'finish' %}
<li class="active">
{% else %}
<li>
{% endif %}
<a href="/allworkflow/?pageNo=0&navStatus=finish">已执行完毕</a>
</li>
<li class="dropdown pull-right">
<a href="#" data-toggle="dropdown" class="dropdown-toggle">下拉<strong class="caret"></strong></a>
<ul class="dropdown-menu">
<li>
<a href="#">操作</a>
</li>
<li>
<a href="#">设置栏目</a>
</li>
<li>
<a href="#">更多设置</a>
</li>
<li class="divider">
</li>
<li>
<a href="#">分割线</a>
</li>
</ul>

{% if navStatus == 'autoreviewwrong' %}
<li class="active">
{% else %}
<li>
{% endif %}
<a href="/allworkflow/?pageNo=0&navStatus=autoreviewwrong">自动审核不通过的</a>
</li>

</ul>
<table class="table table-striped table-hover">
<thead>
<tr>
<th>
编号
工单ID
</th>
<th>
产品
工单名称
</th>
<th>
交付时间
发起人
</th>
<th>
状态
工单状态
</th>
<th>
发起时间
</th>
<th>
目标集群
</th>
</tr>
</thead>
<tbody>
{% for workflow in listWorkflow %}
<tr>
<td>
1
</td>
<td>
TB - Monthly
</td>
<td>
01/04/2012
</td>
<td>
Default
</td>
</tr>
<!--<tr class="success">-->
<tr>
<td>
1
</td>
<td>
TB - Monthly
</td>
<td>
01/04/2012
</td>
<td>
Approved
</td>
</tr>
<!--<tr class="error">-->
<tr>
<td>
2
</td>
<td>
TB - Monthly
</td>
<td>
02/04/2012
</td>
<td>
Declined
</td>
</tr>
<tr>
<td>
3
{{workflow.id}}
</td>
<td>
TB - Monthly
<a href="/detail/{{workflow.id}}/">{{workflow.workflow_name}}</a>
</td>
<td>
03/04/2012
{{workflow.engineer}}
</td>
<td>
Pending
</td>
</tr>
<tr>
<td>
4
{{workflow.status}}
</td>
<td>
TB - Monthly
{{workflow.create_time}}
</td>
<td>
04/04/2012
</td>
<td>
Call in to confirm
{{workflow.cluster_name}}
</td>
</tr>
{% empty %}
<tr>
<td>
4
</td>
<td>
TB - Monthly
</td>
<td>
04/04/2012
</td>
<td>
Call in to confirm
</td>
</tr>
<tr>
<td>
4
</td>
<td>
TB - Monthly
</td>
<td>
04/04/2012
</td>
<td>
Call in to confirm
</td>
<td>当前状态暂无工单,嘿嘿嘿.</td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>

</tr>
{% endfor %}

</tbody>
</table>
<div style="text-align:center;">
<ul class="pagination" style="display:inline-block;">
<li>
<a href="#">前一页</a>
<a href="/allworkflow/?pageNo={{pageNo|add:"-1"}}&navStatus={{navStatus}}">前一页</a>
</li>
<li>
<a href="#">1</a>
<a href="/allworkflow/?pageNo={{pageNo|add:"0"}}&navStatus={{navStatus}}">{{pageNo|add:"1"}}</a>
</li>
<li>
<a href="#">2</a>
<a href="/allworkflow/?pageNo={{pageNo|add:"1"}}&navStatus={{navStatus}}">{{pageNo|add:"2"}}</a>
</li>
<li>
<a href="#">3</a>
<a href="/allworkflow/?pageNo={{pageNo|add:"2"}}&navStatus={{navStatus}}">{{pageNo|add:"3"}}</a>
</li>
<li>
<a href="#">4</a>
<a href="/allworkflow/?pageNo={{pageNo|add:"3"}}&navStatus={{navStatus}}">{{pageNo|add:"4"}}</a>
</li>
<li>
<a href="#">5</a>
<a href="/allworkflow/?pageNo={{pageNo|add:"4"}}&navStatus={{navStatus}}">{{pageNo|add:"5"}}</a>
</li>
<li>
<a href="#">后一页</a>
<a href="/allworkflow/?pageNo={{pageNo|add:"1"}}&navStatus={{navStatus}}">后一页</a>
</li>
</ul>
<button id="btnExecute" type="button" class="btn btn-primary btn-default" style="float:right;" data-loading-text="Loading...">执行操作</button>
</div>
{% endblock content%}
5 changes: 0 additions & 5 deletions sql/static/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1"> <span class="sr-only">Toggle navigation</span><span class="icon-bar"></span><span class="icon-bar"></span><span class="icon-bar"></span></button> <a class="navbar-brand" href="#"><strong>自动化运维平台</strong></a>
</div>
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<form class="navbar-form navbar-right" role="search">
<div class="form-group">
<input type="text" class="form-control" />
</div> <button type="submit" class="btn btn-default">搜索</button>
</form>
<ul class="nav navbar-nav navbar-right">
<li>
<a href="#">你好,{{loginUser}}</a>
Expand Down
53 changes: 51 additions & 2 deletions sql/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,58 @@ def authenticate(request):
result = {'status':1, 'msg':'用户名或密码错误,请重新输入!', 'data':''}
return HttpResponse(json.dumps(result), content_type='application/json')

#首页,也是查看所有SQL工单页面
#首页,也是查看所有SQL工单页面,具备翻页功能
def allworkflow(request):
context = {'currentMenu':'allworkflow'}
#一个页面展示
PAGE_LIMIT = 12

pageNo = 0
navStatus = ''
listAllWorkflow = []

#参数检查
if 'pageNo' in request.GET:
pageNo = request.GET['pageNo']
else:
pageNo = '0'

if 'navStatus' in request.GET:
navStatus = request.GET['navStatus']
else:
navStatus = 'all'
if not isinstance(pageNo, str) or not isinstance(navStatus, str):
raise TypeError('pageNo或navStatus页面传入参数不对')
else:
try:
pageNo = int(pageNo)
if pageNo < 0:
pageNo = 0
except ValueError as ve:
context = {'errMsg': 'pageNo参数不是int.'}
return render(request, 'error.html', context)

loginUser = request.session.get('login_username', False)
#查询workflow model,根据pageNo和navStatus获取对应的内容
offset = pageNo * PAGE_LIMIT
limit = offset + PAGE_LIMIT

listWorkflow = []
#查询全部流程
if navStatus == 'all':
#这句话等同于select * from sql_workflow order by create_time desc limit {offset, limit};
listWorkflow = workflow.objects.exclude(status=Const.workflowStatus['autoreviewwrong']).order_by('-create_time')[offset:limit]
elif navStatus == 'waitingforme':
listWorkflow = workflow.objects.filter(status=Const.workflowStatus['manreviewing'], review_man=loginUser).order_by('-create_time')[offset:limit]
elif navStatus == 'finish':
listWorkflow = workflow.objects.filter(status=Const.workflowStatus['finish']).order_by('-create_time')[offset:limit]
elif navStatus == 'autoreviewwrong':
listWorkflow = workflow.objects.filter(status=Const.workflowStatus['autoreviewwrong']).order_by('-create_time')[offset:limit]
else:
context = {'errMsg': '传入的navStatus参数有误!'}
return render(request, 'error.html', context)


context = {'currentMenu':'allworkflow', 'listWorkflow':listWorkflow, 'pageNo':pageNo, 'navStatus':navStatus}
return render(request, 'allWorkflow.html', context)

#提交SQL的页面
Expand Down
2 changes: 1 addition & 1 deletion startup.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/bash

python3 manage.py runserver 172.16.5.10:9123
gunicorn -w 2 --env DJANGO_SETTINGS_MODULE=archer.settings --error-logfile=/tmp/archer.err -b 192.168.1.12:8888 archer.wsgi:application

0 comments on commit e63129f

Please sign in to comment.