From 63cdef4218999dffeb9d2d64b372b8a3208c5a85 Mon Sep 17 00:00:00 2001 From: guanghongwei Date: Tue, 16 Sep 2014 17:26:49 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=87=EE=86=BD=E6=95=BC=E5=A8=A3=E8=AF=B2?= =?UTF-8?q?=E5=A7=9E=E9=90=A2=E3=84=A6=E5=9F=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- webroot/AutoSa/AutoSa/views.py | 13 ++++++++++++- webroot/AutoSa/UserManage/forms.py | 4 ++-- webroot/AutoSa/templates/addUser.html | 2 ++ 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/webroot/AutoSa/AutoSa/views.py b/webroot/AutoSa/AutoSa/views.py index d5c4e0216..1a2100ae9 100644 --- a/webroot/AutoSa/AutoSa/views.py +++ b/webroot/AutoSa/AutoSa/views.py @@ -165,6 +165,7 @@ def showUser(request): @admin_required def addUser(request): """添加用户""" + msg = '' form = UserAddForm() jm = PyCrypt(key) if request.method == 'GET': @@ -174,7 +175,17 @@ def addUser(request): form = UserAddForm(request.POST) if form.is_valid(): user = form.cleaned_data - return HttpResponse(user) + ldap_password = keygen(16) + u = User( + username=user['username'], + password=user['password'], + key_pass=user['key_pass'], + name=user['name'], + group=user['group'], + is_admin=user['is_admin'], + is_superuser=user['is_superuser'], + ldap_password=ldap_password) + u.save() return render_to_response('addUser.html', {'msg': msg, 'user_menu': 'active'}, context_instance=RequestContext(request)) diff --git a/webroot/AutoSa/UserManage/forms.py b/webroot/AutoSa/UserManage/forms.py index acf31ea3b..affecacf0 100644 --- a/webroot/AutoSa/UserManage/forms.py +++ b/webroot/AutoSa/UserManage/forms.py @@ -25,8 +25,8 @@ class UserAddForm(forms.Form): widget=forms.TextInput(attrs={'class': 'form-control', 'placeholder': '姓名'})) group = forms.ModelMultipleChoiceField(queryset=Group.objects.all(), widget=forms.SelectMultiple(attrs={'class': 'form-control'})) - is_admin = forms.BooleanField() - is_superuser = forms.BooleanField() + is_admin = forms.BooleanField(required=False) + is_superuser = forms.BooleanField(required=False) def clean_password_again(self): password = self.cleaned_data['password'] diff --git a/webroot/AutoSa/templates/addUser.html b/webroot/AutoSa/templates/addUser.html index 6caf522a2..7de47cf57 100644 --- a/webroot/AutoSa/templates/addUser.html +++ b/webroot/AutoSa/templates/addUser.html @@ -64,12 +64,14 @@
+ {{ form.is_admin.errors }}
{{ form.is_admin }}
+ {{ form.is_superuser.errors }}
{{ form.is_superuser }}