修改很多内容

pull/6/head
guanghongwei 10 years ago
parent 50fcac67c3
commit d32026013f

@ -8,6 +8,7 @@ urlpatterns = patterns('',
(r'^$', 'jumpserver.views.index'),
(r'^api/user/$', 'jumpserver.views.api_user'),
(r'^skin_config/$', 'jumpserver.views.skin_config'),
(r'^install/$', 'jumpserver.views.install'),
(r'^base/$', 'jumpserver.views.base'),
(r'^login/$', 'jumpserver.views.login'),
(r'^logout/$', 'jumpserver.views.logout'),

@ -297,4 +297,9 @@ else:
ldap_conn = None
def install(request):
from juser.models import DEPT
DEPT(id=1, name="璺ㄩ儴闂", comment="娣诲姞璺ㄩ儴闂ㄥ皬缁勪娇鐢").save()
DEPT(id=2, name="榛樿", comment="榛樿閮ㄩ棬锛屼綔涓轰腑闂达紝鍙互鐢ㄦ潵鍒濆鍖").save()
return HttpResponse('Ok')

@ -11,11 +11,13 @@ urlpatterns = patterns('juser.views',
(r'^dept_add/$', 'dept_add'),
(r'^dept_del/$', 'dept_del'),
(r'^dept_detail/$', 'dept_detail'),
(r'^dept_del_ajax/$', 'dept_del_ajax'),
(r'^dept_edit/$', 'dept_edit'),
(r'^group_add/$', 'group_add'),
(r'^group_list/$', 'group_list'),
(r'^group_detail/$', 'group_detail'),
(r'^group_del/$', 'group_del'),
(r'^group_del_ajax/$', 'group_del_ajax'),
(r'^group_edit/$', 'group_edit'),
(r'^user_add/$', 'user_add'),
(r'^user_list/$', 'user_list'),

@ -86,17 +86,6 @@ def db_add_group(**kwargs):
group_add_user(group, user_id)
def group_update_user(group_id, users_id):
group = UserGroup.objects.get(id=group_id)
group.user_set.clear()
for user_id in users_id:
user = User.objects.get(id=user_id)
group.user_set.add(user)
def db_add_user(**kwargs):
groups_post = kwargs.pop('groups')
user = User(**kwargs)
@ -261,7 +250,7 @@ def dept_list(request):
if keyword:
contact_list = DEPT.objects.filter(Q(name__icontains=keyword) | Q(comment__icontains=keyword)).order_by('name')
else:
contact_list = DEPT.objects.all()
contact_list = DEPT.objects.filter(id__gt=1)
p = paginator = Paginator(contact_list, 10)
try:
@ -291,7 +280,7 @@ def dept_detail(request):
def dept_del(request):
dept_id = request.GET.get('id', None)
if not dept_id:
if not dept_id or dept_id in ['1', '2']:
return HttpResponseRedirect('/juser/dept_list/')
dept = DEPT.objects.filter(id=dept_id)
if dept:
@ -307,6 +296,32 @@ def dept_member(dept_id):
return dept.user_set.all()
def dept_member_update(dept, users_id_list):
old_users = dept.user_set.all()
new_users = []
for user_id in users_id_list:
new_users.extend(User.objects.filter(id=user_id))
remove_user = [user for user in old_users if user not in new_users]
add_user = [user for user in new_users if user not in old_users]
for user in add_user:
user.dept = dept
user.save()
dept_default = DEPT.objects.get(id=2)
for user in remove_user:
user.dept = dept_default
user.save()
def dept_del_ajax(request):
dept_ids = request.POST.get('dept_ids')
for dept_id in dept_ids.split(','):
DEPT.objects.filter(id=dept_id).delete()
return HttpResponse("鍒犻櫎鎴愬姛")
def dept_edit(request):
header_title, path1, path2 = '閮ㄩ棬缂栬緫', '鐢ㄦ埛绠$悊', '閮ㄩ棬缂栬緫'
if request.method == 'GET':
@ -325,15 +340,16 @@ def dept_edit(request):
else:
dept_id = request.POST.get('id', '')
name = request.POST.get('name', '')
users = request.POST.get('users_selected', [])
users = request.POST.getlist('users_selected', [])
comment = request.POST.get('comment', '')
dept = DEPT.objects.filter(id=dept_id)
if dept:
dept.update(name=name, comment=comment)
dept_member_update(dept[0], users)
else:
error = '閮ㄩ棬涓嶅瓨鍦'
return HttpResponseRedirect('/juser/dept_list/')
return render_to_response('juser/dept_edit.html', locals(), context_instance=RequestContext(request))
@ -405,42 +421,58 @@ def group_detail(request):
def group_del(request):
group_id = request.GET.get('id', None)
group_id = request.GET.get('id', '')
if not group_id:
return HttpResponseRedirect('/')
group = UserGroup.objects.get(id=group_id)
group.delete()
return HttpResponseRedirect('/juser/group_list/', locals(), context_instance=RequestContext(request))
UserGroup.objects.filter(id=group_id).delete()
return HttpResponseRedirect('/juser/group_list/')
def group_del_ajax(request):
group_ids = request.POST.get('group_ids')
for group_id in group_ids.split(','):
UserGroup.objects.filter(id=group_id).delete()
return HttpResponse('鍒犻櫎鎴愬姛')
def group_update_member(group_id, users_id_list):
group = UserGroup.objects.filter(id=group_id)
if group:
group = group[0]
group.user_set.clear()
for user_id in users_id_list:
user = User.objects.get(id=user_id)
group.user_set.add(user)
def group_edit(request):
error = ''
msg = ''
header_title, path1, path2 = '淇敼灞炵粍 | Edit Group', 'juser', 'group_edit'
group_types = {
'M': '閮ㄩ棬',
'A': '鐢ㄦ埛缁',
}
if request.method == 'GET':
group_id = request.GET.get('id', None)
group = UserGroup.objects.get(id=group_id)
group_name = group.name
comment = group.comment
group_type = group.type
users_all = User.objects.all()
users_selected = group.user_set.all()
users = [user for user in users_all if user not in users_selected]
group_id = request.GET.get('id', '')
group = UserGroup.objects.filter(id=group_id)
if group:
group = group[0]
dept_all = DEPT.objects.all()
users_all = User.objects.all()
users_selected = group.user_set.all()
users = [user for user in users_all if user not in users_selected]
return render_to_response('juser/group_edit.html', locals(), context_instance=RequestContext(request))
else:
group_id = request.POST.get('group_id', None)
group_name = request.POST.get('group_name', None)
group_id = request.POST.get('group_id', '')
group_name = request.POST.get('group_name', '')
comment = request.POST.get('comment', '')
users_selected = request.POST.getlist('users_selected')
group_type = request.POST.get('group_type')
group = UserGroup.objects.filter(id=group_id)
group.update(name=group_name, comment=comment, type=group_type)
group_update_user(group_id, users_selected)
try:
if '' in [group_id, group_name]:
raise AddError('缁勫悕涓嶈兘涓虹┖')
UserGroup.objects.filter(id=group_id).update(name=group_name, comment=comment)
except AddError, e:
error = e
return HttpResponseRedirect('/juser/group_list/')

@ -30,8 +30,8 @@
<div class="ibox-content">
<div class="">
<a target="_blank" href="/juser/dept_add/" class="btn btn-sm btn-primary "> 娣诲姞 </a>
<a target="_blank" href="/juser/group_add/" class="btn btn-sm btn-danger "> 鍒犻櫎鎵閫 </a>
<a target="_blank" href="/juser/dept_add/" class="btn btn-sm btn-primary "> 娣诲姞閮ㄩ棬 </a>
<a id="del_btn" class="btn btn-sm btn-danger"> 鍒犻櫎鎵閫 </a>
<form id="search_form" method="get" action="" class="pull-right mail-search">
<div class="input-group">
<input type="text" class="form-control input-sm" id="search_input" name="search" placeholder="Search">
@ -121,6 +121,18 @@
<script>
$(document).ready(function(){
$(".iframe").colorbox({iframe:true, width:"70%", height:"70%"});
var check_array = []
$('#del_btn').click(function(){
$(".gradeX input:checked").each(function() {check_array.push($(this).attr("value")) })
$(".gradeX input:checked").closest("tr").remove()
$.post("/juser/dept_del_ajax/",
{dept_ids: check_array.join(",")},
function(data){
alert(data)
}
)
})
});
</script>

@ -1,5 +1,5 @@
{% extends 'base.html' %}
{% load mytags %}
{% block content %}
{% include 'nav_cat_bar.html' %}
<div class="wrapper wrapper-content animated fadeInRight">
@ -7,7 +7,7 @@
<div class="col-lg-10">
<div class="ibox float-e-margins">
<div class="ibox-title">
<h5>濉啓鍩烘湰淇℃伅 <small> Fill group info.</small></h5>
<h5>濉啓鍩烘湰淇℃伅</h5>
<div class="ibox-tools">
<a class="collapse-link">
<i class="fa fa-chevron-up"></i>
@ -37,16 +37,23 @@
<div class="form-group">
<label for="group_name" class="col-sm-2 control-label">缁勫悕<span class="red-fonts">*</span></label>
<div class="col-sm-8">
<input id="group_name" name="group_name" placeholder="Group name" type="text" class="form-control" value="{{ group_name }}">
<input id="group_id" name="group_id" type="text" class="form-control" value="{{ group.id }}" style="display: none">
<input name="group_id" type="text" class="form-control" value="{{ group.id }}">
<input id="group_name" name="group_name" placeholder="Group name" type="text" class="form-control" value="{{ group.name }}">
</div>
</div>
<div class="hr-line-dashed"></div>
<div class="form-group">
<label for="group_type" class="col-sm-2 control-label">绫诲瀷<span class="red-fonts">*</span></label>
<label for="dept_id" class="col-sm-2 control-label">閮ㄩ棬<span class="red-fonts">*</span></label>
<div class="col-sm-8">
<input class="form-control" value="{{ group_type|group_type_to_str }}" readonly>
<input name="group_type" class="form-control" id="group_type" value="{{ group_type }}" style="display: none">
<select id="dept_id" name="dept_id" class="form-control m-b">
{% for dept in dept_all %}
{% ifequal group.dept.id dept.id %}
<option value="{{ dept.id }}" selected>{{ dept.name }}</option>
{% else %}
<option value="{{ dept.id }}">{{ dept.name }}</option>
{% endifequal %}
{% endfor %}
</select>
</div>
</div>
<div class="hr-line-dashed"></div>
@ -68,9 +75,9 @@
<div class="col-sm-3">
<div>
<select id="users_selected" name="users_selected" class="form-control m-b" size="12" multiple>
{% for user in users_selected %}
<option value="{{ user.id }}">{{ user.name }}</option>
{% endfor %}
{% for user in users_selected %}
<option value="{{ user.id }}">{{ user.name }}</option>
{% endfor %}
</select>
</div>
</div>
@ -87,7 +94,7 @@
<div class="form-group">
<div class="col-sm-4 col-sm-offset-2">
<button class="btn btn-white" type="reset">鍙栨秷</button>
<button id="submit_button" class="btn btn-primary" type="submit">纭淇濆瓨</button>
<button id="submit_button" class="btn btn-primary" type="submit">纭淇濆瓨</button>
</div>
</div>
</form>
@ -120,9 +127,17 @@ $('#groupForm').validator({
}
});
$(document).ready(function() {
$("#submit_button").click(function () {
$('#users_selected option').each(function () {
function change_type(type){
$.post('/juser/group_add_ajax/',
{'type': type},
function(data){
$('#users').html(data)
})
}
$(document).ready(function(){
$("#submit_button").click(function(){
$('#users_selected option').each(function(){
$(this).prop('selected', true)
})
})

@ -30,9 +30,8 @@
<div class="ibox-content">
<div class="">
<a target="_blank" href="/juser/group_add/" class="btn btn-sm btn-primary "> 娣诲姞 </a>
<a target="_blank" href="/juser/group_add/" class="btn btn-sm btn-danger "> 鍒犻櫎鎵閫 </a>
<a target="_blank" href="/juser/group_add/" class="btn btn-sm btn-primary "> 娣诲姞灏忕粍 </a>
<a id="del_btn" class="btn btn-sm btn-danger "> 鍒犻櫎鎵閫 </a>
<form id="search_form" method="get" action="" class="pull-right mail-search">
<div class="input-group">
<input type="text" class="form-control input-sm" id="search_input" name="search" placeholder="Search">
@ -124,18 +123,20 @@
<script>
$(document).ready(function(){
$(".iframe").colorbox({iframe:true, width:"70%", height:"70%"});
var check_array = []
$('#del_btn').click(function(){
$(".gradeX input:checked").each(function() {check_array.push($(this).attr("value")) })
$(".gradeX input:checked").closest("tr").remove()
$.post("/juser/group_del_ajax/",
{group_ids: check_array.join(",")},
function(data){
alert(data)
}
)
})
});
{# function user_group_search(){#}
{# $.ajax({#}
{# type: "GET",#}
{# url: "/juser/group_search/",#}
{# data: $("#search_form").serialize(),#}
{# success: function (data) {#}
{# $("#contents_form").html(data);#}
{# }#}
{# });#}
{# }#}
</script>
{% endblock %}
Loading鈥
Cancel
Save