示例#1
0
 def find_by_url(cls, url: str) -> Optional['Store']:
     for i in range(len(url), 0, -1):
         result = Store.find_one_by_url_prefix(url_prefix=url[:i])
         if result:
             logger.debug('Found a match {} for url {}'.format(result, url))
             return result
     raise store_errors.StoreNotFoundError(
         message='No store found matching URL "{}"'.format(url))
示例#2
0
    def find_one_by_name(cls, name: str) -> Optional['Store']:
        result = pricing.db.find_one(
            collection_name=pricing.configuration['collections']
            ['stores_collection'],
            query={'name': name})
        if result is None:
            message = 'No store found matching name: {}'.format(name)
            logger.warning(message)
            raise store_errors.StoreNotFoundError(message=message)

        result = cls.wrap(store_dict=result)
        return result
示例#3
0
    def get_all_stores(cls):
        query = {}
        results = pricing.db.find(
            collection_name=pricing.configuration['collections']
            ['stores_collection'],
            query=query)
        if results is None:
            message = 'No store found matching query: '.format(query)
            logger.warning(message)
            raise store_errors.StoreNotFoundError(message=message)

        results = [cls.wrap(store_dict=result) for result in results]
        return results