用户修改完毕

pull/6/head
guanghongwei 2015-01-30 11:18:30 +08:00
parent b4006d3d36
commit d25a3ce17c
4 changed files with 38 additions and 6 deletions

View File

@ -34,7 +34,10 @@ def groups_str(username):
user = User.objects.get(username=username)
for group in user.user_group.filter(Q(type='A') | Q(type='M')):
groups.append(group.name)
return ' '.join(groups)
if len(groups) < 4:
return ' '.join(groups)
else:
return "%s ..." % ' '.join(groups[0:3])
@register.filter(name='get_item')

View File

@ -16,6 +16,7 @@ from django.http import HttpResponseRedirect
from django.shortcuts import render_to_response
from django.core.exceptions import ObjectDoesNotExist
from django.db.models import Q
from django.http import HttpResponse
from juser.models import UserGroup, User
from connect import PyCrypt, KEY
@ -135,6 +136,14 @@ def group_add_user(group_name, user_id=None, username=None):
group.user_set.add(user)
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)
@ -253,7 +262,7 @@ def group_add(request):
msg = ''
header_title, path1, path2 = '娣诲姞灞炵粍 | Add Group', 'juser', 'group_add'
group_types = {
'P': '绉佹湁缁',
# 'P': '绉佹湁缁',
'M': '绠$悊缁',
'A': '鎺堟潈缁',
}
@ -321,19 +330,32 @@ def group_edit(request):
error = ''
msg = ''
header_title, path1, path2 = '淇敼灞炵粍 | Edit Group', 'juser', 'group_edit'
group_types = {
# 'P': '绉佹湁缁',
'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]
return render_to_response('juser/group_add.html', locals())
else:
group_id = request.POST.get('group_id', None)
group_name = request.POST.get('group_name', None)
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)
# return HttpResponse(group_type)
group.update(name=group_name, comment=comment, type=group_type)
group_update_user(group_id, users_selected)
return HttpResponseRedirect('/juser/group_list/')

View File

@ -52,7 +52,7 @@
<div class="col-sm-8">
<select id="group_type" name="group_type" class="form-control m-b">
{% for t, type_name in group_types.items %}
{% ifequal t type_name %}
{% ifequal t group_type %}
<option value="{{ t }}" selected>{{ type_name }}</option>
{% else %}
<option value="{{ t }}">{{ type_name }}</option>
@ -80,6 +80,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 %}
</select>
</div>
</div>
@ -96,7 +99,7 @@
<div class="form-group">
<div class="col-sm-4 col-sm-offset-2">
<button class="btn btn-white" type="submit">鍙栨秷</button>
<button class="btn btn-primary" type="submit">纭淇濆瓨</button>
<button class="btn btn-primary" type="submit" onclick="javascript: (function(){$('#users_selected option').each(function(){$(this).prop('selected', true)})})()">纭淇濆瓨</button>
</div>
</div>
</form>

View File

@ -43,7 +43,11 @@
</tr>
<tr class="gradeX">
<td class="text-center">灞炵粍</td>
<td class="text-center">{{ user.username|groups_str }}</td>
<td class="text-center">
{% for group in user.user_group.all %}
{{ group.name }}
{% endfor %}
</td>
</tr>
<tr class="gradeX">
<td class="text-center">Email</td>