diff --git a/helpdesk/lib.py b/helpdesk/lib.py index 97977f24..3dfe5448 100644 --- a/helpdesk/lib.py +++ b/helpdesk/lib.py @@ -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: diff --git a/helpdesk/views/staff.py b/helpdesk/views/staff.py index 78502243..021ac329 100644 --- a/helpdesk/views/staff.py +++ b/helpdesk/views/staff.py @@ -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)