Browse Source

修改添加用户

pull/2/head
guanghongwei 10 years ago
parent
commit
63cdef4218
  1. 13
      webroot/AutoSa/AutoSa/views.py
  2. 4
      webroot/AutoSa/UserManage/forms.py
  3. 2
      webroot/AutoSa/templates/addUser.html

13
webroot/AutoSa/AutoSa/views.py

@ -165,6 +165,7 @@ def showUser(request):
@admin_required @admin_required
def addUser(request): def addUser(request):
"""添加用户""" """添加用户"""
msg = ''
form = UserAddForm() form = UserAddForm()
jm = PyCrypt(key) jm = PyCrypt(key)
if request.method == 'GET': if request.method == 'GET':
@ -174,7 +175,17 @@ def addUser(request):
form = UserAddForm(request.POST) form = UserAddForm(request.POST)
if form.is_valid(): if form.is_valid():
user = form.cleaned_data 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'}, return render_to_response('addUser.html', {'msg': msg, 'user_menu': 'active'},
context_instance=RequestContext(request)) context_instance=RequestContext(request))

4
webroot/AutoSa/UserManage/forms.py

@ -25,8 +25,8 @@ class UserAddForm(forms.Form):
widget=forms.TextInput(attrs={'class': 'form-control', 'placeholder': '姓名'})) widget=forms.TextInput(attrs={'class': 'form-control', 'placeholder': '姓名'}))
group = forms.ModelMultipleChoiceField(queryset=Group.objects.all(), group = forms.ModelMultipleChoiceField(queryset=Group.objects.all(),
widget=forms.SelectMultiple(attrs={'class': 'form-control'})) widget=forms.SelectMultiple(attrs={'class': 'form-control'}))
is_admin = forms.BooleanField() is_admin = forms.BooleanField(required=False)
is_superuser = forms.BooleanField() is_superuser = forms.BooleanField(required=False)
def clean_password_again(self): def clean_password_again(self):
password = self.cleaned_data['password'] password = self.cleaned_data['password']

2
webroot/AutoSa/templates/addUser.html

@ -64,12 +64,14 @@
</div> </div>
</div> </div>
<div class="form-group"> <div class="form-group">
{{ form.is_admin.errors }}
<label for="id_is_admin" class="col-sm-2 control-label">组admin</label> <label for="id_is_admin" class="col-sm-2 control-label">组admin</label>
<div class="col-sm-4"> <div class="col-sm-4">
{{ form.is_admin }} {{ form.is_admin }}
</div> </div>
</div> </div>
<div class="form-group"> <div class="form-group">
{{ form.is_superuser.errors }}
<label for="id_is_superuser" class="col-sm-2 control-label">超级admin</label> <label for="id_is_superuser" class="col-sm-2 control-label">超级admin</label>
<div class="col-sm-4"> <div class="col-sm-4">
{{ form.is_superuser }} {{ form.is_superuser }}

Loading…
Cancel
Save