mirror of https://github.com/jumpserver/jumpserver
解决分页问题
parent
546393d9c3
commit
475501595e
|
@ -5,8 +5,7 @@ from jasset.models import Asset, BisGroup
|
|||
|
||||
class Perm(models.Model):
|
||||
user_group = models.ForeignKey(UserGroup)
|
||||
asset_group = models.ManyToManyField(BisGroup)
|
||||
comment = models.CharField(max_length=100)
|
||||
asset_group = models.ForeignKey(BisGroup)
|
||||
|
||||
def __unicode__(self):
|
||||
return '%s_%s' % (self.user_group.name, self.asset_group.name)
|
||||
|
|
|
@ -122,47 +122,40 @@ def dept_perm_list(request):
|
|||
return render_to_response('jperm/dept_perm_list.html', locals(), context_instance=RequestContext(request))
|
||||
|
||||
|
||||
def perm_group_update(perm_id, user_group_id_list, asset_groups_id_list):
|
||||
perm = Perm.objects.filter(id=perm_id)
|
||||
if perm:
|
||||
perm = perm[0]
|
||||
user_group_list = []
|
||||
asset_group_list = []
|
||||
|
||||
for user_group_id in user_group_id_list:
|
||||
user_group_list.extend(UserGroup.objects.filter(id=user_group_id))
|
||||
def perm_group_update(user_group_id, asset_groups_id_list):
|
||||
user_group = UserGroup.objects.filter(id=user_group_id)
|
||||
if user_group:
|
||||
user_group = user_group[0]
|
||||
old_asset_group = [perm.asset_group for perm in user_group.perm_set.all()]
|
||||
new_asset_group = []
|
||||
|
||||
for asset_group_id in asset_groups_id_list:
|
||||
asset_group_list.extend(BisGroup.objects.filter(id=asset_group_id))
|
||||
new_asset_group.extend(BisGroup.objects.filter(id=asset_group_id))
|
||||
|
||||
perm.user_group.clear()
|
||||
perm.asset_group.clear()
|
||||
perm.user_group = user_group_list
|
||||
perm.asset_group = asset_group_list
|
||||
del_asset_group = [asset_group for asset_group in old_asset_group if asset_group not in new_asset_group]
|
||||
add_asset_group = [asset_group for asset_group in new_asset_group if asset_group not in old_asset_group]
|
||||
|
||||
for asset_group in del_asset_group:
|
||||
Perm.objects.filter(user_group=user_group, asset_group=asset_group).delete()
|
||||
|
||||
for asset_group in add_asset_group:
|
||||
Perm(user_group=user_group, asset_group=asset_group).save()
|
||||
|
||||
|
||||
def perm_edit(request):
|
||||
if request.method == 'GET':
|
||||
header_title, path1, path2 = u'缂栬緫鎺堟潈', u'鎺堟潈绠$悊', u'鎺堟潈缂栬緫'
|
||||
perm_id = request.GET.get('id', '')
|
||||
perm = Perm.objects.filter(id=perm_id)
|
||||
if perm:
|
||||
perm = perm[0]
|
||||
name = perm.name
|
||||
comment = perm.comment
|
||||
user_groups_select = perm.user_group.all()
|
||||
asset_groups_select = perm.asset_group.all()
|
||||
|
||||
user_groups_all = UserGroup.objects.all()
|
||||
user_group_id = request.GET.get('id', '')
|
||||
user_group = UserGroup.objects.filter(id=user_group_id)
|
||||
if user_group:
|
||||
user_group = user_group[0]
|
||||
asset_groups_all = BisGroup.objects.all()
|
||||
|
||||
user_groups = [user_group for user_group in user_groups_all if user_group not in user_groups_select]
|
||||
asset_groups_select = [perm.asset_group for perm in user_group.perm_set.all()]
|
||||
asset_groups = [asset_group for asset_group in asset_groups_all if asset_group not in asset_groups_select]
|
||||
else:
|
||||
perm_id = request.POST.get('perm_id', '')
|
||||
user_group_id_list = request.POST.getlist('user_groups_select')
|
||||
user_group_id = request.POST.get('user_group_id')
|
||||
asset_group_id_list = request.POST.getlist('asset_groups_select')
|
||||
perm_group_update(perm_id, user_group_id_list, asset_group_id_list)
|
||||
perm_group_update(user_group_id, asset_group_id_list)
|
||||
|
||||
return HttpResponseRedirect('/jperm/perm_list/')
|
||||
return render_to_response('jperm/perm_edit.html', locals(), context_instance=RequestContext(request))
|
||||
|
|
|
@ -108,6 +108,27 @@ def dept_perm_count(dept_id):
|
|||
return 0
|
||||
|
||||
|
||||
@register.filter(name='ugrp_perm_agrp_count')
|
||||
def ugrp_perm_agrp_count(user_group_id):
|
||||
user_group = UserGroup.objects.filter(id=user_group_id)
|
||||
if user_group:
|
||||
user_group = user_group[0]
|
||||
return user_group.perm_set.all().count()
|
||||
return 0
|
||||
|
||||
|
||||
@register.filter(name='ugrp_perm_asset_count')
|
||||
def ugrp_perm_asset_count(user_group_id):
|
||||
user_group = UserGroup.objects.filter(id=user_group_id)
|
||||
assets = []
|
||||
if user_group:
|
||||
user_group = user_group[0]
|
||||
asset_groups = [perm.asset_group for perm in user_group.perm_set.all()]
|
||||
for asset_group in asset_groups:
|
||||
assets.extend(asset_group.asset_set.all())
|
||||
return len(set(assets))
|
||||
|
||||
|
||||
@register.filter(name='group_type_to_str')
|
||||
def group_type_to_str(type_name):
|
||||
group_types = {
|
||||
|
|
|
@ -20,7 +20,7 @@ urlpatterns = patterns('juser.views',
|
|||
(r'^group_del_ajax/$', 'group_del_ajax'),
|
||||
(r'^group_edit/$', 'group_edit'),
|
||||
(r'^user_add/$', 'user_add'),
|
||||
(r'^user_list/$', 'user_list'),
|
||||
(r'^user_list/(?P<option>\w*)/?$', 'user_list'),
|
||||
(r'^user_detail/$', 'user_detail'),
|
||||
(r'^user_del/$', 'user_del'),
|
||||
(r'^user_del_ajax/$', 'user_del_ajax'),
|
||||
|
|
|
@ -502,14 +502,31 @@ def user_add(request):
|
|||
return render_to_response('juser/user_add.html', locals(), context_instance=RequestContext(request))
|
||||
|
||||
|
||||
def user_list(request):
|
||||
def user_list(request, option=""):
|
||||
user_role = {'SU': u'瓒呯骇绠$悊鍛', 'GA': u'缁勭鐞嗗憳', 'CU': u'鏅氱敤鎴'}
|
||||
header_title, path1, path2 = '鏌ョ湅鐢ㄦ埛', '鐢ㄦ埛绠$悊', '鐢ㄦ埛鍒楄〃'
|
||||
keyword = request.GET.get('search', '')
|
||||
if keyword:
|
||||
keyword = request.GET.get('keyword', '')
|
||||
gid = request.GET.get('gid', '')
|
||||
did = request.GET.get('did', '')
|
||||
if option == "search":
|
||||
contact_list = User.objects.filter(Q(username__icontains=keyword) | Q(name__icontains=keyword)).order_by('name')
|
||||
elif option == "group":
|
||||
user_group = UserGroup.objects.filter(id=gid)
|
||||
if user_group:
|
||||
user_group = user_group[0]
|
||||
contact_list = user_group.user_set.all().order_by('name')
|
||||
else:
|
||||
contact_list = []
|
||||
elif option == "dept":
|
||||
dept = DEPT.objects.filter(id=did)
|
||||
if dept:
|
||||
dept = dept[0]
|
||||
contact_list = dept.user_set.all().order_by('name')
|
||||
else:
|
||||
contact_list = []
|
||||
else:
|
||||
contact_list = User.objects.all().order_by('id')
|
||||
print option
|
||||
contact_list = User.objects.all().order_by('name')
|
||||
|
||||
contact_list, p, contacts, page_range, current_page, show_first, show_end = pages(contact_list, request)
|
||||
|
||||
|
|
|
@ -48,8 +48,8 @@
|
|||
<tr>
|
||||
|
||||
<th class="text-center">閮ㄩ棬鍚嶇О</th>
|
||||
<th class="text-center">閮ㄩ棬鎴愬憳鏁閲</th>
|
||||
<th class="text-center">鎺堟潈涓绘満鏁閲</th>
|
||||
<th class="text-center">閮ㄩ棬鎴愬憳鏁鐩</th>
|
||||
<th class="text-center">鎺堟潈涓绘満鏁鐩</th>
|
||||
<th class="text-center">澶囨敞</th>
|
||||
<th class="text-center">鎿嶄綔</th>
|
||||
</tr>
|
||||
|
@ -63,7 +63,7 @@
|
|||
<td class="text-center"> {{ dept.comment }} </td>
|
||||
<td class="text-center">
|
||||
<a title="[ {{ dept.name }} ] 鎴愬憳淇℃伅" href="../dept_detail/?id={{ dept.id }}" class="iframe btn btn-xs btn-primary">涓绘満</a>
|
||||
<a href="../dept_perm_edit/?id={{ dept.id }}" class="btn btn-xs btn-info">鎺堟潈缂栬緫</a>
|
||||
<a href="../dept_perm_edit/?id={{ dept.id }}" class="btn btn-xs btn-danger">鎺堟潈缂栬緫</a>
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
|
|
|
@ -38,43 +38,10 @@
|
|||
{% endif %}
|
||||
<div class="row">
|
||||
<div class="form-group">
|
||||
<label for="name" class="col-sm-2 control-label">鎺堟潈鍚<span class="red-fonts">*</span></label>
|
||||
<div class="col-sm-8">
|
||||
<input id="name" name="name" placeholder="鎺堟潈鍚嶇О" type="text" class="form-control" value="{{ name }}">
|
||||
<input id="perm_id" name="perm_id" style="display: none" value="{{ perm.id }}">
|
||||
<span class="help-block m-b-none">鍙栦釜鍚嶅瓧鏂逛究杈ㄨ瘑</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="hr-line-dashed"></div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="" class="col-sm-2 control-label">鐢ㄦ埛缁<span class="red-fonts">*</span></label>
|
||||
<label for="" class="col-sm-2 control-label">灏忕粍<span class="red-fonts">*</span></label>
|
||||
<div class="col-sm-4">
|
||||
<div>
|
||||
<select id="user_groups" name="user_groups" class="form-control" size="5" multiple>
|
||||
{% for user_group in user_groups %}
|
||||
<option value="{{ user_group.id }}">{{ user_group.name }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="col-sm-1">
|
||||
<div class="btn-group" style="margin-top: 12px;">
|
||||
<button type="button" class="btn btn-white" onclick="move('user_groups', 'user_groups_select')"><i class="fa fa-chevron-right"></i></button>
|
||||
<button type="button" class="btn btn-white" onclick="move('user_groups_select', 'user_groups')"><i class="fa fa-chevron-left"></i> </button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-sm-3">
|
||||
<div>
|
||||
<select id="user_groups_select" name="user_groups_select" class="form-control m-b" size="5" multiple>
|
||||
{% for user_group in user_groups_select %}
|
||||
<option value="{{ user_group.id }}">{{ user_group.name }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
<input id="user_group_id" name="user_group_id"type="text" value="{{ user_group.id }}" style="display: none">
|
||||
<input id="user_group_name" name="user_group_name" type="text" class="form-control" value="{{ user_group.name }}" readonly>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
@ -84,7 +51,7 @@
|
|||
<label for="" class="col-sm-2 control-label">涓绘満缁<span class="red-fonts">*</span></label>
|
||||
<div class="col-sm-4">
|
||||
<div>
|
||||
<select id="asset_groups" name="asset_groups" class="form-control m-b" size="5" multiple>
|
||||
<select id="asset_groups" name="asset_groups" class="form-control m-b" size="12" multiple>
|
||||
{% for asset_group in asset_groups %}
|
||||
<option value="{{ asset_group.id }}">{{ asset_group.name }}</option>
|
||||
{% endfor %}
|
||||
|
@ -93,7 +60,7 @@
|
|||
</div>
|
||||
|
||||
<div class="col-sm-1">
|
||||
<div class="btn-group" style="margin-top: 12px;">
|
||||
<div class="btn-group" style="margin-top: 42px;">
|
||||
<button type="button" class="btn btn-white" onclick="move('asset_groups', 'asset_groups_select')"><i class="fa fa-chevron-right"></i></button>
|
||||
<button type="button" class="btn btn-white" onclick="move('asset_groups_select', 'asset_groups')"><i class="fa fa-chevron-left"></i> </button>
|
||||
</div>
|
||||
|
@ -101,7 +68,7 @@
|
|||
|
||||
<div class="col-sm-3">
|
||||
<div>
|
||||
<select id="asset_groups_select" name="asset_groups_select" class="form-control m-b" size="5" multiple>
|
||||
<select id="asset_groups_select" name="asset_groups_select" class="form-control m-b" size="12" multiple>
|
||||
{% for asset_group in asset_groups_select %}
|
||||
<option value="{{ asset_group.id }}">{{ asset_group.name }}</option>
|
||||
{% endfor %}
|
||||
|
@ -109,16 +76,7 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="hr-line-dashed"></div>
|
||||
<div class="form-group">
|
||||
<label for="group_name" class="col-sm-2 control-label">澶囨敞</label>
|
||||
<div class="col-sm-8">
|
||||
<input id="comment" name="comment" placeholder="澶囨敞璇存槑" type="text" class="form-control" value="{{ comment }}">
|
||||
</div>
|
||||
</div>
|
||||
<div class="hr-line-dashed"></div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="form-group">
|
||||
|
|
|
@ -48,9 +48,9 @@
|
|||
<tr>
|
||||
<th class="text-center">缁勫悕</th>
|
||||
<th class="text-center">鎵灞為儴闂</th>
|
||||
<th class="text-center">鎴愬憳鏁閲</th>
|
||||
<th class="text-center">鎺堟潈缁勬暟閲</th>
|
||||
<th class="text-center">鎺堟潈涓绘満鏁閲</th>
|
||||
<th class="text-center">鎴愬憳鏁鐩</th>
|
||||
<th class="text-center">鎺堟潈涓绘満缁勬暟鐩</th>
|
||||
<th class="text-center">鎺堟潈涓绘満鏁鐩</th>
|
||||
<th class="text-center">澶囨敞</th>
|
||||
<th class="text-center">鎿嶄綔</th>
|
||||
</tr>
|
||||
|
@ -61,12 +61,13 @@
|
|||
<td class="text-center"> {{ group.name }} </td>
|
||||
<td class="text-center"> {{ group.dept.name }} </td>
|
||||
<td class="text-center"> {{ group.id | member_count }} </td>
|
||||
<td class="text-center"> {{ group.id | member_count }} </td>
|
||||
<td class="text-center"> {{ group.id | member_count }} </td>
|
||||
<td class="text-center"> {{ group.id | ugrp_perm_agrp_count }} </td>
|
||||
<td class="text-center"> {{ group.id | ugrp_perm_asset_count }} </td>
|
||||
<td class="text-center"> {{ group.comment }} </td>
|
||||
<td class="text-center">
|
||||
<a href="../perm_edit/?id={{ group.id }}" class="btn btn-xs btn-info">鎺堟潈缂栬緫</a>
|
||||
{# <a href="../group_del/?id={{ group.id }}" class="btn btn-xs btn-danger">鍒犻櫎</a>#}
|
||||
<a href="../perm_edit/?id={{ group.id }}" class="btn btn-xs btn-primary">涓绘満缁</a>
|
||||
<a href="../perm_edit/?id={{ group.id }}" class="btn btn-xs btn-info">涓绘満</a>
|
||||
<a href="../perm_edit/?id={{ group.id }}" class="btn btn-xs btn-danger">鎺堟潈缂栬緫</a>
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
|
|
|
@ -51,7 +51,7 @@
|
|||
<input type="checkbox" id="select_all" onclick="selectAll()" name="select_all">
|
||||
</th>
|
||||
<th class="text-center">閮ㄩ棬鍚嶇О</th>
|
||||
<th class="text-center">鎴愬憳鏁閲</th>
|
||||
<th class="text-center">鎴愬憳鏁鐩</th>
|
||||
<th class="text-center">澶囨敞</th>
|
||||
<th class="text-center">鎿嶄綔</th>
|
||||
</tr>
|
||||
|
@ -66,7 +66,7 @@
|
|||
<td class="text-center"> {{ dept.id | dept_member }} </td>
|
||||
<td class="text-center"> {{ dept.comment }} </td>
|
||||
<td class="text-center">
|
||||
<a title="[ {{ dept.name }} ] 鎴愬憳淇℃伅" href="../dept_detail/?id={{ dept.id }}" class="iframe btn btn-xs btn-primary">鎴愬憳</a>
|
||||
<a href="../user_list/dept/?did={{ dept.id }}" class="btn btn-xs btn-primary">鎴愬憳</a>
|
||||
<a href="../dept_edit/?id={{ dept.id }}" class="btn btn-xs btn-info">缂栬緫</a>
|
||||
<a href="../dept_del/?id={{ dept.id }}" class="btn btn-xs btn-danger">鍒犻櫎</a>
|
||||
</td>
|
||||
|
|
|
@ -52,7 +52,7 @@
|
|||
</th>
|
||||
<th class="text-center">缁勫悕</th>
|
||||
<th class="text-center">鎵灞為儴闂</th>
|
||||
<th class="text-center">鎴愬憳鏁閲</th>
|
||||
<th class="text-center">鎴愬憳鏁鐩</th>
|
||||
<th class="text-center">澶囨敞</th>
|
||||
<th class="text-center">鎿嶄綔</th>
|
||||
</tr>
|
||||
|
@ -68,7 +68,7 @@
|
|||
<td class="text-center"> {{ group.id | member_count }} </td>
|
||||
<td class="text-center"> {{ group.comment }} </td>
|
||||
<td class="text-center">
|
||||
<a title="[ {{ group.name }} ] 鎴愬憳淇℃伅" href="../group_detail/?id={{ group.id }}" class="iframe btn btn-xs btn-primary">鎴愬憳</a>
|
||||
<a href="../user_list/group/?gid={{ group.id }}" class="btn btn-xs btn-primary">鎴愬憳</a>
|
||||
<a href="../group_edit/?id={{ group.id }}" class="btn btn-xs btn-info">缂栬緫</a>
|
||||
<a href="../group_del/?id={{ group.id }}" class="btn btn-xs btn-danger">鍒犻櫎</a>
|
||||
</td>
|
||||
|
|
|
@ -40,9 +40,6 @@
|
|||
<a href="/jperm/dept_perm_list/">閮ㄩ棬鎺堟潈</a>
|
||||
</li>
|
||||
|
||||
<li id="perm_add">
|
||||
<a href="/jperm/perm_add/">鎺堟潈娣诲姞</a>
|
||||
</li>
|
||||
<li id="perm_list">
|
||||
<a href="/jperm/perm_list/">灏忕粍鎺堟潈</a>
|
||||
</li>
|
||||
|
|
Loading鈥
Reference in New Issue