Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def completion_demo(request):
q = request.GET.get('q', '')
error = ''
query = User.objects.all().order_by('username')
if q:
try:
query = apply_search(query, q, schema=UserQLSchema)
except DjangoQLError as e:
query = query.none()
error = str(e)
return render(request, 'completion_demo.html', context={
'q': q,
'error': error,
'search_results': query,
'introspections': json.dumps(UserQLSchema(query.model).as_dict()),
})
self.line = line
self.column = column
super(DjangoQLError, self).__init__(message)
def __str__(self):
message = super(DjangoQLError, self).__str__()
if self.line:
position_info = 'Line %s' % self.line
if self.column:
position_info += ', col %s' % self.column
return '%s: %s' % (position_info, message)
else:
return message
class DjangoQLSyntaxError(DjangoQLError):
pass
class DjangoQLLexerError(DjangoQLSyntaxError):
pass
class DjangoQLParserError(DjangoQLSyntaxError):
pass
class DjangoQLSchemaError(DjangoQLError):
pass
not self.djangoql_search_enabled(request)
):
return super(DjangoQLSearchMixin, self).get_search_results(
request=request,
queryset=queryset,
search_term=search_term,
)
use_distinct = False
if not search_term:
return queryset, use_distinct
try:
return (
apply_search(queryset, search_term, self.djangoql_schema),
use_distinct,
)
except (DjangoQLError, ValueError, FieldError, ValidationError) as e:
msg = self.djangoql_error_message(e)
messages.add_message(request, messages.WARNING, msg)
return queryset.none(), use_distinct
def __str__(self):
message = super(DjangoQLError, self).__str__()
if self.line:
position_info = 'Line %s' % self.line
if self.column:
position_info += ', col %s' % self.column
return '%s: %s' % (position_info, message)
else:
return message
| Q(impact__icontains=queryterm)
)
elif re.match(URL_QUERY_PATTERN, queryterm):
queryset = queryset.filter(
Q(docs_url__icontains=queryterm)
| Q(library_url__icontains=queryterm)
| Q(health_check_url__icontains=queryterm)
)
else:
try:
queryset = apply_search(
queryset, queryterm, models.LibrarySQLSchema
)
except DjangoQLError:
log.exception("libraries.query_error", queryterm=queryterm)
return self.model.objects.none()
return queryset.order_by("name")
return message
class DjangoQLSyntaxError(DjangoQLError):
pass
class DjangoQLLexerError(DjangoQLSyntaxError):
pass
class DjangoQLParserError(DjangoQLSyntaxError):
pass
class DjangoQLSchemaError(DjangoQLError):
pass
| Q(owner__icontains=queryterm)
| Q(status__icontains=queryterm)
| Q(impact__icontains=queryterm)
)
elif re.match(URL_QUERY_PATTERN, queryterm):
queryset = queryset.filter(
Q(docs_url__icontains=queryterm)
| Q(environment__health_check_url__icontains=queryterm)
| Q(environment__service_urls__icontains=queryterm)
)
else:
try:
queryset = apply_search(queryset, queryterm, models.ServiceQLSchema)
except DjangoQLError:
log.exception("services.query_error", queryterm=queryterm)
return self.model.objects.none()
return queryset.order_by("name")