~widelands-dev/widelands-website/django_staticfiles

« back to all changes in this revision

Viewing changes to django_messages_wl/views.py

  • Committer: Holger Rapp
  • Date: 2009-02-21 18:24:02 UTC
  • Revision ID: sirver@kallisto.local-20090221182402-k3tuf5c4gjwslbjf
Main Page contains now the same informations as before

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
from django.contrib.auth.models import User
2
 
from django.http import HttpResponse
3
 
import json
4
 
 
5
 
 
6
 
def get_usernames(request):
7
 
    """AJAX Callback for JS autocomplete.
8
 
 
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
12
 
    2. urls.py
13
 
 
14
 
    """
15
 
    if request.is_ajax():
16
 
        q = request.GET.get('term', '')
17
 
 
18
 
        usernames = User.objects.exclude(is_active=False).filter(username__icontains=q)
19
 
        results = []
20
 
        for user in usernames:
21
 
            name_json = {'value': user.username}
22
 
            results.append(name_json)
23
 
        data = json.dumps(results)
24
 
    else:
25
 
        data = 'fail'
26
 
    mimetype = 'application/json'
27
 
    return HttpResponse(data, mimetype)