示例#1
0
文件: views.py 项目: codinl/mydj
def admin_list(request,cur_page=1,template='admin/admin/list.tpl'):
    count = Admin.get_count()
    if count > 0:
        cur_page = int(cur_page)
        p = Paginator(cur_page,count)
        admin_list = Admin.get_list(cur_page=cur_page)
        if admin_list:
            return render_response(template,admin_list=admin_list,p=p)
    return render_response(template,admin_list=None,p=None)
示例#2
0
文件: views.py 项目: codinl/mydj
def admin_edit(request,admin_id=0,template='admin/admin/edit.tpl'):
    ok = True
    admin = Admin.get_admin(admin_id)
    if request.method == 'GET':
        return render_response(template,admin=admin)
    elif request.method == 'POST':
        form = EditAdminForm(request.POST)
        if not form.is_valid():
            ok = False
        if ok:
            name = form.cleaned_data['name']
            if len(name) < 3:
                ok = False
        if ok:
            pwd = form.cleaned_data['password']
            repwd = form.cleaned_data['repassword']
            is_active = form.cleaned_data['is_active']
            if pwd and repwd:
                if len(pwd) < 5:
                    form.errors['msg'] = u"密码不能少于5个字符"
                    ok = False
                if ok:
                    if pwd != repwd:
                        form.errors['msg'] = u"两次密码不一致!"
                        ok = False
        if ok:
            is_active = form.cleaned_data['is_active']
            admin.is_active = is_active
            if name != admin.name:
                admin.name = name
            if pwd:
                password = make_password(pwd)
                admin.password = password  
            try:
                admin.save()
            except Exception,e:
                ok = False
                print e
        if ok:
            return HttpResponse("<script type='text/javascript'>window.top.art.dialog({id:'admin_edit'}).close();window.top.right.location.reload();</script>")
        else:
            return HttpResponse("<script type='text/javascript'>window.top.art.dialog({id:'admin_edit'}).close();alert('編輯失败:');</script>")