添加 group add view

pull/6/head
ibuler 2015-01-07 23:56:36 +08:00
parent 2aea864fbe
commit fac7fe3281
2 changed files with 42 additions and 1 deletions

View File

@ -2,10 +2,45 @@
from django.shortcuts import render_to_response
from juser.models import Group, User
class AddError(Exception):
pass
def group_add(request):
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
group = Group.objects.filter(name=group_name)
if group:
error = u'%s 已存在' % group_name
assert AddError
group = Group(name=group_name, comment=comment)
group.save()
except AddError:
pass
except TypeError:
error = u'保存用户失败'
else:
msg = u'添加用户成功'
return render_to_response('juser/group_add.html',
{'header_title': u'添加属组 | Add Group', 'path1': 'juser', 'path2': 'group_add'})
{'header_title': u'添加属组 | Add Group',
'path1': 'juser', 'path2': 'group_add',
'error': error, 'msg': msg})
def user_add(request):

View File

@ -28,6 +28,12 @@
</div>
<div class="ibox-content">
<form method="post" class="form-horizontal" action="">
{% if error %}
<div class="alert alert-warning text-center">{{ error }}</div>
{% endif %}
{% if msg %}
<div class="alert alert-success text-center">{{ msg }}</div>
{% endif %}
<div class="form-group">
<label for="j_group_name" class="col-sm-2 control-label">组名<span class="red-fonts">*</span></label>
<div class="col-sm-8">