本文整理汇总了Python中models.User.create方法的典型用法代码示例。如果您正苦于以下问题:Python User.create方法的具体用法?Python User.create怎么用?Python User.create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.User
的用法示例。
在下文中一共展示了User.create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: populate_with_defaults
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import create [as 别名]
def populate_with_defaults():
'''Create user admin and grant him all permission
If the admin user already exists the function will simply return
'''
logging.getLogger(__name__).debug("Populating with default users")
if not User.select().where(User.name == 'admin').exists():
admin = User.create(name='admin', password='admin')
admins = Group.create(name='admins')
starCap = Capability.create(domain='.+',
action=(Action.CREATE |
Action.READ |
Action.UPDATE |
Action.DELETE))
admins.capabilities.add(starCap)
admin.groups.add(admins)
admin.save()
if not User.select().where(User.name == 'anonymous').exists():
anon = User.create(name='anonymous', password='')
anons = Group.create(name='anonymous')
readCap = Capability.create(domain=Capability.simToReg('/volumes/*'),
action=Action.READ)
anons.capabilities.add(readCap)
anon.groups.add(anons)
anon.save()
示例2: make_random_user
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import create [as 别名]
def make_random_user():
hasher = hashlib.md5()
hasher.update(''.join([random.choice(string.letters) for i in range(10)]))
name = hasher.hexdigest()
user = User(name)
user.create('lolwut')
return user
示例3: test_distinct
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import create [as 别名]
def test_distinct(self):
assert User.create(name='jack', email='[email protected]')
assert User.create(name='jack', email='[email protected]')
assert User.create(name='wangchao', email='[email protected]')
assert User.create(name='hit9', email='[email protected]')
query = User.select(fn.count(distinct(User.name)))
result = query.execute()
count = result.tuples()[0][0]
assert count == 3
query = User.orderby(User.id).select(distinct(User.email))
result = query.execute()
assert result.tuples() == (
('[email protected]',), ('[email protected]',), ('[email protected]', )
)
emails = [user.email for user in result.all()]
assert len(emails) == len(set(emails))
query = User.orderby(User.id).select(distinct(User.name, User.email))
try:
result = query.execute()
except Exception: # should raise an error
pass
else:
raise Exception
query = User.orderby(User.id).select(distinct(User.name), User.email)
result = query.execute()
assert result.count == 4
示例4: create_or_login
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import create [as 别名]
def create_or_login(resp):
session['openid'] = resp.identity_url
args = request.args.to_dict()
oauth_token = args.get('openid.sreg.oauth-token')
if oauth_token:
session['oauth_token'] = oauth_token
name = resp.fullname or resp.nickname
email = resp.email
user = User.get_by_openid(resp.identity_url)
if user is not None:
flash(u'Successfully signed in')
if user.oauth_token != oauth_token:
user.oauth_token = oauth_token
user.save()
g.user = user
return redirect(oid.get_next_url())
else:
auto_profile_create = os.environ.get('auto_profile_create', None)
if auto_profile_create:
User.create(name, email, session['openid'], oauth_token)
return redirect(oid.get_next_url())
return redirect(url_for(
'.create_profile',
next=oid.get_next_url(),
name=name,
email=email))
示例5: test_select
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import create [as 别名]
def test_select(self):
assert User.create(name='jack', email='[email protected]')
assert User.create(name='amy', email='[email protected]')
assert Post.create(name='hello world!', user_id=1)
assert [('jack', 'hello world!')] == [
(user.name, post.name) for user, post in (User & Post).select()]
示例6: test_left_join
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import create [as 别名]
def test_left_join(self):
User.create(name='jack', email='[email protected]')
User.create(name='amy', email='[email protected]')
Post.create(name='Hello world', user_id=1)
query = User.left_join(Post).select(User.name)
result = query.execute()
assert result.count == 2
示例7: test_tuples
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import create [as 别名]
def test_tuples(self):
assert User.create(name='jack', email='[email protected]')
assert User.create(name='amy', email='[email protected]')
assert User.create(name='tom', email='[email protected]')
query = User.select(User.id)
result = query.execute()
assert result.tuples() == ((1,), (2,), (3,))
示例8: testShortGame
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import create [as 别名]
def testShortGame(self):
self.setUp()
repository = GameStateRepository()
joe = User.create('joe', '[email protected]')
steve = User.create('steve', '[email protected]')
v = PrintView()
game = GameState.create()
game.addPlayer(joe)
game.addPlayer(steve)
for p in game.players:
p.bag = LetterBag.fromString('catgegae')
game.start()
self.assertTrue(game.leader().score == 0, "leader score==0")
repository.register(game)
id = repository.id(game)
self.assertTrue(id != None, 'registering with repository set game id')
game2 = repository.findById(id)
self.assertTrue(game2.leader().score == 0, "leader score==0")
game2.playWord(joe,0,0,True,'cat')
repository.update(game2)
game3 = repository.findById(id) # same id retrieves game2 update
self.assertTrue(game3.leader().score == 4, "same id retrieves update")
self.tearDown()
示例9: login_success
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import create [as 别名]
def login_success():
user = User()
session = bottle.request.environ.get('beaker.session')
auth_session = google.get_auth_session(
data={'code': bottle.request.params.get('code'),
'redirect_uri': redirect_uri,
'grant_type': 'authorization_code'},
decoder=json.loads)
session_json = auth_session.get(user_info_uri).json()
session_json = dict((k, unicode(v).encode('utf-8')) for k, v in
session_json.iteritems()) # For non-Ascii characters
# Checks if user exists, if not creates new one
if user.get(session_json['id']) is None:
user_info = {
'google_id': session_json['id'],
'name': session_json['name'],
'email': session_json['email'],
'picture': session_json['picture']}
logging.info("Hurray!! %s joined us.\n", user_info['name'])
user.create(user_info)
logging.info("Created user %s \n", user_info['google_id'])
# Creates user session
session['user'] = session_json['id']
bottle.redirect('/')
示例10: test_findone
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import create [as 别名]
def test_findone(self):
assert User.create(name='jack', email='[email protected]')
assert User.create(name='amy', email='[email protected]')
jack = User.findone(name='jack')
amy = User.findone(name='amy')
assert jack.email == '[email protected]'
assert amy.email == '[email protected]'
示例11: test_right_join
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import create [as 别名]
def test_right_join(self):
if db_type != 'sqlite': # sqlite3 current not support right join
User.create(name='jack', email='[email protected]')
User.create(name='amy', email='[email protected]')
Post.create(name='Hello world', user_id=1)
query = Post.right_join(User).select()
result = query.execute()
assert result.count == 2
示例12: setUp
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import create [as 别名]
def setUp(self):
self.n1, self.n2 = uuid.uuid4().hex, uuid.uuid4().hex
self.k1, self.k2 = fakePublicKey(), fakePublicKey()
self.u1 = User.create(self.n1, self.k1)
self.u2 = User.create(self.n2, self.k2)
self.m1 = Message.create(self.u1, self.u2, 'u1->u2')
self.m2 = Message.create(self.u2, self.u1, 'u2->u1')
self.m3 = Message.create(self.u1, self.u2, 'u1=>u2')
示例13: create_user
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import create [as 别名]
def create_user(**kwargs):
"""Takes arguments and create a new user.
:param kwargs:
"""
db.connect()
User.create(first_name=kwargs['first_name'], second_name=kwargs['second_name'],
phone=kwargs['phone'], role=kwargs['role'], username=kwargs['username'],
password=generate_password_hash(kwargs['password']), email=kwargs['email'])
示例14: syncUser
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import create [as 别名]
def syncUser(self):
self.connection.request("GET", "/sync/agent")
response = self.connection.getresponse()
data = json.loads(response.read())
print response.read()
if not data.has_key('up-to-date'):
for user in data['name']:
User.create(iid=user['iid'],username=user['username'],password=user['password'],
email=user['email'],role=user['role'],joined_on=user['joined_on'])
示例15: create_user
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import create [as 别名]
def create_user(**kwargs):
""""Create user controls."""
User.create(
first_name=kwargs['first_name'],
last_name=kwargs['last_name'],
username=kwargs['username'],
password=kwargs['password'],
email=kwargs['email'],
)