Esempio n. 1
0
    def __init__(self, factory, *parts, **kwargs):
        self.factory = IQueryViewFactory(factory)

        self.parts = []
        self.operators = []
        if len(parts) == 0:
            raise ValueError("Empty query?")

        for part, index in zip(parts, range(len(parts))):
            if index % 2 == 0:
                if not IPlanBuilder.providedBy(part):
                    raise ValueError("Element at index %d should be a Query or"
                                     " condition, %r given" % (index, part))
                for query in part.get_basic_queries():
                    if not factory.has_field(query[0]):
                        raise ValueError("Unknown query field: '%s'" %
                                         (query[0], ))
                self.parts.append(part)

            if index % 2 == 1:
                if not isinstance(part, Operator):
                    raise ValueError("Element at index %d should be an "
                                     "Operator, %r given" % (index, part))
                self.operators.append(part)

        sorting = kwargs.pop('sorting', None)
        self.set_sorting(sorting)

        if kwargs:
            raise ValueError('Uknown keywords: %s' % (kwargs.keys(), ))
Esempio n. 2
0
File: query.py Progetto: f3at/feat
    def __init__(self, *parts, **kwargs):
        self.parts = []
        self.operators = []
        if len(parts) == 0:
            # This is to allow querying with empty query. The default field
            # is the first one defined for this class.
            parts = [Condition(self.default_field, Evaluator.none, None)]

        for index, part in enumerate(parts):
            if index % 2 == 0:
                if not IPlanBuilder.providedBy(part):
                    raise ValueError("Element at index %d should be a Query or" " condition, %r given" % (index, part))
                for query in part.get_basic_queries():
                    if query.field not in self.fields:
                        raise ValueError("Unknown query field: '%s'" % (query.field,))
                self.parts.append(part)

            if index % 2 == 1:
                if not isinstance(part, Operator):
                    raise ValueError("Element at index %d should be an " "Operator, %r given" % (index, part))
                if self.operators and part not in self.operators:
                    raise ValueError(
                        "Sorry, mixing different operators inside"
                        "a query is not currently supported. "
                        "Please use nested queries instead"
                    )
                self.operators.append(part)

        self.include_value = list(kwargs.pop("include_value", list()))

        if not isinstance(self.include_value, (list, tuple)):
            raise ValueError("%r should be a list or tuple" % (self.include_value))

        self.aggregate = kwargs.pop("aggregate", None)

        sorting = kwargs.pop("sorting", None)
        self.set_sorting(sorting)

        if kwargs:
            raise ValueError("Unknown keywords: %s" % (kwargs.keys(),))