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()),
})
def get_search_results(self, request, queryset, search_term):
if (
self.search_mode_toggle_enabled() and
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
Q(name__icontains=queryterm)
| 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(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")
Q(name__icontains=queryterm)
| 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")