本文整理汇总了Python中model.User.insert方法的典型用法代码示例。如果您正苦于以下问题:Python User.insert方法的具体用法?Python User.insert怎么用?Python User.insert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类model.User
的用法示例。
在下文中一共展示了User.insert方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: register_user
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import insert [as 别名]
def register_user():
i = ctx.request.input(name='',email='', password='')
name = i.name.strip()
email = i.email.strip()
password = i.password
if not name:
raise APIValueError('name')
if not email or not email_valid(email):
raise APIValueError('email')
if not password or not password_valid(password):
raise APIValueError('password')
user = User.find_first('where email=?', email)
if user:
raise APIError('registered failed', 'email', 'Email is already in use')
user = User(name = name, email = email, password = password, image = 'about:blank')
user.insert()
return user
示例2: user_register
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import insert [as 别名]
def user_register(email, password, username, captcha, answer):
'''
Register a user. And if success it will be logged in automatically.
'''
if answer.lower() != captcha.lower():
raise APIValueError('captcha', 'Wrong Captcha - ' + captcha)
if not username:
raise APIValueError('username', message="Username cannot be empty.")
if not email or not _RE_EMAIL.match(email):
raise APIValueError('email', message="Email cannot be empty.")
if not password or not _RE_MD5.match(password):
raise APIValueError('password', message="Invalid Hashvalue")
user = User.find_first('where t_emailaddr=?', email)
if user:
raise APIValueError('email', message="EMail is already in use.")
# Write to database
user = User(username=username, email=email, password=password,
avatar='/resources/images/user_default.gif', creation_time=time.time())
current_user = user.insert()
# Login as registered user.
cookie = make_signed_cookie(str(current_user['t_uid']), user.password, None)
ctx.response.set_cookie(_COOKIE_NAME, cookie)
return current_user
示例3: User
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import insert [as 别名]
#!/usr/bin/env python
#-*- coding:utf-8 -*-
import logging
logging.basicConfig(format='%(levelname)s:%(message)s',level='INFO')
from model import User,Blog,Comment
import db
db.create_engine(user='root',password='123456',database='myblog')
u = User(name = 'Test',email='[email protected]',password='123456',image='about:blank')
u.insert()
print 'new user id:',u.id
u1 = User.find_first('where email=?',['[email protected]'])
print 'find user\'s name:',u1.name
示例4: insert
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import insert [as 别名]
def insert():
from model import User
mongo = User()
mongo.insert({"id": 1, "name": "meego"})
示例5: test_insert
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import insert [as 别名]
def test_insert(loop):
user = User(id = '111',name = 'aaa',email='[email protected]', passwd='1234567890', image='about:blank')
yield from create_pool(loop,**kw)
yield from user.insert()
print('insert')