jumpserver/juser/views.py

85 lines
2.4 KiB
Python
Raw Normal View History

2015-01-05 15:55:05 +00:00
# coding: utf-8
2015-01-03 12:42:20 +00:00
from django.shortcuts import render_to_response
2015-01-10 05:50:59 +00:00
from juser.models import UserGroup, User
2015-01-07 15:56:36 +00:00
class AddError(Exception):
pass
2015-01-03 12:42:20 +00:00
2015-01-07 15:20:48 +00:00
def group_add(request):
2015-01-07 15:56:36 +00:00
error = ''
msg = ''
if request.method == 'POST':
group_name = request.POST.get('j_group_name', None)
comment = request.POST.get('j_comment', None)
try:
if not group_name:
error = u'组名不能为空'
raise AddError
2015-01-10 05:50:59 +00:00
group = UserGroup.objects.filter(name=group_name)
2015-01-07 15:56:36 +00:00
if group:
error = u'%s 已存在' % group_name
2015-01-07 16:01:41 +00:00
raise AddError
2015-01-07 15:56:36 +00:00
2015-01-10 05:50:59 +00:00
group = UserGroup(name=group_name, comment=comment)
2015-01-07 15:56:36 +00:00
group.save()
except AddError:
pass
except TypeError:
error = u'保存用户失败'
else:
2015-01-07 16:07:00 +00:00
msg = u'添加组 %s 成功' % group_name
2015-01-07 15:56:36 +00:00
2015-01-07 15:20:48 +00:00
return render_to_response('juser/group_add.html',
2015-01-07 15:56:36 +00:00
{'header_title': u'添加属组 | Add Group',
'path1': 'juser', 'path2': 'group_add',
'error': error, 'msg': msg})
2015-01-07 15:20:48 +00:00
2015-01-09 14:10:38 +00:00
def group_list(request):
2015-01-10 05:50:59 +00:00
groups = UserGroup.objects.all()
2015-01-09 14:51:46 +00:00
return render_to_response('juser/group_list.html',
{'header_title': u'查看属组 | Add Group',
'path1': 'juser', 'path2': 'group_add',
'groups': groups})
2015-01-09 14:10:38 +00:00
def user_list(request):
pass
2015-01-05 13:20:09 +00:00
def user_add(request):
2015-01-10 05:10:44 +00:00
error = ''
msg = ''
user_role = {'SU': 'SuperUser', 'GA': 'GroupAdmin', 'CU': 'CommonUser'}
2015-01-10 05:50:59 +00:00
groups = UserGroup.objects.all()
2015-01-10 05:10:44 +00:00
if request.method == 'POST':
username = request.POST.get('j_username', None)
password = request.POST.get('j_password', None)
name = request.POST.get('j_name', None)
email = request.POST.get('j_email', '')
groups = request.POST.getlist('j_group', None)
role = request.POST.get('j_role', None)
ssh_pwd = request.POST.get('j_ssh_pwd', None)
is_active = request.POST.get('j_is_active', None)
2015-01-07 15:20:48 +00:00
return render_to_response('juser/user_add.html',
2015-01-10 05:10:44 +00:00
{'header_title': u'添加用户 | Add User',
'path1': 'juser', 'path2': 'user_add',
'roles': user_role, 'groups': groups})
2015-01-07 15:20:48 +00:00
2015-01-03 12:42:20 +00:00
2014-12-22 09:18:51 +00:00
2015-01-10 04:30:21 +00:00