[PATCH 31/51] users: Expose a way to get a list of users for autocompletion
Damien Lespiau
damien.lespiau at intel.com
Sat Sep 12 01:55:04 AEST 2015
Just like we can query a list of submitters to auto-complete the search
field, we now can query a list of users. This will be useful for
delegate or reviewer autocompletion.
Signed-off-by: Damien Lespiau <damien.lespiau at intel.com>
---
patchwork/urls.py | 2 ++
patchwork/views/base.py | 32 +++++++++++++++++++++++++++++++-
2 files changed, 33 insertions(+), 1 deletion(-)
diff --git a/patchwork/urls.py b/patchwork/urls.py
index fc8226c..68ec759 100644
--- a/patchwork/urls.py
+++ b/patchwork/urls.py
@@ -106,6 +106,8 @@ urlpatterns = patterns('',
# submitter autocomplete
(r'^submitter/$', 'patchwork.views.submitter_complete'),
+ # user autocomplete
+ (r'^complete_user/$', 'patchwork.views.user_complete'),
# email setup
(r'^mail/$', 'patchwork.views.mail.settings'),
diff --git a/patchwork/views/base.py b/patchwork/views/base.py
index 9d90f56..3f7fa76 100644
--- a/patchwork/views/base.py
+++ b/patchwork/views/base.py
@@ -19,7 +19,8 @@
import json
-from patchwork.models import Patch, Project, Person, EmailConfirmation
+from patchwork.models import Patch, Project, Person, EmailConfirmation, User, \
+ user_name
from django.shortcuts import render_to_response, get_object_or_404
from django.http import HttpResponse, HttpResponseRedirect, Http404
from patchwork.requestcontext import PatchworkRequestContext
@@ -113,6 +114,35 @@ def submitter_complete(request):
return HttpResponse(json.dumps(data), content_type="application/json")
+def user_complete(request):
+ search = request.GET.get('q', '')
+ limit = request.GET.get('l', None)
+
+ if len(search) < 3:
+ return HttpResponse(content_type="application/json")
+
+ queryset = User.objects.filter(Q(username__icontains = search) |
+ Q(first_name__icontains = search) |
+ Q(last_name__icontains = search))
+ if limit is not None:
+ try:
+ limit = int(limit)
+ except ValueError:
+ limit = None
+
+ if limit is not None and limit > 0:
+ queryset = queryset[:limit]
+
+ data = []
+ for user in queryset:
+ item = {}
+ item['pk'] = user.id
+ item['username'] = user.username
+ item['display_name'] = user_name(user)
+ data.append(item)
+
+ return HttpResponse(json.dumps(data), content_type="application/json")
+
help_pages = {'': 'index.html',
'about/': 'about.html',
}
--
2.1.0
More information about the Patchwork
mailing list