本文整理汇总了Python中app.users.models.User.save方法的典型用法代码示例。如果您正苦于以下问题:Python User.save方法的具体用法?Python User.save怎么用?Python User.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app.users.models.User
的用法示例。
在下文中一共展示了User.save方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: register
# 需要导入模块: from app.users.models import User [as 别名]
# 或者: from app.users.models.User import save [as 别名]
def register():
email = request.form['email']
username = request.form['username']
password = request.form['password'].encode('utf8')
salt = generate_random_salt()
password_hash = generate_password_hash(password, salt)
# Check if email already exist in database
# if account does not exist create account in database
if User.objects(email=email).first() == None:
user = User(email=email)
user.accounts['internal'] = {"username":username, "password_hash":password_hash, \
"salt":salt}
user.save()
ret = json_util.dumps({"message":"account created", "status":"success"})
resp = Response(response=ret,
status=201,
mimetype="application/json")
return resp
else:
ret = json_util.dumps({"message":"Email already exist in database"})
resp = Response(response=ret,
status=200,
mimetype="application/json")
return resp
示例2: register
# 需要导入模块: from app.users.models import User [as 别名]
# 或者: from app.users.models.User import save [as 别名]
def register():
"""
Registration Form
"""
form = RegisterForm(request.form)
if form.validate_on_submit():
# create an user instance not yet stored in the database
user = User(username=form.name.data,
email=form.email.data,
password=generate_password_hash(form.password.data)
)
#current_user=True)
# Insert the record in our database and commit it
try:
user.save()
except errors.NotUniqueError:
return render_template("users/register.html",
form=form,
duplicate=True,
user=None)
except:
raise
# Log the user in, as he now has an id
session['user_id'] = str(user.id)
session['user'] = user.username
print "session user_id: %s" % (str(user.id))
# flash will display a message to the user
#flash('Thanks for registering')
# redirect user to the 'home' method of the user module.
return redirect(url_for('users.home'))
return render_template("users/register.html", form=form, user=None)
示例3: create
# 需要导入模块: from app.users.models import User [as 别名]
# 或者: from app.users.models.User import save [as 别名]
def create():
args = ['username', 'realname', 'email', 'pw', 'phone']
result = ''
try:
for i in args:
assert i in request.args, 'missing ' + i
assert len(list(graph_db.find("User","username",request.args['username']))) == 0, "user already exists"
assert len(list(graph_db.find("User","email",request.args['email']))) == 0, "email already exists"
u = User(username=request.args['username'],
realname=request.args['realname'],
email=request.args['email'],
password=hash_pw(request.args['pw']),
phone=request.args['phone'])
while True:
u.userid = randint(app.config['UID_START'],app.config['UID_END'])
if len(list(graph_db.find("User","id",u.userid))) == 0: break
u.save()
result = "user %s created" % u.userid
except AssertionError, e:
result = str(e)
示例4: TimerTest
# 需要导入模块: from app.users.models import User [as 别名]
# 或者: from app.users.models.User import save [as 别名]
class TimerTest(TestCase):
ARRIVED_AT = timezone.make_aware(datetime(2015, 10, 1, 9, 50))
LEFT_AT = timezone.make_aware(datetime(2015, 10, 1, 19, 30))
def setUp(self):
self.user = User(name="test")
self.user.save()
def test_arrived(self):
manager = TimeManager(self.user)
manager.arrived(self.ARRIVED_AT)
day_log = DayLog.find_or_create(self.user, self.ARRIVED_AT.date())
timer_logs = TimerLog.findAll(self.user, self.ARRIVED_AT.date())
self.assertEqual(day_log.arrived_at, self.ARRIVED_AT)
self.assertEqual(len(timer_logs), 1)
self.assertEqual(timer_logs[0].action_type, TimerLog.ARRIVED)
self.assertEqual(timer_logs[0].time, self.ARRIVED_AT)
def test_left(self):
manager = TimeManager(self.user)
manager.left(self.LEFT_AT)
day_log = DayLog.find_or_create(self.user, self.LEFT_AT.date())
timer_logs = TimerLog.findAll(self.user, self.LEFT_AT.date())
self.assertEqual(day_log.left_at, self.LEFT_AT)
self.assertEqual(len(timer_logs), 1)
self.assertEqual(timer_logs[0].action_type, TimerLog.LEFT)
self.assertEqual(timer_logs[0].time, self.LEFT_AT)
def test_arrive_and_left(self):
manager = TimeManager(self.user)
manager.arrived(self.ARRIVED_AT)
manager.left(self.LEFT_AT)
day_log = DayLog.find_or_create(self.user, self.ARRIVED_AT.date())
timer_logs = TimerLog.findAll(self.user, self.ARRIVED_AT.date())
self.assertEqual(day_log.arrived_at, self.ARRIVED_AT)
self.assertEqual(day_log.left_at, self.LEFT_AT)
self.assertEqual(day_log.work_time, 520)
self.assertEqual(len(timer_logs), 2)
示例5: register
# 需要导入模块: from app.users.models import User [as 别名]
# 或者: from app.users.models.User import save [as 别名]
def register():
"""
Registration Form
"""
form = RegisterForm(request.form)
if form.validate_on_submit():
# create an user instance not yet stored in the database
user = User(username=form.name.data, email=form.email.data, \
password=generate_password_hash(form.password.data))
# Insert the record in our database and commit it
user.save()
#db.session.add(user)
#db.session.commit()
# Log the user in, as he now has an id
session['user_id'] = str(user.id)
print "session user_id: %s" % (str(user.id))
# flash will display a message to the user
#flash('Thanks for registering')
# redirect user to the 'home' method of the user module.
return redirect(url_for('users.home'))
return render_template("users/register.html", form=form)