From 8c9e763f74d99841dc33adddc53c79262817d09c Mon Sep 17 00:00:00 2001 From: guanghongwei <hongwei.guang@yolu-inc.com> Date: Sat, 10 Jan 2015 16:24:44 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=BB=98=E8=AE=A4=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- jumpserver/views.py | 2 -- juser/views.py | 20 +++++++------------- templates/juser/user_add.html | 29 ++++++++++++++++++----------- 3 files changed, 25 insertions(+), 26 deletions(-) diff --git a/jumpserver/views.py b/jumpserver/views.py index 9c5cfc0f..ef9c9560 100644 --- a/jumpserver/views.py +++ b/jumpserver/views.py @@ -12,5 +12,3 @@ def skin_config(request): return render_to_response('skin_config.html') -def header_path(header_title, path1, path2): - return header_title, path1, path2 diff --git a/juser/views.py b/juser/views.py index d2a28ccd..e632ef9f 100644 --- a/juser/views.py +++ b/juser/views.py @@ -10,7 +10,6 @@ from django.shortcuts import render_to_response from juser.models import UserGroup, User from connect import PyCrypt, KEY -from jumpserver.views import header_path cryptor = PyCrypt(KEY) @@ -37,7 +36,7 @@ class AddError(Exception): def group_add(request): error = '' msg = '' - header_title, path1, path2 = header_path('æ·»åŠ å±žç»„ | Add Group', 'juser', 'group_add') + header_title, path1, path2 = 'æ·»åŠ å±žç»„ | Add Group', 'juser', 'group_add' if request.method == 'POST': group_name = request.POST.get('group_name', None) @@ -69,12 +68,10 @@ def group_add(request): def group_list(request): - + header_title, path1, path2 = '查看属组 | Add Group', 'juser', 'group_add' groups = UserGroup.objects.all() return render_to_response('juser/group_list.html', - {'header_title': u'查看属组 | Add Group', - 'path1': 'juser', 'path2': 'group_add', - 'groups': groups}) + locals()) def user_list(request): @@ -100,7 +97,7 @@ def db_del_user(username): def user_add(request): error = '' msg = '' - + header_title, path1, path2 = 'æ·»åŠ ç”¨æˆ· | Add User', 'juser', 'user_add' user_role = {'SU': u'超级管ç†å‘˜', 'GA': u'组管ç†å‘˜', 'CU': u'普通用户'} all_group = UserGroup.objects.all() if request.method == 'POST': @@ -109,13 +106,13 @@ def user_add(request): name = request.POST.get('name', None) email = request.POST.get('email', '') groups = request.POST.getlist('groups', None) - role = request.POST.get('role', None) + role_post = request.POST.get('role', None) ssh_pwd = request.POST.get('ssh_pwd', None) ssh_key_pwd1 = request.POST.get('ssh_key_pwd1', None) is_active = request.POST.get('is_active', '1') try: - if None in [username, password, ssh_key_pwd1, name, groups, role, is_active]: + if None in [username, password, ssh_key_pwd1, name, groups, role_post, is_active]: error = u'带*内容ä¸èƒ½ä¸ºç©º' raise AddError user = User.objects.filter(username=username) @@ -132,10 +129,7 @@ def user_add(request): is_active=is_active, date_joined=time_now) msg = u'æ·»åŠ ç”¨æˆ·æˆåŠŸ' return render_to_response('juser/user_add.html', - {'header_title': u'æ·»åŠ ç”¨æˆ· | Add User', - 'path1': 'juser', 'path2': 'user_add', - 'roles': user_role, 'all_group': all_group, - 'error': error, 'msg': msg}) + locals()) diff --git a/templates/juser/user_add.html b/templates/juser/user_add.html index 01430bbf..42a72442 100644 --- a/templates/juser/user_add.html +++ b/templates/juser/user_add.html @@ -37,14 +37,14 @@ <div class="form-group"> <label for="username" class="col-sm-2 control-label">用户å<span class="red-fonts">*</span></label> <div class="col-sm-8"> - <input id="username" name="username" placeholder="Username" type="text" class="form-control"> + <input id="username" name="username" placeholder="Username" type="text" class="form-control" value={{ username }}> </div> </div> <div class="hr-line-dashed"></div> <div class="form-group"> <label for="password" class="col-sm-2 control-label">密ç <span class="red-fonts">*</span></label> <div class="col-sm-8"> - <input id="password" name="password" placeholder="Password" type="password" class="form-control"> + <input id="password" name="password" placeholder="Password" type="password" class="form-control" value={{ password }}> <span class="help-block m-b-none"> 登陆web的密ç </span> @@ -54,7 +54,7 @@ <div class="form-group"> <label for="ssh_key_pwd1" class="col-sm-2 control-label">密钥密ç <span class="red-fonts">*</span></label> <div class="col-sm-8"> - <input id="ssh_key_pwd1" name="ssh_key_pwd1" placeholder="SSH Key Password" type="password" class="form-control"> + <input id="ssh_key_pwd1" name="ssh_key_pwd1" placeholder="SSH Key Password" type="password" class="form-control" value="{{ ssh_key_pwd1 }}"> <span class="help-block m-b-none"> 登陆 Jumpserver 使用的SSH密钥的密ç </span> @@ -64,7 +64,7 @@ <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="Name" type="text" class="form-control" > + <input id="name" name="name" placeholder="Name" type="text" class="form-control" value={{ name }} > </div> </div> <div class="hr-line-dashed"></div> @@ -73,10 +73,14 @@ <div class="col-sm-8"> <select id="groups" name="groups" class="form-control m-b" multiple> {% for group in all_group %} - {% if forloop.first %} + {% if groups and group.id in groups %} <option value="{{ group.id }}" selected>{{ group.name }}</option> {% else %} - <option value="{{ group.id }}">{{ group.name }}</option> + {% if forloop.first %} + <option value="{{ group.id }}" selected>{{ group.name }}</option> + {% else %} + <option value="{{ group.id }}">{{ group.name }}</option> + {% endif %} {% endif %} {% endfor %} </select> @@ -87,8 +91,12 @@ <label for="role" class="col-lg-2 control-label">角色<span class="red-fonts">*</span></label> <div class="col-sm-8"> <select id="role" name="role" class="form-control m-b"> - {% for r, role in roles.items %} - <option value="{{ r }}">{{ role }}</option> + {% for r, role_name in user_role %} + {% ifequal r role_post %} + <option value="{{ r }}" selected>{{ role_name }}</option> + {% else %} + <option value="{{ r }}">{{ role_name }}</option> + {% endifequal %} {% endfor %} </select> </div> @@ -97,7 +105,7 @@ <div class="form-group"> <label for="ssh_pwd" class="col-sm-2 control-label">SSH密ç </label> <div class="col-sm-8"> - <input id="ssh_pwd" name="ssh_pwd" type="password" placeholder="SSH Password" class="form-control"> + <input id="ssh_pwd" name="ssh_pwd" type="password" placeholder="SSH Password" class="form-control" value="{{ ssh_pwd }}"> <span class="help-block m-b-none"> 如果使用passwordæ–¹å¼ï¼Œè¯¥å¯†ç 是用户在åŽç«¯æœåŠ¡å™¨çš„å¯†ç </span> @@ -107,12 +115,11 @@ <div class="form-group"> <label for="email" class="col-sm-2 control-label">Email</label> <div class="col-sm-8"> - <input id="email" name="email" type="email" placeholder="Email" class="form-control"> + <input id="email" name="email" type="email" placeholder="Email" class="form-control" value="{{ email }}"> </div> </div> <div class="hr-line-dashed"></div> <div class="form-group"><label class="col-sm-2 control-label">是å¦å¯ç”¨</label> - <div class="col-sm-8"> <div class="radio i-checks"> <label><input type="radio" value="1" name="is_active" checked>å¯ç”¨ </label> -- 2.18.0