示例#1
0
def users(request):
    key_list = [
        'id', 'username', 'is_active', 'date_joined', 'email', 'last_login'
    ]
    u = usermodel()
    r = u.find({})
    result = Query.fSqlResult(r, key_list)
    return render(request, 'users/users.html', {'ret': result})
示例#2
0
def deleteUsersById(request):
    id = request.REQUEST.get('id', None)
    result = {"ret": "delete faild"}
    if id:
        u = usermodel()
        r = u.delete({"id": id})
        result = {"ret": "delete success"}

    return HttpResponse(json.dumps(result), content_type="application/json")
示例#3
0
def ajax_users(request):
    page = request.REQUEST.get('p', 1)

    pageSize = request.REQUEST.get('pageSize', 6)

    key_list = [
        'id', 'username', 'is_active', 'date_joined', 'email', 'last_login'
    ]

    u = usermodel()

    r = u.find({})

    result = Query.fSqlResult(r, key_list)

    totalPage = u.count({})

    if totalPage % pageSize:
        totalPage = totalPage / pageSize + 1
    else:
        totalPage = totalPage / pageSize

    head = {
        'a_id': "用户ID",
        'b_username': "******",
        'c_is_active': "是否可用",
        'd_date_joined': "加入时间",
        'e_email': "邮件",
        'f_last_login': "******"
    }
    new_result = []

    for i in result:
        if i['is_active']:
            i['is_active'] = '可用'
        if i['date_joined']:
            i['date_joined'] = str(i['date_joined'])
        if i['last_login']:
            i['last_login'] = str(i['last_login'])
        new_result.append(i)
    print new_result
    ret = {
        "body": new_result,
        "head": head,
        "page": {
            "current": page,
            "totalpage": totalPage,
            "lastpage": totalPage
        }
    }
    return HttpResponse(json.dumps(ret, sort_keys=True),
                        content_type="application/json")
示例#4
0
def getUsersById(request):
    id = request.REQUEST.get('id', None)
    result = {}
    if id is None or id == 0:
        return HttpResponse(json.dumps(result),
                            content_type="application/json")

    key_list = [
        'id', 'username', 'is_active', 'date_joined', 'email', 'last_login'
    ]

    u = usermodel()
    r = u.find({"id": id})
    result = Query.fSqlResult(r, key_list)
    ret = {'result': result[0]}
    return HttpResponse(json.dumps(ret), content_type="application/json")
示例#5
0
def new_users(request):
    if request.method == 'POST':
        user_name = request.REQUEST.get('user_name')
        user_passwd = request.REQUEST.get('user_passwd')
        if user_name is not None and user_passwd is not None:
            pwd = make_password(user_passwd, None, 'pbkdf2_sha256')
            if request.META.has_key('HTTP_X_FORWARDED_FOR'):
                ip = request.META['HTTP_X_FORWARDED_FOR']
            else:
                ip = request.META['REMOTE_ADDR']
            insert = {
                "user_name": user_name,
                'user_passwd': pwd,
                'client_ip': ip,
                'auth_group': 1
            }
            u = usermodel()
            uid = u.insert(insert)
            if uid:
                return HttpResponseRedirect("/users/")
    return render(request, 'users/new_users.html', {})