本文整理汇总了Python中app.user.models.User.save方法的典型用法代码示例。如果您正苦于以下问题:Python User.save方法的具体用法?Python User.save怎么用?Python User.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app.user.models.User
的用法示例。
在下文中一共展示了User.save方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_get_by_id
# 需要导入模块: from app.user.models import User [as 别名]
# 或者: from app.user.models.User import save [as 别名]
def test_get_by_id(self):
"""Get user by ID."""
user = User('foo', '[email protected]')
user.save()
retrieved = User.get_by_id(user.id)
assert retrieved == user
示例2: register
# 需要导入模块: from app.user.models import User [as 别名]
# 或者: from app.user.models.User import save [as 别名]
def register():
form = RegistrationForm()
if form.validate_on_submit():
user = User(username=form.username.data,
password=form.password.data)
user.save()
return redirect(url_for('auth.login'))
return render_template('auth/register.html', form=form)
示例3: create_user
# 需要导入模块: from app.user.models import User [as 别名]
# 或者: from app.user.models.User import save [as 别名]
def create_user():
email = request.form.get('email')
name = request.form.get('name')
if not email or not name:
abort(400)
try:
user = User.objects().get(email=email)
except DoesNotExist:
user = User(email=email, name=name)
user.save()
except MultipleObjectsReturned:
abort(500)
except NotUniqueError:
abort(203)
resp = {'user': user.dict()}
return jsonify(resp)
示例4: create_admin_user
# 需要导入模块: from app.user.models import User [as 别名]
# 或者: from app.user.models.User import save [as 别名]
def create_admin_user(username, password):
"""Creates the administrator user.
Returns the created admin user.
:param username: The username of the user.
:param password: The password of the user.
"""
user = User.query.filter_by(username=username).first()
if user:
return user
user = User()
role = Role.query.filter_by(permissions=Permission.ADMINISTER).first()
user.role = role
user.username = username
user.password = password
user.save()
return user
示例5: test_password_is_nullable
# 需要导入模块: from app.user.models import User [as 别名]
# 或者: from app.user.models.User import save [as 别名]
def test_password_is_nullable(self):
user = User(username='foo', email='[email protected]')
user.save()
assert user.password is None
示例6: test_created_at_defaults_to_datetime
# 需要导入模块: from app.user.models import User [as 别名]
# 或者: from app.user.models.User import save [as 别名]
def test_created_at_defaults_to_datetime(self):
user = User(username='foo', email='[email protected]')
user.save()
assert bool(user.created_at)
assert isinstance(user.created_at, dt.datetime)