]> git.ozlabs.org Git - patchwork/commitdiff
views/base: Include email addresses in submitter autocomplete search
authorJeremy Kerr <jk@ozlabs.org>
Sun, 13 Oct 2013 04:48:21 +0000 (12:48 +0800)
committerJeremy Kerr <jk@ozlabs.org>
Sun, 13 Oct 2013 04:48:21 +0000 (12:48 +0800)
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 <jk@ozlabs.org>
apps/patchwork/tests/__init__.py
apps/patchwork/tests/person.py [new file with mode: 0644]
apps/patchwork/views/base.py

index d9ed3462131cea756f8384e6382b0c97db62ec5b..e4bf42c27046cb8889ff2aaac90ba8046e2c14c8 100644 (file)
@@ -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 (file)
index 0000000..63bbadb
--- /dev/null
@@ -0,0 +1,46 @@
+# Patchwork - automated patch tracking system
+# Copyright (C) 2013 Jeremy Kerr <jk@ozlabs.org>
+#
+# 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')
index 82c036811688cf668b75be22969a86af9771c3ae..634e383084817afe6403dda31378dad0e60c4017 100644 (file)
@@ -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