Exemplo n.º 1
0
    def sgrp(self, value):
        """Store 'search groups' keywords.

        The keywords are stored in tuple with one keywords per element.
        """

        self._sgrp = Parser.format_search_keywords(value)  # pylint: disable=attribute-defined-outside-init
Exemplo n.º 2
0
    def scat(self, value):
        """Store content categories.

        The ``scat`` option defines the content category or categories for
        the operation. If operation is ``create``, there must be only one
        category. If the operation is ``search`` or the operation requires
        searching content, there can be multiple values.

        The keywords are stored in tuple with one keywords per element.

        If any of the given categories is incorrect, an error is set. This
        is a simple error handling that fails the operation instead of trying
        to recover it. An unknown value is set to the ``scat`` option in case
        of a failure because it minimizes the search results in the error
        scenario. If all categories would be searched with errors, it could
        lead to a large search results sets in case of failures.
        """

        scat = Parser.format_search_keywords(value)
        if not scat:
            scat = (Const.SNIPPET, )
        if Const.ALL_CATEGORIES in scat:
            scat = Const.CATEGORIES

        if not set(scat).issubset(Const.CATEGORIES):
            Cause.push(Cause.HTTP_BAD_REQUEST, 'content categories: {} :are not a subset of: {}'.format(self._format_scat(scat), Const.CATEGORIES))  # noqa pylint: disable=line-too-long
            scat = (Const.UNKNOWN_CATEGORY, )

        if self.operation == self.CREATE and (Const.UNKNOWN_CATEGORY in scat
                                              or len(scat) != 1):
            Cause.push(Cause.HTTP_BAD_REQUEST, 'content category must be unique when content is created: {}'.format(self._format_scat(scat)))  # noqa pylint: disable=line-too-long

        self._scat = scat  # pylint: disable=attribute-defined-outside-init