当前位置: 首页>>代码示例>>Python>>正文


Python User.find_all方法代码示例

本文整理汇总了Python中models.User.find_all方法的典型用法代码示例。如果您正苦于以下问题:Python User.find_all方法的具体用法?Python User.find_all怎么用?Python User.find_all使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.User的用法示例。


在下文中一共展示了User.find_all方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import find_all [as 别名]
def test(request):
	users = yield from User.find_all()
	logging.info('users is %s' % str(users))
	return {
	'__template__': 'test.html',
	'users': users
	}
开发者ID:ujfj1986,项目名称:blog,代码行数:9,代码来源:handlers.py

示例2: api_get_users

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import find_all [as 别名]
def api_get_users(*, page='1'):
    page_index = get_page_index(page)
    num = yield from User.find_num('count(id)')
    p = Page(num, page_index)
    if num == 0:
        return dict(page=p, users=())
    users = yield from User.find_all(orderBy='created_at desc', limit=(p.offset, p.limit))
    for u in users:
        u.passwd = '******'
    return dict(page=p, users=users)
开发者ID:chris5641,项目名称:simple-blog,代码行数:12,代码来源:handlers.py

示例3: api_register_user

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import find_all [as 别名]
def api_register_user(*, email, name, passwd):
    if not name or not name.strip():
        raise APIValueError('name')
    if not email or not _RE_EMAIL.match(email):
        raise APIValueError('email')
    if not passwd or not _RE_SHA1.match(passwd):
        raise APIValueError('passwd')
    users = yield from User.find_all('email=?', [email])
    if len(users) > 0:
        raise APIError('register:failed', 'email', 'Email is already in use.')
    user = User(name=name.strip(), email=email, passwd=passwd,
                image='http://www.gravatar.com/avatar/%s?d=mm&s=120' % hashlib.md5(email.encode('utf-8')).hexdigest())
    yield from user.register()
    # make session cookie:
    r = web.Response()
    r.set_cookie(COOKIE_NAME, user.user2cookie(86400), max_age=86400, httponly=True)
    user.passwd = '******'
    r.content_type = 'application/json'
    r.body = json.dumps(user, ensure_ascii=False).encode('utf-8')
    return r
开发者ID:utopiaprince,项目名称:python-blog,代码行数:22,代码来源:handlers.py

示例4: api_register_user

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import find_all [as 别名]
def api_register_user(*, email, name, passwd):
    # strip():去除多余空格
    if not name or not name.strip():
        raise APIValueError('name')
    if not email or not _RE_EMAIL.match(email):
        raise APIValueError('email')
    if not passwd or not _RE_SHA1.match(passwd):
        raise APIValueError('passwd')
    users = yield from User.find_all('email=?', [email])
    if len(users) > 0:
        raise APIError('register failed', 'email', 'Email is already in use.')
    uid = next_id()
    # 密码以sha1形式保存在数据库(uid:passwd)=> sha1
    sha1_passwd = '%s:%s' % (uid, passwd)
    user = User(id=uid, name=name.strip(), email=email, passwd=hashlib.sha1(sha1_passwd.encode('utf-8')).hexdigest(),
                image='http://www.gravatar.com/avatar/%s?d=mm&s=120' % hashlib.md5(email.encode('utf-8')).hexdigest())
    yield from user.save()
    r = web.Response()
    r.set_cookie(COOKIE_NAME, user2cookie(user, 86400), max_age=86400, httponly=True)
    r.content_type = 'application/json'
    r.body = json.dumps(user, ensure_ascii=False).encode('utf-8')
    return r
开发者ID:chris5641,项目名称:simple-blog,代码行数:24,代码来源:handlers.py

示例5: authenticate

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import find_all [as 别名]
def authenticate(*, email, passwd):
    if not email:
        raise APIValueError('email', 'Invalid email.')
    if not passwd:
        raise APIValueError('passwd', 'Invalid passwd.')
    users = yield from User.find_all('email=?', [email])
    if len(users) == 0:
        raise APIValueError('email', 'email not exist.')
    user = users[0]
    # 把密码转化成sha1与数据库中sha1进行比较
    sha1 = hashlib.sha1()
    sha1.update(user.id.encode('utf-8'))
    sha1.update(b':')
    sha1.update(passwd.encode('utf-8'))
    if user.passwd != sha1.hexdigest():
        raise APIValueError('passwd', 'Invalid passwd.')
    r = web.Response()
    r.set_cookie(COOKIE_NAME, user2cookie(user, 86400), max_age=86400, httponly=True)
    user.passwd = '******'
    r.content_type = 'application/json'
    r.body = json.dumps(user, ensure_ascii=False).encode('utf-8')
    return r
开发者ID:chris5641,项目名称:simple-blog,代码行数:24,代码来源:handlers.py

示例6: blog_id

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import find_all [as 别名]
def blog_id(id):
    if request.method == 'POST':
        comment_content = request.form['comment_content']
        comment_name = request.form['comment_name']
        comment = Comment(id=next_id(), blog_id=id, user_id='guest', user_name=comment_name,
                          user_image='',
                          content=comment_content, created_at=time.time())
        comment.save()
        image = common.create_avatar_by_name(comment_name)
        user = User(id=next_id(), email='', passwd='', admin=0, name=comment_name,
                    image=image,
                    created_at=time.time())
        mylog.info(image)
        # TODO 先使用name来进行判定是否唯一,后期希望能够使用email来判断是否唯一
        _user = User.find_all('name= ?', [comment_name])
        if len(_user) == 0:
            user.save()
        flash('comment and new user had been saved successfully!')

    blog = Blog.find(id)
    md_text = highlight.parse2markdown(blog.content)
    blog.html_content = md_text
    comments = Comment.find_all('blog_id= ?', [id])
    return render_template('blogdetail.html', blog=blog, comments=comments)
开发者ID:fantianwen,项目名称:web_blog,代码行数:26,代码来源:app.py

示例7: test_users

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import find_all [as 别名]
def test_users():
	users = User.find_all()
	return dict(users=users)
开发者ID:dasbindus,项目名称:my-python-webapp,代码行数:5,代码来源:urls.py

示例8: getbyid

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import find_all [as 别名]
def getbyid(id):
    user = User.get(primary_key=id)
    users = User.find_all()
    return dict(users=users, user=user)
开发者ID:silentsee,项目名称:blog,代码行数:6,代码来源:urls.py

示例9: find_all_test

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import find_all [as 别名]
def find_all_test(loop):
    yield from orm.create_pool(loop=loop, user='www-data', password='www-data', db='myblog')
    rs = yield from User.find_all()
    for x in range(len(rs)):
        print(rs[x])
开发者ID:chris5641,项目名称:simple-blog,代码行数:7,代码来源:test.py

示例10: test_find_all

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import find_all [as 别名]
def test_find_all(loop):
    yield from orm.create_pool(user='johnie', password='MwKuPD1I', db='johnietest', host='mysql01-db.sh.cn.ao.ericsson.se', port =3508, loop = loop)
    u = User()
    rs = yield from u.find_all()
    yield from orm.close_pool()
    print(rs)
开发者ID:johniezz,项目名称:python3_blog,代码行数:8,代码来源:ormtest.py

示例11: api_get_users

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import find_all [as 别名]
def api_get_users():
    users = User.find_all()
    for u in users:
        u.password = '******'
    return dict(users=users)
开发者ID:blackboarddd,项目名称:PyTest,代码行数:7,代码来源:urls.py

示例12: get_avator_or_404

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import find_all [as 别名]
def get_avator_or_404(user_name):
    users = User.find_all('name= ?', [user_name])
    image = users[0].image
    return image
开发者ID:fantianwen,项目名称:web_blog,代码行数:6,代码来源:app.py


注:本文中的models.User.find_all方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。