Exemplo n.º 1
0
    def initialize(self, suggestor: Suggestor):
        self.suggestor = suggestor
        self.suggestion_data = SuggestionData()
        self.suggestion_data.open_connection()

        self.param_extractor = ParamExtractor(self)
        self.body_extractor = BodyExtractor(self)
Exemplo n.º 2
0
    def initialize(self):
        self.suggestion_data = SuggestionData()
        self.suggestion_data.open_connection()
        self.suggestion_item_data = SuggestionItemData()
        self.suggestion_item_data.open_connection()

        self.path_extractor = PathExtractor(self)
        self.param_extractor = ParamExtractor(self)
Exemplo n.º 3
0
class SuggestionItems(RequestHandler):
    suggestion_data = None
    suggestion_item_data = None
    path_extractor = None
    param_extractor = None

    def initialize(self):
        self.suggestion_data = SuggestionData()
        self.suggestion_data.open_connection()
        self.suggestion_item_data = SuggestionItemData()
        self.suggestion_item_data.open_connection()

        self.path_extractor = PathExtractor(self)
        self.param_extractor = ParamExtractor(self)

    def data_received(self, chunk):
        pass

    @asynchronous
    def get(self, suggestion_id, *args, **kwargs):
        suggestion = self.suggestion_data.get(self.path_extractor.suggestion_id(suggestion_id))
        start = self.param_extractor.offset()
        end = start + self.param_extractor.page_size()

        items = suggestion["items"][start:end]

        self.set_status(200)
        self.set_header('Content-Type', 'application/json')
        self.add_header('next_offset', end)

        self.write(
            dumps(
                {
                    "offset": self.param_extractor.offset(),
                    # "total_items": len(suggestion["items"]),
                    "items": items,
                    "version": __version__
                }
            )
        )
        self.finish()

        self.suggestion_item_data.insert(
            items,
            self.param_extractor.locale(),
            self.param_extractor.application_id(),
            self.param_extractor.session_id(),
            self.param_extractor.offset(),
            self.param_extractor.page_size()
        )
Exemplo n.º 4
0
    def initialize(self, suggestor: Suggestor):
        self.suggestor = suggestor
        self.suggestion_data = SuggestionData()
        self.suggestion_data.open_connection()

        self.param_extractor = ParamExtractor(self)
        self.body_extractor = BodyExtractor(self)
Exemplo n.º 5
0
    def initialize(self):
        self.suggestion_data = SuggestionData()
        self.suggestion_data.open_connection()
        self.suggestion_item_data = SuggestionItemData()
        self.suggestion_item_data.open_connection()

        self.path_extractor = PathExtractor(self)
        self.param_extractor = ParamExtractor(self)
Exemplo n.º 6
0
class SuggestionItems(RequestHandler):
    suggestion_data = None
    suggestion_item_data = None
    path_extractor = None
    param_extractor = None

    def initialize(self):
        self.suggestion_data = SuggestionData()
        self.suggestion_data.open_connection()
        self.suggestion_item_data = SuggestionItemData()
        self.suggestion_item_data.open_connection()

        self.path_extractor = PathExtractor(self)
        self.param_extractor = ParamExtractor(self)

    def data_received(self, chunk):
        pass

    @asynchronous
    def get(self, suggestion_id, *args, **kwargs):
        suggestion = self.suggestion_data.get(
            self.path_extractor.suggestion_id(suggestion_id))
        start = self.param_extractor.offset()
        end = start + self.param_extractor.page_size()

        items = suggestion["items"][start:end]

        self.set_status(200)
        self.set_header('Content-Type', 'application/json')
        self.add_header('next_offset', end)

        self.write(
            dumps({
                "offset": self.param_extractor.offset(),
                # "total_items": len(suggestion["items"]),
                "items": items,
                "version": __version__
            }))
        self.finish()

        self.suggestion_item_data.insert(items, self.param_extractor.locale(),
                                         self.param_extractor.application_id(),
                                         self.param_extractor.session_id(),
                                         self.param_extractor.offset(),
                                         self.param_extractor.page_size())
Exemplo n.º 7
0
class Root(RequestHandler):
    suggestor = None
    suggestion_data = None
    param_extractor = None
    body_extractor = None

    def initialize(self, suggestor: Suggestor):
        self.suggestor = suggestor
        self.suggestion_data = SuggestionData()
        self.suggestion_data.open_connection()

        self.param_extractor = ParamExtractor(self)
        self.body_extractor = BodyExtractor(self)

    def data_received(self, chunk):
        pass

    def on_finish(self):
        pass

    @asynchronous
    def post(self, *args, **kwargs):
        self.set_header('Content-Type', 'application/json')

        context = self.body_extractor.context()
        suggestion_items = self.suggestor.create_suggestion_items(context)

        # TODO WHAT OF THE CONTEXT DO I STORE HERE? Whole context is a lot context _id could relate to an old

        _id = self.suggestion_data.insert(
            suggestion_items,
            self.param_extractor.locale(),
            context,
            self.param_extractor.user_id(),
            self.param_extractor.application_id(),
            self.param_extractor.session_id()
        )

        self.set_header('Content-Type', 'application/json')
        self.add_header("Location", "/%s" % str(_id))
        self.add_header("_id", str(_id))
        self.set_status(201)
        self.finish()
Exemplo n.º 8
0
class Root(RequestHandler):
    suggestor = None
    suggestion_data = None
    param_extractor = None
    body_extractor = None

    def initialize(self, suggestor: Suggestor):
        self.suggestor = suggestor
        self.suggestion_data = SuggestionData()
        self.suggestion_data.open_connection()

        self.param_extractor = ParamExtractor(self)
        self.body_extractor = BodyExtractor(self)

    def data_received(self, chunk):
        pass

    def on_finish(self):
        pass

    @asynchronous
    def post(self, *args, **kwargs):
        self.set_header('Content-Type', 'application/json')

        context = self.body_extractor.context()
        suggestion_items = self.suggestor.create_suggestion_items(context)

        # TODO WHAT OF THE CONTEXT DO I STORE HERE? Whole context is a lot context _id could relate to an old

        _id = self.suggestion_data.insert(
            suggestion_items, self.param_extractor.locale(), context,
            self.param_extractor.user_id(),
            self.param_extractor.application_id(),
            self.param_extractor.session_id())

        self.set_header('Content-Type', 'application/json')
        self.add_header("Location", "/%s" % str(_id))
        self.add_header("_id", str(_id))
        self.set_status(201)
        self.finish()