Skip to content

Commit

Permalink
upgrade to py3
Browse files Browse the repository at this point in the history
  • Loading branch information
lijie3721 committed Nov 25, 2016
1 parent 2f5b84d commit fc3cd31
Show file tree
Hide file tree
Showing 17 changed files with 647 additions and 22 deletions.
4 changes: 4 additions & 0 deletions CrazyEye/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,9 @@

url(r'^login/$',views.login,name='login'),
url(r'^accounts/profile/$',views.personal),
url(r'^configure/index/$',views.configure_index,name="table_index"),#显示所有注册的表
url(r'^configure/(\w+)/$',views.configure_url_dispatch,name="table_list"), #显示每个表的数据
url(r'^configure/(\w+)/change/(\d+)/$',views.table_change,name="table_change"),
url(r'^configure/(\w+)/add/$',views.table_add,name="table_add"),

]
7 changes: 7 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
cryptography==1.5.2
Django==1.10.2
django-session-security==2.4.0
djangorestframework==3.5.3
paramiko==2.0.2
pycparser==2.16
PyMySQL==0.7.9
1 change: 1 addition & 0 deletions statics/css/custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,4 @@
height: 300px;
overflow: auto;
}

18 changes: 18 additions & 0 deletions statics/js/king_admin/filter_horizontal.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* Created by alex on 11/24/16.
*/


//run this script before submit,to make sure all chosen options all selected
function CheckSelectedOptions() {
$("select[data-type='m2m_chosen'] option").prop("selected",true);
}


function ChoseAllOptions(from_select_ele_id,target_select_ele_id) {
console.log(from_select_ele_id +'--' + target_select_ele_id);
var from_options = $("#"+from_select_ele_id + " option");

console.log(from_options);
$("#" +target_select_ele_id).append(from_options);
}
11 changes: 7 additions & 4 deletions templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
<script src="/static/js/pace.min.js"></script>

{% endblock %}

{% block extra_head_resources %}{% endblock %}

</head>

Expand Down Expand Up @@ -153,9 +153,10 @@ <h1 class="page-header text-overflow">{% block page-title %}{% endblock %}</h1>
<!--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->
<!--End page title-->


{% block breadcrumb %} {% endblock %}
<!--Breadcrumb-->
<!--
<ol class="breadcrumb">
<li><a href="#">Home</a></li>
<li><a href="#">Library</a></li>
Expand Down Expand Up @@ -461,7 +462,7 @@ <h3 class="panel-title">近期危险操作统计</h3>
{% endif %}

<li>
<a href="/admin/" target="_blank">
<a href="{% url 'table_index' %}" >
<i class="fa fa-cog"></i>
<span class="menu-title">
配置
Expand Down Expand Up @@ -597,7 +598,7 @@ <h4 class="modal-title" id="myLargeModalLabel">当天登录用户</h4>

function SetActiveMenu(active_node){

//console.log("activ---enode:: " + active_node);
//console.log("active node:: " + active_node);
if (active_node == ''){
active_node = '/';
}
Expand All @@ -607,6 +608,8 @@ <h4 class="modal-title" id="myLargeModalLabel">当天登录用户</h4>
node_ele.parent().addClass("in");
}

//根本不需要上面这么麻烦,还需要后端返回 个当前menu,太low了
$("#mainnav-menu li").find("a[href='{{ request.path }}']").parent().addClass("active-link");
}

//for chart
Expand Down
69 changes: 69 additions & 0 deletions templates/king_admin/filter_horizontal_multi_select.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@

{% load custom_tag %}

<div class="col-md-5">
{# {% get_attr field %}#}
<p>可选 </p>
{% get_m2m_objs field.name form_obj.instance as m2m_objs %}
{% get_chosen_m2m_objs field form_obj.instance as chosen_m2m_objs %}


<select style="height: 200px" id="available_{{ field.name }}" multiple class="form-control ">
{% for obj in m2m_objs %}
{% if obj not in chosen_m2m_objs%}
<option value="{{ obj.id }}">{{ obj }}</option>
{% endif %}
{% endfor %}
</select>
<p class="btn-link" onclick="ChoseAllOptions('available_{{ field.name }}','id_{{ field.name }}')" align="center" style="cursor:pointer;font-weight:bold;margin-top:10px">
Choose all <i class="fa fa-chevron-circle-right" aria-hidden="true"></i>
</p>
</div>
<div class="col-md-1" align="center" style="margin-top: 35px">
<i class="fa fa-arrow-circle-left" aria-hidden="true"></i>
<br>
<i class="fa fa-arrow-circle-right" style="margin-left: -3px" aria-hidden="true"></i>

</div>
<div class="col-md-5">
<p>已选 </p>
<select data-type="m2m_chosen" style="height: 200px" multiple class="form-control" id="id_{{ field.name }}" name="{{ field.name }}" >
{% for obj in chosen_m2m_objs %}
<option value="{{ obj.id }}" selected>{{ obj }}</option>
{% endfor %}

</select>
<p class="btn-link" onclick="ChoseAllOptions('id_{{ field.name }}','available_{{ field.name }}')" align="center" style="cursor:pointer;font-weight:bold;margin-top:10px">
<i class="fa fa-chevron-circle-left" aria-hidden="true"></i>Remove all
</p>
</div>
<script>
document.getElementById("available_{{ field.name }}").addEventListener("dblclick", function (ele) {
moveClickedOption(ele,"id_{{ field.name }}");

});
document.getElementById("id_{{ field.name }}").addEventListener("dblclick", function (ele) {
moveClickedOption(ele,"available_{{ field.name }}");

});
document.getElementById("id_{{ field.name }}").addEventListener("click", function (ele) {
$(ele).preventDefault;

});
function moveClickedOption(ele,target_select_ele_id){
console.log("to target_select_ele: "+target_select_ele_id);
console.log(ele);
console.log(ele.srcElement.type);
if (ele.srcElement.type != 'select-multiple'){ //为避免当select里无option时,再点击会把select自己删除 掉

var clone_ele = $(ele)[0].srcElement;
$(ele)[0].srcElement.remove();
$("#" +target_select_ele_id ).append(clone_ele);
console.log(ele.srcElement.firstChild +ele.srcElement.value );

$("#id_{{ field.name }} option").prop("selected",true); //设定右边select的全为选 中状态
console.log($("#id_{{ field.name }} option")); //设定右边select的全为选 中状态
}

}
</script>
39 changes: 39 additions & 0 deletions templates/king_admin/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{% extends 'index.html' %}
{% load custom_tag %}
{% block breadcrumb %}
<ol class="breadcrumb">
<li class="active">配置中心</li>

</ol>
{% endblock %}
{% block page-content %}


<div class="row">

<div class="panel col-md-7">
<div class="panel-heading">
<h3 class="panel-title">配置中心</h3>
</div>

<div class="panel-body">
<table class="table table-hover table-vcenter">
{% for k,admin_class in enabled_admins.items %}

<tr>
<td><a style="font-weight:bold ;color: #447e9b" href="{% url 'table_list' k %}">{% get_db_table_name admin_class %}</a></td>
<td><a href="{% url 'table_add' k %}"><i style="color: green" class="fa fa-plus-square-o pull-right" aria-hidden="true">增加</i></a></td>
<td><a href="{% url 'table_list' k %}"><i style="color: red" class="fa fa-edit " aria-hidden="true">修改</i></a></td>

</tr>


{% endfor %}
</table>
</div>
</div>


</div>

{% endblock %}
74 changes: 74 additions & 0 deletions templates/king_admin/model_obj_list.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
{% extends 'index.html' %}
{% load custom_tag %}
{% block breadcrumb %}
<ol class="breadcrumb">
<li><a href="{% url 'table_index' %}">配置中心</a></li>
<li class="active"> {{ table_obj.model_verbose_name }}</li>
</ol>
{% endblock %}
{% block page-content %}

<div class="panel">
<div class="panel-heading">
<h3 class="panel-title">Select {{ table_obj.model_verbose_name }} to change</h3>
</div>
<div class="panel-body">
<div class="table-responsive">
<table class="table table-hover">
<thead>
<tr>
{% if table_obj.list_display %}
{% for column in table_obj.list_display %}
<th>{{ column }}</th>
{% endfor %}
{% else %}
<th>{{ table_obj }}</th>
{% endif %}
</tr>
</thead>
<tbody>
{% for row in table_obj.query_sets %}
<tr>
{% build_table_row row table_obj %}

</tr>
{% endfor %}
</tbody>
<footer>
<tr>
<td colspan="12" class="footable-visible">
<div class="pagination">

<nav>
<p>共{{ paginator.count }}条数据</p>
<ul class="pagination">
{% if table_obj.query_sets.has_previous %}
<li class="disabled">
<a href="{{ request.get_full_path }}?page={{ table_obj.query_sets.previous_page_number }}" aria-label="Previous"><span aria-hidden="true">&laquo;</span></a>
</li>
{% endif %}
{% for p_num in paginator.page_range %}
{% render_page_num request table_obj.query_sets p_num %}
{% endfor %}
{% if customer_list.has_next %}
<li>
<a href="{{ request.get_full_path }}?page={{ table_obj.query_sets.next_page_number }}" aria-label="Next">
<span aria-hidden="true">&raquo;</span>
</a>
</li>
{% endif %}
</ul>
</nav>

</div> <!--end pagination-->

</td>
</tr>
</footer>
</table>
</div>
</div>

</div>

{% endblock %}
60 changes: 60 additions & 0 deletions templates/king_admin/table_add.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
{% extends 'index.html' %}
{% load custom_tag %}
{% block breadcrumb %}
<ol class="breadcrumb">
<li><a href="{% url 'table_index' %}">配置中心</a></li>
<li><a href="{% url 'table_list' model_db_table %}">{{ model_name }}</a></li>
<li class="active"> 添加 {{ model_name }}</li>
</ol>
{% endblock %}

{% block page-content %}

<div class="panel">
<div class="panel-heading">
<h3 class="panel-title">Add {{ model_name }}</h3>
</div>

<form method="post" onsubmit="return CheckSelectedOptions()" class=" form-horizontal form-padding">{% csrf_token %}
<div class="panel-body">
{% for field in form_obj %}
<div class="form-group">
{%if field.field.required%}
<label class="col-md-2 control-label">
<b>{{field.label}}</b>
</label>
{% else %}
<label class="col-md-2 control-label">
{{field.label}}
</label>
{% endif %}
<div class="col-md-9">
{% if field.name not in admin_class.filter_horizontal %}
{{ field }}
{% if field.errors %}
<span style="color: red">{{ field.errors }}</span>
{% endif %}
{% else %}
{% include 'king_admin/filter_horizontal_multi_select.html' %}
{% endif %}
</div>
</div>
{% endfor %}
{{ form_obj.errors }}
</div> <!--end panel-body-->
<div class="panel-footer">
<div class="row">
<div class="col-sm-2 ">
<button class="btn btn-danger " type="reset">Delete</button>
</div>
<div class="col-sm-4 ">
<button class="btn btn-info pull-right " type="submit">Save</button>
</div>
</div>
</div>
</form>

</div>
<script src="/static/js/king_admin/filter_horizontal.js"></script>

{% endblock %}
Loading

0 comments on commit fc3cd31

Please sign in to comment.