1 # -*- coding: utf-8 -*- |
1 # -*- coding: utf-8 -*- |
2 from __future__ import absolute_import |
2 from __future__ import absolute_import |
3 |
|
4 #python |
3 #python |
5 from urlparse import urlparse |
4 from urlparse import urlparse |
|
5 import urllib |
6 import os |
6 import os |
7 |
7 |
8 #django |
8 #django |
9 from django.conf import settings |
9 from django.conf import settings |
|
10 from django.shortcuts import render_to_response |
|
11 from django.template import RequestContext |
|
12 from django.core.urlresolvers import reverse |
|
13 from django.db.models.signals import post_save |
|
14 |
|
15 #django.contrib |
10 from django.contrib.auth.decorators import login_required |
16 from django.contrib.auth.decorators import login_required |
11 from django.contrib.auth.forms import AuthenticationForm |
17 from django.contrib.auth.forms import AuthenticationForm |
12 from django.contrib.auth.forms import PasswordChangeForm |
18 from django.contrib.auth.forms import PasswordChangeForm |
13 from django.contrib.auth.models import User |
|
14 from django.core.exceptions import ObjectDoesNotExist |
19 from django.core.exceptions import ObjectDoesNotExist |
15 from django.core.urlresolvers import reverse |
|
16 from django.db.models import Q |
|
17 from django.http import HttpResponse |
|
18 from django.shortcuts import render_to_response |
|
19 from django.template import RequestContext |
|
20 from django.utils import simplejson as json |
|
21 |
20 |
22 #PIL |
21 #PIL |
23 from PIL import Image |
22 from PIL import Image |
24 |
23 |
25 #kiwipycon |
24 #kiwipycon |
26 from project.kiwipycon.utils import set_message_cookie |
25 from project.kiwipycon.utils import set_message_cookie |
27 from project.kiwipycon.talk.models import Talk |
26 from project.kiwipycon.talk.models import Talk |
28 from project.kiwipycon.registration.models import Registration |
27 from project.kiwipycon.registration.models import Registration |
29 from project.kiwipycon.registration.models import Wifi |
28 from project.kiwipycon.registration.models import Wifi |
30 from project.kiwipycon.registration.forms import WifiForm |
29 from project.kiwipycon.registration.forms import WifiForm |
|
30 from project.kiwipycon.sponsor.models import Sponsor |
31 |
31 |
32 from .utils import kiwipycon_createuser |
32 from .utils import kiwipycon_createuser |
33 from .utils import handle_uploaded_photo |
33 from .utils import handle_uploaded_photo |
34 from .forms import RegisterForm |
34 from .forms import RegisterForm |
35 from .forms import EditProfileForm |
35 from .forms import EditProfileForm |
232 |
234 |
233 return render_to_response(template_name, RequestContext(request, { |
235 return render_to_response(template_name, RequestContext(request, { |
234 "form": username_form |
236 "form": username_form |
235 })) |
237 })) |
236 |
238 |
237 |
|
238 def get_usernames(request): |
|
239 """Returns in json the list of ten possible usernames |
|
240 starting with the last pattern in the comma separated string |
|
241 """ |
|
242 |
|
243 get_params = request.GET |
|
244 search_author = get_params.get('q') |
|
245 |
|
246 if search_author: |
|
247 search_author = search_author.strip() |
|
248 else: |
|
249 return HttpResponse(json.dumps('')) |
|
250 |
|
251 |
|
252 users = User.objects.filter( |
|
253 Q(username__istartswith=search_author) | Q( |
|
254 first_name__istartswith=search_author) | Q( |
|
255 last_name__istartswith=search_author)) |
|
256 |
|
257 results = [] |
|
258 |
|
259 for user in users: |
|
260 results.append( |
|
261 {'name': str(user.username), |
|
262 'value': '%s (%s)' % (user.get_full_name(), user.username) |
|
263 }) |
|
264 |
|
265 return HttpResponse(json.dumps(results)) |
|