Пример #1
0
    def _comparator_func(self, obj):
        (value, ) = cmp(self.attr)(obj)

        if self.verb:
            return self.apply_verb(value)
        else:
            return value == self.value
Пример #2
0
    def distinct(self, *attrs):
        if not attrs:
            attrs = self._attrs - {'created', 'updated'}

        meta = [(cmp(*attrs)(obj), obj) for obj in self.reverse()]

        return type(self)(OrderedDict(meta).values())
Пример #3
0
    def values(self, *attrs):
        if not attrs:
            attrs = self._attrs

        return type(self)(
            (dict(zip(attrs, obj)) for obj in map(cmp(*attrs), self)),
            model=self.model)
Пример #4
0
    def order_by(self, *fields: Fields):
        if not fields:
            raise AttributeError

        return type(self)(
            sorted(self, key=cmp(*fields)),
            model=self.model
        )
Пример #5
0
    def values(self, *fields: Fields) -> 'QuerySet':
        if not fields:
            fields = self._attrs

        return type(self)(
            (
                dict(zip(fields, obj))
                for obj in map(cmp(*fields), self)
            ),
            model=self.model
        )
Пример #6
0
    def values_list(self, *attrs, flat=False):
        # TODO: Allow order_by on values_list

        if not attrs:
            attrs = self._attrs

        if len(attrs) > 1 and flat:
            raise TypeError(
                '/flat/ is not valid when values_list is called with more than '
                'one field.')

        return type(self)((flatmap if flat else map)(cmp(*attrs), self))
Пример #7
0
    def distinct(self, *fields: Fields) -> 'QuerySet':
        if not fields:
            fields = self._attrs - {'created', 'updated'}

        meta = [
            (cmp(*fields)(obj), obj)
            for obj in self.reverse()
        ]

        return type(self)(
            OrderedDict(meta).values(),
            model=self.model
        ).reverse()
Пример #8
0
    def values_list(self, *fields: Fields, flat: bool=False) -> 'QuerySet':
        # TODO: Allow order_by on values_list

        if not fields:
            fields = self._attrs

        if len(fields) > 1 and flat:
            raise TypeError(
                '/flat/ is not valid when values_list is called with more than '
                'one field.'
            )

        return type(self)(
            (flatmap if flat else map)(cmp(*fields), self),
            model=self.model
        )
Пример #9
0
    def order_by(self, *attrs):
        if not attrs:
            raise AttributeError

        return type(self)(sorted(self, key=cmp(*attrs)))