How to use the djangoql.compat.text_type function in djangoql

To help you get started, we’ve selected a few djangoql examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ivelum / djangoql / djangoql / schema.py View on Github external
'Field "%s" can be compared to dates in '
                '"YYYY-MM-DD" format, but not to %s' % (
                    self.name,
                    repr(value),
                )
            )

    def get_lookup_value(self, value):
        if not value:
            return None
        return datetime.strptime(value, '%Y-%m-%d').date()


class DateTimeField(DjangoQLField):
    type = 'datetime'
    value_types = [text_type]
    value_types_description = 'timestamps in "YYYY-MM-DD HH:MM" format'

    def validate(self, value):
        super(DateTimeField, self).validate(value)
        try:
            self.get_lookup_value(value)
        except ValueError:
            raise DjangoQLSchemaError(
                'Field "%s" can be compared to timestamps in '
                '"YYYY-MM-DD HH:MM" format, but not to %s' % (
                    self.name,
                    repr(value),
                )
            )

    def get_lookup_value(self, value):
github ivelum / djangoql / djangoql / admin.py View on Github external
def djangoql_error_message(self, exception):
        if isinstance(exception, ValidationError):
            msg = exception.messages[0]
        else:
            msg = text_type(exception)
        return render_to_string('djangoql/error_message.html', context={
            'error_message': msg,
        })
github ivelum / djangoql / djangoql / schema.py View on Github external
def model_label(self, model):
        return text_type(model._meta)
github ivelum / djangoql / djangoql / schema.py View on Github external
field_kwargs['related_model'] = field.related_model
        else:
            field_cls = self.get_field_cls(field)
        if isinstance(field, (ManyToOneRel, ManyToManyRel, ForeignObjectRel)):
            # Django 1.8 doesn't have .null attribute for these fields
            field_kwargs['nullable'] = True
        else:
            field_kwargs['nullable'] = field.null
        field_kwargs['suggest_options'] = (
            field.name in self.suggest_options.get(model, [])
        )
        field_instance = field_cls(**field_kwargs)
        # Check if suggested options conflict with field type
        if field_cls != StrField and field_instance.suggest_options:
            for option in field_instance.get_options():
                if isinstance(option, text_type):
                    # Convert to StrField
                    field_instance = StrField(**field_kwargs)
        return field_instance
github ivelum / djangoql / djangoql / ast.py View on Github external
def __str__(self):
        children = []
        for k, v in self.__dict__.items():
            if isinstance(v, (list, tuple)):
                v = '[%s]' % ', '.join([text_type(v) for v in v if v])
            children.append('%s=%s' % (k, v))
        return '<%s%s%s>' % (
            self.__class__.__name__,
            ': ' if children else '',
            ', '.join(children),
        )
github ivelum / djangoql / djangoql / parser.py View on Github external
def p_error(self, token):
        if token is None:
            self.raise_syntax_error('Unexpected end of input')
        else:
            fragment = text_type(token.value)
            if len(fragment) > 20:
                fragment = fragment[:17] + '...'
            self.raise_syntax_error(
                'Syntax error at %s' % repr(fragment),
                token=token,
            )