本文整理汇总了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
}
示例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)
示例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
示例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
示例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
示例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)
示例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)
示例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)
示例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])
示例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)
示例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)
示例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