Merge pull request #415 from mhannig/fix-broken-keyword-search

JSON Serialization broke Keyword-Searches
This commit is contained in:
Ross Poulton 2016-07-05 08:48:10 +10:00 committed by GitHub
commit f2e497c3c6
2 changed files with 16 additions and 14 deletions

View File

@ -21,6 +21,7 @@ import logging
logger = logging.getLogger('helpdesk')
from django.utils.encoding import smart_str
from django.db.models import Q
def send_templated_mail(template_name, email_context, recipients, sender=None, bcc=None, fail_silently=False, files=None):
"""
@ -177,17 +178,25 @@ def apply_query(queryset, params):
params is a dictionary that contains the following:
filtering: A dict of Django ORM filters, eg:
{'user__id__in': [1, 3, 103], 'title__contains': 'foo'}
other_filter: Another filter of some type, most likely a
set of Q() objects.
search_string: A freetext search string
sorting: The name of the column to sort by
"""
for key in params['filtering'].keys():
filter = {key: params['filtering'][key]}
queryset = queryset.filter(**filter)
if params.get('other_filter', None):
# eg a Q() set
queryset = queryset.filter(params['other_filter'])
search = params.get('search_string', None)
if search:
qset = (
Q(title__icontains=search) |
Q(description__icontains=search) |
Q(resolution__icontains=search) |
Q(submitter_email__icontains=search)
)
queryset = queryset.filter(qset)
sorting = params.get('sorting', None)
if sorting:

View File

@ -724,7 +724,7 @@ def ticket_list(request):
'sorting': None,
'sortreverse': False,
'keyword': None,
'other_filter': None,
'search_string': None,
}
from_saved_query = False
@ -834,15 +834,8 @@ def ticket_list(request):
q = request.GET.get('q', None)
if q:
qset = (
Q(title__icontains=q) |
Q(description__icontains=q) |
Q(resolution__icontains=q) |
Q(submitter_email__icontains=q)
)
context = dict(context, query=q)
query_params['other_filter'] = qset
query_params['search_string'] = q
### SORTING
sort = request.GET.get('sort', None)