From df1abefaaa678cedc4ce0293fd84bb4164c9852d Mon Sep 17 00:00:00 2001 From: Jeremy Kerr Date: Sun, 13 Oct 2013 12:48:21 +0800 Subject: [PATCH] views/base: Include email addresses in submitter autocomplete search Currently, we only search names, which is a problem for Person objects with only an email address set. This change includes the email addresses in the search. Signed-off-by: Jeremy Kerr --- apps/patchwork/tests/__init__.py | 1 + apps/patchwork/tests/person.py | 46 ++++++++++++++++++++++++++++++++ apps/patchwork/views/base.py | 4 ++- 3 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 apps/patchwork/tests/person.py diff --git a/apps/patchwork/tests/__init__.py b/apps/patchwork/tests/__init__.py index d9ed346..e4bf42c 100644 --- a/apps/patchwork/tests/__init__.py +++ b/apps/patchwork/tests/__init__.py @@ -29,3 +29,4 @@ from patchwork.tests.user import * from patchwork.tests.mail_settings import * from patchwork.tests.notifications import * from patchwork.tests.list import * +from patchwork.tests.person import * diff --git a/apps/patchwork/tests/person.py b/apps/patchwork/tests/person.py new file mode 100644 index 0000000..63bbadb --- /dev/null +++ b/apps/patchwork/tests/person.py @@ -0,0 +1,46 @@ +# Patchwork - automated patch tracking system +# Copyright (C) 2013 Jeremy Kerr +# +# This file is part of the Patchwork package. +# +# Patchwork is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# Patchwork is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Patchwork; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +import unittest +from django.test import TestCase +from django.test.client import Client +from patchwork.models import EmailConfirmation, Person, Bundle +import json + +class SubmitterCompletionTest(TestCase): + def setUp(self): + self.people = [ + Person(name = "Test Name", email = "test1@example.com"), + Person(email = "test2@example.com"), + ] + map(lambda p: p.save(), self.people) + + def testNameComplete(self): + response = self.client.get('/submitter/', {'q': 'name'}) + self.assertEquals(response.status_code, 200) + data = json.loads(response.content) + self.assertEquals(len(data), 1) + self.assertEquals(data[0]['fields']['name'], 'Test Name') + + def testEmailComplete(self): + response = self.client.get('/submitter/', {'q': 'test2'}) + self.assertEquals(response.status_code, 200) + data = json.loads(response.content) + self.assertEquals(len(data), 1) + self.assertEquals(data[0]['fields']['email'], 'test2@example.com') diff --git a/apps/patchwork/views/base.py b/apps/patchwork/views/base.py index 82c0368..634e383 100644 --- a/apps/patchwork/views/base.py +++ b/apps/patchwork/views/base.py @@ -25,6 +25,7 @@ from patchwork.requestcontext import PatchworkRequestContext from django.core import serializers, urlresolvers from django.template.loader import render_to_string from django.conf import settings +from django.db.models import Q def projects(request): context = PatchworkRequestContext(request) @@ -87,7 +88,8 @@ def submitter_complete(request): search = request.GET.get('q', '') response = HttpResponse(mimetype = "text/plain") if len(search) > 3: - queryset = Person.objects.filter(name__icontains = search) + queryset = Person.objects.filter(Q(name__icontains = search) | + Q(email__icontains = search)) json_serializer = serializers.get_serializer("json")() json_serializer.serialize(queryset, ensure_ascii=False, stream=response) return response -- 2.39.2