class Favorites(RequestHandler): _path_extractor = None _favorite_data = None def set_default_headers(self): if ADD_CORS_HEADERS: self.set_header("Access-Control-Allow-Origin", "*") self.set_header('Access-Control-Allow-Methods', 'GET, POST, OPTIONS') self.set_header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept') def initialize(self): self._path_extractor = PathExtractor(self) self._favorite_data = FavoriteData() self._favorite_data.open_connection() @asynchronous @engine def get(self, user_id, *args, **kwargs): favorites = self._favorite_data.find( self._path_extractor.user_id(user_id) ) self.set_status(200) self.set_header("Content-Type", "application/json") self.finish( dumps( { "favorites": [ x["_id"]["product_id"] for x in favorites ], "version": __version__ } ) )
class Favorites(RequestHandler): _path_extractor = None _favorite_data = None def set_default_headers(self): if ADD_CORS_HEADERS: self.set_header("Access-Control-Allow-Origin", "*") self.set_header('Access-Control-Allow-Methods', 'GET, POST, OPTIONS') self.set_header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept') def initialize(self): self._path_extractor = PathExtractor(self) self._favorite_data = FavoriteData() self._favorite_data.open_connection() @asynchronous @engine def get(self, user_id, *args, **kwargs): favorites = self._favorite_data.find( self._path_extractor.user_id(user_id)) self.set_status(200) self.set_header("Content-Type", "application/json") self.finish( dumps({ "favorites": [x["_id"]["product_id"] for x in favorites], "version": __version__ }))
class Favorites(Base): _favorite_data = None def initialize(self): self._favorite_data = FavoriteData() self._favorite_data.open_connection() def _get_from_service(self, _id): try: app_log.debug("Favorites,get_from_service,_id=%s", _id) favorites = self._favorite_data.find(_id) return [str(x["_id"]["product_id"]) for x in favorites] except: app_log.error("get_from_service,_id=%s", _id) return None