Exemplo n.º 1
0
    def _get_field_or_error(self, field_name):
        """
        Check that the attempted filter field is valid

        :raises InvalidFilterError: If the filter field is not valid
        """
        predeclared_fields = self.serializer_class._declared_fields
        initialized_fields = self.get_serializer().fields if hasattr(
            self, 'get_serializer') else {}
        serializer_fields = predeclared_fields.copy()
        # Merges fields that were declared on serializer with fields that may have been dynamically added
        serializer_fields.update(initialized_fields)

        if field_name not in serializer_fields:
            raise InvalidFilterError(
                detail="'{0}' is not a valid field for this endpoint.".format(
                    field_name))
        if field_name not in getattr(self.serializer_class,
                                     'filterable_fields', set()):
            raise InvalidFilterFieldError(parameter='filter', value=field_name)
        field = serializer_fields[field_name]
        # You cannot filter on deprecated fields.
        if isinstance(field, ShowIfVersion) and utils.is_deprecated(
                self.request.version, field.min_version, field.max_version):
            raise InvalidFilterFieldError(parameter='filter', value=field_name)
        return serializer_fields[field_name]
Exemplo n.º 2
0
    def _get_field_or_error(self, field_name):
        """
        Check that the attempted filter field is valid

        :raises InvalidFilterError: If the filter field is not valid
        """
        serializer_class = self.serializer_class
        if field_name not in serializer_class._declared_fields:
            raise InvalidFilterError(detail="'{0}' is not a valid field for this endpoint.".format(field_name))
        if field_name not in getattr(serializer_class, 'filterable_fields', set()):
            raise InvalidFilterFieldError(parameter='filter', value=field_name)
        field = serializer_class._declared_fields[field_name]
        # You cannot filter on deprecated fields.
        if isinstance(field, ShowIfVersion) and utils.is_deprecated(self.request.version, field.min_version, field.max_version):
            raise InvalidFilterFieldError(parameter='filter', value=field_name)
        return serializer_class._declared_fields[field_name]
Exemplo n.º 3
0
    def _get_field_or_error(self, field_name):
        """
        Check that the attempted filter field is valid

        :raises InvalidFilterError: If the filter field is not valid
        """
        if field_name not in self.serializer_class._declared_fields:
            raise InvalidFilterError(detail="'{0}' is not a valid field for this endpoint.".format(field_name))
        if field_name not in getattr(self.serializer_class, 'filterable_fields', set()):
            raise InvalidFilterFieldError(parameter='filter', value=field_name)
        return self.serializer_class._declared_fields[field_name]