当前位置: 首页>>代码示例>>Python>>正文


Python Database.find_one方法代码示例

本文整理汇总了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)
开发者ID:rc65,项目名称:stacs-hack-2016,代码行数:9,代码来源:graph.py

示例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
开发者ID:tuannvm,项目名称:flask,代码行数:16,代码来源:user.py

示例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)
开发者ID:rc65,项目名称:stacs-hack-2016,代码行数:19,代码来源:user.py

示例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
开发者ID:tuannvm,项目名称:flask,代码行数:19,代码来源:user.py

示例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
开发者ID:rc65,项目名称:stacs-hack-2016,代码行数:21,代码来源:user.py

示例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
开发者ID:marciodasilva,项目名称:blogsite,代码行数:7,代码来源:user.py

示例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)
开发者ID:marciodasilva,项目名称:blogsite,代码行数:6,代码来源:user.py

示例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)
开发者ID:marciodasilva,项目名称:blogsite,代码行数:5,代码来源:blog.py

示例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}))
开发者ID:rc65,项目名称:stacs-hack-2016,代码行数:4,代码来源:aggregator.py

示例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)
开发者ID:asimonia,项目名称:web-blog,代码行数:6,代码来源:user.py

示例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)
开发者ID:asimonia,项目名称:web-blog,代码行数:6,代码来源:user.py

示例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)
开发者ID:PhilDL,项目名称:ipi-flask-project,代码行数:6,代码来源:user.py

示例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)
开发者ID:tuannvm,项目名称:flask,代码行数:5,代码来源:blog.py

示例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)
开发者ID:tuannvm,项目名称:flask,代码行数:5,代码来源:post.py

示例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}))
开发者ID:rc65,项目名称:stacs-hack-2016,代码行数:4,代码来源:user.py


注:本文中的common.database.Database.find_one方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。