本文整理汇总了Python中common.database.Database.find_one方法的典型用法代码示例。如果您正苦于以下问题:Python Database.find_one方法的具体用法?Python Database.find_one怎么用?Python Database.find_one使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类common.database.Database
的用法示例。
在下文中一共展示了Database.find_one方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: from_name
# 需要导入模块: from common.database import Database [as 别名]
# 或者: from common.database.Database import find_one [as 别名]
def from_name(cls, name, **kwargs):
data = Database.find_one(GraphConstants.COLLECTION, {'unique_name': name})
if not data:
raise GraphErrors.GraphNotFoundError("The graph you requested '{}' was not found.".format(name))
data.update(kwargs)
graph = cls.from_json(data)
return graph.run(data)
示例2: login_valid_user
# 需要导入模块: from common.database import Database [as 别名]
# 或者: from common.database.Database import find_one [as 别名]
def login_valid_user(email, password):
"""
:param email: user's email
:param password: user's password
:return: True if valid, False otherwise
"""
userData = Database.find_one("users", {'email': email})
if userData is None:
raise UserNotExistsError("this user does not existed!")
return False
if not Utils.check_hashed_password(password, userData['password']):
raise UserIncorrectPasswordError("Incorrect password!")
return False
return True
示例3: is_login_valid
# 需要导入模块: from common.database import Database [as 别名]
# 或者: from common.database.Database import find_one [as 别名]
def is_login_valid(cls, email, password):
"""
This method verifies that an e-mail/password combo (as sent by the site forms) is valid or not.
Checks that the e-mail exists, and that the password associated to that e-mail is correct.
:param email: The user's email
:param password: A sha512 hashed password
:return: True if valid, False otherwise
"""
user_data = Database.find_one(UserConstants.COLLECTION, {"email": email}) # Password in sha512 -> pbkdf2_sha512
if user_data is None:
# Tell the user that their e-mail doesn't exist
raise UserErrors.UserNotExistsError("Your user does not exist.")
if not Utils.check_hashed_password(password, user_data['password']):
# Tell the user that their password is wrong
raise UserErrors.IncorrectPasswordError("Your password was wrong.")
return cls(**user_data)
示例4: register_user
# 需要导入模块: from common.database import Database [as 别名]
# 或者: from common.database.Database import find_one [as 别名]
def register_user(email, password):
"""
This method registers a user using e-mail and password.
The password already come with sha-512 hash algorithm.
:param email: user's email (might be invalid)
:param password: sha512-hashed password
:return: True if registered successfully, of False otherwise
"""
userData = Database.find_one("users", {'email': email})
if userData is not None:
raise UserExistsError("user already existed!")
#if email is invalid, then what?
if not Utils.email_is_valid(email):
raise UserEmailInvalid("invalid email!")
#hash password, create new object, then insert to db
User(email, Utils.hash_password(password)).save_to_db()
return True
示例5: register_user
# 需要导入模块: from common.database import Database [as 别名]
# 或者: from common.database.Database import find_one [as 别名]
def register_user(email, password):
"""
This method registers a user using e-mail and password.
The password already comes hashed as sha-512.
:param email: user's e-mail (might be invalid)
:param password: sha512-hashed password
:return: True if registered successfully, or False otherwise (exceptions can also be raised)
"""
user_data = Database.find_one(UserConstants.COLLECTION, {"email": email})
if user_data is not None:
raise UserErrors.UserAlreadyRegisteredError("The e-mail you used to register already exists.")
if not Utils.email_is_valid(email):
raise UserErrors.InvalidEmailError("The e-mail does not have the right format.")
user = User(email, Utils.hash_password(password))
user.save_to_db()
return user
示例6: get_by_id
# 需要导入模块: from common.database import Database [as 别名]
# 或者: from common.database.Database import find_one [as 别名]
def get_by_id(cls, _id):
data = Database.find_one("users", {"_id": _id})
if data is not None:
return cls(**data)
return None
示例7: get_by_email
# 需要导入模块: from common.database import Database [as 别名]
# 或者: from common.database.Database import find_one [as 别名]
def get_by_email(cls, email):
data = Database.find_one("users", {"email": email})
if data is not None:
return cls(**data)
示例8: from_mongo
# 需要导入模块: from common.database import Database [as 别名]
# 或者: from common.database.Database import find_one [as 别名]
def from_mongo(cls, id):
blog_data = Database.find_one(collection='blogs', query={'_id': id})
return cls(**blog_data)
示例9: find_by_group
# 需要导入模块: from common.database import Database [as 别名]
# 或者: from common.database.Database import find_one [as 别名]
def find_by_group(cls, group):
return cls(**Database.find_one(AggregatorConstants.COLLECTION, {"group": group}))
示例10: get_by_id
# 需要导入模块: from common.database import Database [as 别名]
# 或者: from common.database.Database import find_one [as 别名]
def get_by_id(cls, _id):
data = Database.find_one('users', {'_id': _id})
if data is not None:
return cls(**data)
示例11: get_by_email
# 需要导入模块: from common.database import Database [as 别名]
# 或者: from common.database.Database import find_one [as 别名]
def get_by_email(cls, email):
data = Database.find_one('users', {'email': email})
if data is not None:
return cls(**data)
示例12: get_by_id
# 需要导入模块: from common.database import Database [as 别名]
# 或者: from common.database.Database import find_one [as 别名]
def get_by_id(self):
data = Database.find_one("users", {"_id": self._id})
if data is not None:
return cls(**data)
示例13: find_by_id
# 需要导入模块: from common.database import Database [as 别名]
# 或者: from common.database.Database import find_one [as 别名]
def find_by_id(cls, _id):
blogData = Database.find_one(collection='blogs', query={'_id': _id})
return cls(**blogData)
示例14: get_from_mongo_by_id
# 需要导入模块: from common.database import Database [as 别名]
# 或者: from common.database.Database import find_one [as 别名]
def get_from_mongo_by_id(cls, _id):
postData = Database.find_one(collection='posts', query={'_id': _id})
return cls(**postData)
示例15: find_by_id
# 需要导入模块: from common.database import Database [as 别名]
# 或者: from common.database.Database import find_one [as 别名]
def find_by_id(cls, id):
return cls(**Database.find_one(UserConstants.COLLECTION, {'_id': id}))