本文整理汇总了Python中User.insert方法的典型用法代码示例。如果您正苦于以下问题:Python User.insert方法的具体用法?Python User.insert怎么用?Python User.insert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类User
的用法示例。
在下文中一共展示了User.insert方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testapp
# 需要导入模块: import User [as 别名]
# 或者: from User import insert [as 别名]
def testapp(request):
app = create_app('{{cookiecutter.app_name}}.settings.TestConfig')
client = app.test_client()
db.app = app
db.create_all()
if getattr(request.module, "create_user", True):
admin = User(username="admin", password="supersafepassword")
admin.insert()
my_role = Role(name='admin')
my_role.insert()
admin.add_roles('admin')
non_admin = User(username="non_admin", password="supersafepassword")
non_admin.insert()
safe_commit()
def teardown():
db.session.remove()
db.drop_all()
request.addfinalizer(teardown)
return client
示例2: admin_users_edit_post
# 需要导入模块: import User [as 别名]
# 或者: from User import insert [as 别名]
def admin_users_edit_post():
payload = get_payload(request)
user_id = payload.get('user_id')
if user_id:
user = User.get(user_id)
return_value = success('All profile values have been updated.')
else:
user = User()
user.insert()
return_value = success('User created.')
if not payload.get('password'):
return jsonify(failure('You must set a password for new users'))
if not payload.get('email'):
return jsonify(failure('You must set an email for new users'))
if not payload.get('name'):
return jsonify(failure('You must set a name for new users'))
for key in payload:
if key == 'password':
user.set_password(payload[key])
elif key != 'user_id':
setattr(user, key, payload[key])
g.user.insert()
safe_commit()
return jsonify(return_value)
示例3: create_user
# 需要导入模块: import User [as 别名]
# 或者: from User import insert [as 别名]
def create_user():
return_value = success('The user was created.')
payload = get_payload(request)
user = User(username=payload.get('email'), password=payload.get('password'),
name=payload.get('name'))
valid = user.validate()
if valid['success']:
user.insert()
safe_commit()
return_value['id'] = user.id
else:
del(user)
return_value = valid
return jsonify(return_value)