本文整理汇总了Python中models.user.User.save方法的典型用法代码示例。如果您正苦于以下问题:Python User.save方法的具体用法?Python User.save怎么用?Python User.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.user.User
的用法示例。
在下文中一共展示了User.save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: facebook_authorized
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import save [as 别名]
def facebook_authorized():
resp = facebook.authorized_response()
if resp is None:
return 'Access denied: reason=%s error=%s' % (
request.args['error_reason'],
request.args['error_description']
)
if isinstance(resp, OAuthException):
return 'Access denied: %s' % resp.message
session['oauth_token'] = (resp['access_token'], '')
me = facebook.get('/me')
username = me.data['name']
email= me.data['email']
user = User.objects(email=email).first()
if user:
session['user_id'] = str(user.id)
else:
user = User()
user.email = email
user.username = username
user.save()
Inventory(owner=user.to_dbref(),
name='Basic',
is_basic=True).save()
return redirect('/')
示例2: post_app
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import save [as 别名]
def post_app():
#print('form')
signed_request = request.form.get('signed_request')
data = facebook_tools.parse_signed_request(signed_request,
FACEBOOK_APP_SECRET)
print(signed_request)
print(data)
session['oauth_token'] = (data['oauth_token'],'')
me = facebook.get('/me')
username = me.data['name']
email= me.data['email']
user = User.objects(email=email).first()
if user:
session['user_id'] = str(user.id)
else:
user = User()
user.email = email
user.username = username
user.save()
Inventory(owner=user.to_dbref(),
name='Basic',
is_basic=True).save()
return send_file('public/index.html')
示例3: createUser
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import save [as 别名]
def createUser(self, args):
self._start(args)
while True:
username = raw_input('Enter email address: ')
if User.users().get(username=username):
print('Username already exists. Please pick another username.')
else:
break
print('username: %s' % username)
while True:
is_admin = raw_input('Admininstrative user? (y/N): ')
if (len(is_admin) == 0) or (is_admin.upper() == 'N'):
admin = False
break
elif is_admin.upper() == 'Y':
admin = True
break
while True:
password_1 = getpass.getpass('Enter password: ')
password_2 = getpass.getpass('Re-enter password: ')
if password_1 != password_2:
print('Passwords do not match.')
else:
break
user = User(username, password_1, admin)
user.save()
# Db.instance().insert_user(username, password_1, admin)
print('Successfully created user %s' % username)
示例4: test_does_not_find_by_invalid_credentials
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import save [as 别名]
def test_does_not_find_by_invalid_credentials(self):
user = User(email_address="[email protected]",
password="password")
user.save()
get_user = User.find_by_credentials(email_address="[email protected]",
password="WrongPassword")
self.assertIsNone(get_user)
示例5: create_user
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import save [as 别名]
def create_user(self):
user = User()
user.username = 'test_username'
user.password = 'test_password'
user.name = 'test_name'
user.email = '[email protected]'
user.save()
return user
示例6: users
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import save [as 别名]
def users(eid):
if eid:
if request.method == 'POST':
user = User(eid = eid).from_form(request.form)
user.save()
else:
user = User().get(eid = eid)
return menu.render('form.html', form = user.as_form())
else:
return menu.render('list.html', items = User().all())
示例7: test_delete_user_wrong
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import save [as 别名]
def test_delete_user_wrong(self):
"""the id does not match a user"""
user_args = {"first_name": "quokka", "id": "QO",
"email": "[email protected]", "password": "1234"}
user = User(**user_args)
user.save()
rv = self.app.delete('{}/users/{}/'.format(self.path, "noID"),
follow_redirects=True)
self.assertEqual(rv.status_code, 404)
storage.delete(user)
示例8: testRawUserSave
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import save [as 别名]
def testRawUserSave(self):
user = User(firstName="John", lastName="Skauge", userName="John", password="MyPassword")
# noinspection PyUnresolvedReferences
self.assertFalse(user.id)
user.save()
self.assertTrue(user.id)
user.delete()
#this will throw a DoesNotExist error, hence the @unittest.expectedFailure
user = User.objects.get(id=user.id)
示例9: createUser
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import save [as 别名]
def createUser():
user = User({
"username": request.form.get('username'),
"email": request.form.get('email'),
"password": request.form.get('password'),
"created": time.time()
})
user.save()
response = { "success": True, "user": user.__dict__ }
return dumps(response)
示例10: create_user
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import save [as 别名]
def create_user(self, data):
try:
province =self.provinces[data[1]]
except:
province=0
u=User()
u.uid=data[0]
u.province=data[1]
u.gender=data[2]
u.verified=data[3]
u.save() # store to mongo
示例11: test_update_user_bad_id
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import save [as 别名]
def test_update_user_bad_id(self):
"""test update with no matching id"""
user_args = {"first_name": "quokka", "id": "QO",
"email": "[email protected]", "password": "1234"}
user = User(**user_args)
user.save()
rv = self.app.put('{}/users/{}/'.format(self.path, "noID"),
content_type="application/json",
data=json.dumps({"id": "Z"}),
follow_redirects=True)
self.assertEqual(rv.status_code, 404)
storage.delete(user)
示例12: post
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import save [as 别名]
def post(self):
email = self.get_argument('email', '')
form = UserForm(self.request.arguments)
if not form.validate():
self.render('auth/signup.html', error_message='', form=form)
elif User.exists_email(email):
error_message = '既に存在するメールアドレスです。'
self.render('auth/signup.html', error_message=error_message, form=form)
else:
user = User(**form.data)
user.save()
self.redirect(self.reverse_url('login'))
示例13: test_update_user_bad_json
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import save [as 别名]
def test_update_user_bad_json(self):
"""test update with ill formed json"""
user_args = {"first_name": "quokka", "id": "QO2",
"email": "[email protected]", "password": "1234"}
user = User(**user_args)
user.save()
rv = self.app.put('{}/users/{}/'.format(self.path, user.id),
content_type="application/json",
data={"id": "Z"},
follow_redirects=True)
self.assertEqual(rv.status_code, 400)
self.assertEqual(rv.get_data(), b"Not a JSON")
storage.delete(user)
示例14: test_delete_user
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import save [as 别名]
def test_delete_user(self):
"""test delete a user"""
user_args = {"first_name": "quokka", "id": "QO",
"email": "[email protected]", "password": "1234"}
user = User(**user_args)
user.save()
rv = self.app.delete('{}/users/{}/'.format(
self.path, user_args["id"]),
follow_redirects=True)
self.assertEqual(rv.status_code, 200)
self.assertEqual(rv.headers.get("Content-Type"), "application/json")
json_format = getJson(rv)
self.assertEqual(json_format, {})
self.assertIsNone(storage.get("User", user_args["id"]))
示例15: run
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import save [as 别名]
def run(self):
User.drop_collection()
Message.drop_collection()
user1 = User()
user2 = User()
user3 = User()
user4 = User()
user1.firstName = "John"
user1.lastName = "Doe"
user1.birthDate = datetime.now()
user1.userName = "Creator"
user1.passHash = user1.userName
user2.firstName = "Jane"
user2.lastName = "Doe"
user2.birthDate = datetime.now()
user2.userName = "Nemesis"
user2.passHash = user2.userName
user3.firstName = "Michelle"
user3.lastName = "Nielsen"
user3.birthDate = datetime.now()
user3.userName = "GoldDigger86"
user3.passHash = user3.userName
user4.firstName = "Leif"
user4.lastName = "Paulsen"
user4.birthDate = datetime.now()
user4.userName = "The_Artist"
user4.passHash = user4.userName
user1.save()
user2.save()
user3.save()
user4.save()
message1 = Message()
message1.subject = "First message"
message1.text = "This is the first message ever in the system. Hello Jane this is John, how are you?"
message1.sender = user1
message1.receiver = user2
message1.save()
message2 = Message()
message2.subject = "Second message"
message2.text = "This is the second message ever in the system. Hello Jane this is Åge, how are you?"
message2.sender = user4
message2.receiver = user2
message2.save()
message3 = Message()
message3.subject = "Second message"
message3.text = "This is the Third message ever in the system. Hello Jane this is Åge, how are you?"
message3.sender = user4
message3.receiver = user1
message3.save()