1
from django.contrib.auth.models import User
2
from django.http import HttpResponse
6
def get_usernames(request):
7
"""AJAX Callback for JS autocomplete.
9
This is used for autocompletion of usernames when writing PMs.
10
The path.name of this function has to be used in each place:
11
1. Argument of source of the JS widget
16
q = request.GET.get('term', '')
18
usernames = User.objects.exclude(is_active=False).filter(username__icontains=q)
20
for user in usernames:
21
name_json = {'value': user.username}
22
results.append(name_json)
23
data = json.dumps(results)
26
mimetype = 'application/json'
27
return HttpResponse(data, mimetype)