1 # -*- coding: utf-8 -*- |
1 # -*- coding: utf-8 -*- |
2 from __future__ import absolute_import |
2 from __future__ import absolute_import |
|
3 |
3 #python |
4 #python |
4 from urlparse import urlparse |
5 from urlparse import urlparse |
|
6 import json |
5 import urllib |
7 import urllib |
6 import os |
8 import os |
7 |
9 |
8 #django |
10 #django |
9 from django.conf import settings |
11 from django.conf import settings |
|
12 from django.db.models import Q |
|
13 from django.http import HttpResponse |
10 from django.shortcuts import render_to_response |
14 from django.shortcuts import render_to_response |
11 from django.template import RequestContext |
15 from django.template import RequestContext |
12 from django.core.urlresolvers import reverse |
16 from django.core.urlresolvers import reverse |
13 from django.db.models.signals import post_save |
17 from django.db.models.signals import post_save |
14 |
18 |
15 #django.contrib |
19 #django.contrib |
16 from django.contrib.auth.decorators import login_required |
20 from django.contrib.auth.decorators import login_required |
17 from django.contrib.auth.forms import AuthenticationForm |
21 from django.contrib.auth.forms import AuthenticationForm |
18 from django.contrib.auth.forms import PasswordChangeForm |
22 from django.contrib.auth.forms import PasswordChangeForm |
|
23 from django.contrib.auth.models import User |
19 from django.core.exceptions import ObjectDoesNotExist |
24 from django.core.exceptions import ObjectDoesNotExist |
20 |
25 |
21 #PIL |
26 #PIL |
22 from PIL import Image |
27 from PIL import Image |
23 |
28 |
234 |
239 |
235 return render_to_response(template_name, RequestContext(request, { |
240 return render_to_response(template_name, RequestContext(request, { |
236 "form": username_form |
241 "form": username_form |
237 })) |
242 })) |
238 |
243 |
|
244 |
|
245 def get_usernames(request): |
|
246 """Returns in json the list of ten possible usernames |
|
247 starting with the last pattern in the comma separated string |
|
248 """ |
|
249 |
|
250 get_params = request.GET |
|
251 authors_str = get_params.get('input') |
|
252 |
|
253 if not authors_str: |
|
254 return HttpResponse(json.dumps('')) |
|
255 |
|
256 authors = authors_str.split(',') |
|
257 search_author = authors[-1].strip() |
|
258 |
|
259 users = User.objects.filter( |
|
260 Q(username__istartswith=search_author) | Q( |
|
261 first_name__istartswith=search_author) | Q( |
|
262 last_name__istartswith=search_author)) |
|
263 |
|
264 results = [{'id': '', |
|
265 'info': 'plugin_header', |
|
266 'value': 'User Names' |
|
267 }] |
|
268 |
|
269 for user in users: |
|
270 results.append( |
|
271 {'id': 'author_name', |
|
272 'info': str(user.get_full_name()), |
|
273 'value': str(user.username) |
|
274 }) |
|
275 |
|
276 json_response = {'results': results} |
|
277 |
|
278 return HttpResponse(json.dumps(json_response)) |