本文整理匯總了Python中www.models.User.save方法的典型用法代碼示例。如果您正苦於以下問題:Python User.save方法的具體用法?Python User.save怎麽用?Python User.save使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類www.models.User
的用法示例。
在下文中一共展示了User.save方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: api_register_user
# 需要導入模塊: from www.models import User [as 別名]
# 或者: from www.models.User import save [as 別名]
def api_register_user(*, email, name, passwd): # https://www.python.org/dev/peps/pep-3102/
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.findAll('email=?', [email])
if len(users) > 0:
raise APIError('register:failed', 'email', 'email already in use')
uid = next_id()
sha1_passwd = '%s:%s' % (uid, passwd) # get SHA1 for 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()
# make session cookie:
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
示例2: api_register_user
# 需要導入模塊: from www.models import User [as 別名]
# 或者: from www.models.User import save [as 別名]
def api_register_user(*, email, name, passwd):
#判斷name是否為空:
if not name or not name.strip():
raise APIValueError('name')
#判斷email是否為空及是否滿足email格式:
if not email or not _RE_EMAIL.match(email):
raise APIValueError('email')
#判斷password首付為空及是否滿足password格式:
if not passwd or not _RE_SHA1.match(passwd):
raise APIValueError('passwd')
#數據中查詢對應的email信息:
users = yield from User.findAll('email=?', [email])
#判斷查詢結果是否存在,若存在則返回異常提示郵件已存在:
if len(users) > 0:
raise APIError('register:failed', 'email', 'Email is already in use.')
#生成唯一ID:
uid = next_id()
#重構唯一ID和password成新的字符串:
sha1_passwd = '%s:%s' % (uid, passwd)
#構建用戶對象信息:
#hashlib.sha1().hexdigest():取得SHA1哈希摘要算法的摘要值。
user = User(id=uid, name=name.strip(), email=email, passwd=hashlib.sha1(sha1_passwd.encode('utf-8')).hexdigest(), image='http://www(first).gravatar.com/avatar/%s?d=mm&s=120' % hashlib.md5(email.encode('utf-8')).hexdigest())
#將用戶信息存儲到數據庫:
yield from user.save()
# make session cookie:
#構造session cookie信息:
r = web.Response()
#aiohttp.web.StreamResponse().set_cookie():設置cookie的方法。
r.set_cookie(COOKIE_NAME, user2cookie(user, 86400), max_age=86400, httponly=True) #max_age:定義cookie的有效期(秒);
user.passwd = '******'
r.content_type = 'application/json'
#以json格式序列化響應信息; ensure_ascii默認為True,非ASCII字符也進行轉義。如果為False,這些字符將保持原樣。
r.body = json.dumps(user, ensure_ascii=False).encode('utf-8')
return r
示例3: do_signup
# 需要導入模塊: from www.models import User [as 別名]
# 或者: from www.models.User import save [as 別名]
def do_signup(sender, interval):
logger("Entering do_signup (%s)" % (sender))
try:
try:
user = User(phonenumber=sender,interval=int(interval))
except (ValueError, IndexError):
user = User(phonenumber=sender)
user.save()
except:
logger("user already exists! %s" % sender)
#TODO send a message back? fail silently?
#raise Exception, "User '%s' already exists" % sender
raise
return
signup_email = "Thank you for signing up! How to play: we will send you a message listing a definition and a choice of four words. You must choose the correct word corresponding to that definition. Respond with only the number of the word that you believe is correct. Text 'stats' to see how you're doing and 'quit' to leave WordiSMS."
SMS(user.phonenumber, signup_email).send()
logger("Exiting do_signup")
return
示例4: test_save
# 需要導入模塊: from www.models import User [as 別名]
# 或者: from www.models.User import save [as 別名]
def test_save():
loop = asyncio.get_event_loop()
loop.run_until_complete(www.orm.create_pool(loop, user='root', password='root', db='awesome'))
u = User(name='Test', email='[email protected]', passwd='1234567890', image='about:blank')
loop.run_until_complete(u.save())
loop.stop()
示例5: api_register_user
# 需要導入模塊: from www.models import User [as 別名]
# 或者: from www.models.User import save [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.findAll('email=?', [email])
if len(users) > 0:
raise APIError('register:failed', 'email', 'Email is already in use.')
uid = next_id()
sha1_password = '%s:%s' % (uid, passwd)
user = User(id=uid, name=name.strip(), email=email,passwd=hashlib.sha1(sha1_password.encode('utf-8').hexdigest(),
image=''))
yield from user.save()
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).enconde('utf-8')
return r
示例6: test
# 需要導入模塊: from www.models import User [as 別名]
# 或者: from www.models.User import save [as 別名]
def test(loop):
yield from orm.create_pool(loop=loop, user='www-data', password='www-data', database='awesome')
u=User(admin=True, name='kHRYSTAL', email='[email protected]', passwd=hashlib.sha1(('%s:%s' % (next_id(), 'yyg1990918')).encode('utf-8')).hexdigest(), image='about:blank')
yield from u.save()
示例7: test
# 需要導入模塊: from www.models import User [as 別名]
# 或者: from www.models.User import save [as 別名]
def test(loop):
yield from www.orm.create_pool(host="127.0.0.1", port=3306, user="root", password="1", db="awesome", loop=loop)
u = User(name="test3", email="[email protected]", passwd="test", image="about:blank")
yield from u.save()
示例8: test
# 需要導入模塊: from www.models import User [as 別名]
# 或者: from www.models.User import save [as 別名]
def test(loop):
yield from www.orm.create_pool(loop=loop, user='www-data', password='www-data', db='awesome')
u = User(name='test77',email='[email protected]',passwd='test',image='about:blank')
yield from u.save()
示例9: test
# 需要導入模塊: from www.models import User [as 別名]
# 或者: from www.models.User import save [as 別名]
def test(loop):
yield from orm.create_pool(loop=loop, user='www-data', password='www-data', database='awesome')
u=User(name='Yao', email='[email protected]', passwd="sas", image='about:blank')
yield from u.save()
示例10: test
# 需要導入模塊: from www.models import User [as 別名]
# 或者: from www.models.User import save [as 別名]
def test(loop):
yield from www.orm.create_pool(loop=loop, user='weibo', password='weibo', db='weibo')
u = User(name='Test1', email='[email protected]', passwd='1234567890', image='about:blank')
yield from u.save()
示例11: test
# 需要導入模塊: from www.models import User [as 別名]
# 或者: from www.models.User import save [as 別名]
def test(loop):
yield from www.orm.create_pool(loop=loop, host='localhost', port=3306, user='root', password='123456', db='awesome')
u = User(name='test85',email='[email protected]',passwd='test',image='about:blank')
yield from u.save()
示例12: test
# 需要導入模塊: from www.models import User [as 別名]
# 或者: from www.models.User import save [as 別名]
def test(loop, x):
yield from orm.create_pool(user='root', password='', database='awesome', loop=loop)
u = User(name='Test%d' % x, email='test%[email protected]' % x, passwd='123456', image='about:blank')
yield from u.save()