| author | rougeronj |
| Thu, 27 Sep 2012 11:33:07 +0200 | |
| changeset 807 | 06891536f619 |
| parent 326 | 7b7325dc4aec |
| child 949 | 091da391cbec |
| permissions | -rw-r--r-- |
|
111
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
63
diff
changeset
|
1 |
from django.contrib.auth import authenticate, login, logout |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
63
diff
changeset
|
2 |
from django.contrib.auth.decorators import login_required |
|
128
503e365a3af7
Starting 'group_management' branch (CAUTION : STILL SOME BUGS)
cavaliet
parents:
111
diff
changeset
|
3 |
from django.contrib.auth.forms import PasswordChangeForm |
|
111
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
63
diff
changeset
|
4 |
from django.http import HttpResponse, HttpResponseRedirect |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
63
diff
changeset
|
5 |
from django.shortcuts import render_to_response |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
63
diff
changeset
|
6 |
from django.template import RequestContext, loader |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
63
diff
changeset
|
7 |
from django.utils import simplejson |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
63
diff
changeset
|
8 |
from django.utils.translation import ugettext as _ |
| 325 | 9 |
from forms import ProfileForm, LanguageChangeForm, PictureForm |
| 169 | 10 |
from django.views.i18n import set_language |
|
111
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
63
diff
changeset
|
11 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
63
diff
changeset
|
12 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
63
diff
changeset
|
13 |
@login_required |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
63
diff
changeset
|
14 |
def profile(request): |
| 169 | 15 |
msg = '' |
|
326
7b7325dc4aec
Add translations for uneditable groups + change size of modal windows
verrierj
parents:
325
diff
changeset
|
16 |
profile = request.user.get_profile() |
|
7b7325dc4aec
Add translations for uneditable groups + change size of modal windows
verrierj
parents:
325
diff
changeset
|
17 |
user_language = profile.language |
| 169 | 18 |
|
| 165 | 19 |
if request.method == "POST": |
|
314
1a8620e5ebb0
Add memcached and sorl thumbnail pour thumbnail management. Set default pict on content, project and user.
cavaliet
parents:
174
diff
changeset
|
20 |
profile_form = ProfileForm(request.user, request.POST, instance=request.user) |
| 169 | 21 |
language_form = LanguageChangeForm(request.user, request.POST) |
22 |
password_form = PasswordChangeForm(request.user) |
|
23 |
||
24 |
if profile_form.is_valid() and language_form.is_valid(): |
|
25 |
profile_form.save() |
|
26 |
language_form.save() |
|
27 |
set_language(request) |
|
28 |
msg = _("Your profile has been updated.") |
|
|
326
7b7325dc4aec
Add translations for uneditable groups + change size of modal windows
verrierj
parents:
325
diff
changeset
|
29 |
user_language = language_form.cleaned_data['language'] |
| 169 | 30 |
|
| 165 | 31 |
else: |
| 169 | 32 |
language_form = LanguageChangeForm() |
33 |
profile_form = ProfileForm(instance=request.user) |
|
34 |
password_form = PasswordChangeForm(request.user) |
|
|
314
1a8620e5ebb0
Add memcached and sorl thumbnail pour thumbnail management. Set default pict on content, project and user.
cavaliet
parents:
174
diff
changeset
|
35 |
|
| 325 | 36 |
profile_picture_form = PictureForm() |
|
314
1a8620e5ebb0
Add memcached and sorl thumbnail pour thumbnail management. Set default pict on content, project and user.
cavaliet
parents:
174
diff
changeset
|
37 |
|
|
1a8620e5ebb0
Add memcached and sorl thumbnail pour thumbnail management. Set default pict on content, project and user.
cavaliet
parents:
174
diff
changeset
|
38 |
return render_to_response('ldt/user/change_profile.html', {'profile_form' : profile_form, 'language_form' : language_form, 'password_form' : password_form, 'user_language' : user_language, 'profile_picture_form':profile_picture_form, 'msg' : msg }, context_instance=RequestContext(request)) |
|
111
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
63
diff
changeset
|
39 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
63
diff
changeset
|
40 |
|
| 169 | 41 |
@login_required |
42 |
def password(request): |
|
43 |
msg = '' |
|
|
174
43748b6b0678
Add a default profile instead of get_or_create_profile
verrierj
parents:
169
diff
changeset
|
44 |
user_language = request.user.get_profile().language |
| 169 | 45 |
|
46 |
if request.method == "POST": |
|
47 |
password_form = PasswordChangeForm(request.user, request.POST) |
|
48 |
profile_form = ProfileForm(instance=request.user) |
|
49 |
language_form = LanguageChangeForm() |
|
50 |
if password_form.is_valid(): |
|
51 |
password_form.save() |
|
52 |
msg = _("Your password has been updated.") |
|
53 |
||
54 |
else: |
|
55 |
language_form = LanguageChangeForm() |
|
56 |
profile_form = ProfileForm() |
|
57 |
password_form = PasswordChangeForm(request.user) |
|
|
314
1a8620e5ebb0
Add memcached and sorl thumbnail pour thumbnail management. Set default pict on content, project and user.
cavaliet
parents:
174
diff
changeset
|
58 |
|
| 325 | 59 |
profile_picture_form = PictureForm() |
|
314
1a8620e5ebb0
Add memcached and sorl thumbnail pour thumbnail management. Set default pict on content, project and user.
cavaliet
parents:
174
diff
changeset
|
60 |
|
|
1a8620e5ebb0
Add memcached and sorl thumbnail pour thumbnail management. Set default pict on content, project and user.
cavaliet
parents:
174
diff
changeset
|
61 |
return render_to_response('ldt/user/change_profile.html', {'profile_form' : profile_form, 'language_form' : language_form, 'password_form' : password_form, 'user_language' : user_language, 'profile_picture_form':profile_picture_form, 'msg' : msg }, context_instance=RequestContext(request)) |
|
1a8620e5ebb0
Add memcached and sorl thumbnail pour thumbnail management. Set default pict on content, project and user.
cavaliet
parents:
174
diff
changeset
|
62 |
|
|
1a8620e5ebb0
Add memcached and sorl thumbnail pour thumbnail management. Set default pict on content, project and user.
cavaliet
parents:
174
diff
changeset
|
63 |
|
|
1a8620e5ebb0
Add memcached and sorl thumbnail pour thumbnail management. Set default pict on content, project and user.
cavaliet
parents:
174
diff
changeset
|
64 |
@login_required |
|
1a8620e5ebb0
Add memcached and sorl thumbnail pour thumbnail management. Set default pict on content, project and user.
cavaliet
parents:
174
diff
changeset
|
65 |
def profile_picture(request): |
|
1a8620e5ebb0
Add memcached and sorl thumbnail pour thumbnail management. Set default pict on content, project and user.
cavaliet
parents:
174
diff
changeset
|
66 |
msg = '' |
|
1a8620e5ebb0
Add memcached and sorl thumbnail pour thumbnail management. Set default pict on content, project and user.
cavaliet
parents:
174
diff
changeset
|
67 |
user_language = request.user.get_profile().language |
|
1a8620e5ebb0
Add memcached and sorl thumbnail pour thumbnail management. Set default pict on content, project and user.
cavaliet
parents:
174
diff
changeset
|
68 |
|
|
1a8620e5ebb0
Add memcached and sorl thumbnail pour thumbnail management. Set default pict on content, project and user.
cavaliet
parents:
174
diff
changeset
|
69 |
if request.method == "POST": |
|
1a8620e5ebb0
Add memcached and sorl thumbnail pour thumbnail management. Set default pict on content, project and user.
cavaliet
parents:
174
diff
changeset
|
70 |
profile_form = ProfileForm(instance=request.user) |
|
1a8620e5ebb0
Add memcached and sorl thumbnail pour thumbnail management. Set default pict on content, project and user.
cavaliet
parents:
174
diff
changeset
|
71 |
language_form = LanguageChangeForm(request.user, request.POST) |
|
1a8620e5ebb0
Add memcached and sorl thumbnail pour thumbnail management. Set default pict on content, project and user.
cavaliet
parents:
174
diff
changeset
|
72 |
password_form = PasswordChangeForm(request.user) |
| 325 | 73 |
profile_picture_form = PictureForm(request.user, request.POST, request.FILES) |
|
314
1a8620e5ebb0
Add memcached and sorl thumbnail pour thumbnail management. Set default pict on content, project and user.
cavaliet
parents:
174
diff
changeset
|
74 |
if profile_picture_form.is_valid(): |
|
1a8620e5ebb0
Add memcached and sorl thumbnail pour thumbnail management. Set default pict on content, project and user.
cavaliet
parents:
174
diff
changeset
|
75 |
profile_picture_form.save() |
|
1a8620e5ebb0
Add memcached and sorl thumbnail pour thumbnail management. Set default pict on content, project and user.
cavaliet
parents:
174
diff
changeset
|
76 |
msg = _("Your profile picture has been updated.") |
|
1a8620e5ebb0
Add memcached and sorl thumbnail pour thumbnail management. Set default pict on content, project and user.
cavaliet
parents:
174
diff
changeset
|
77 |
|
|
1a8620e5ebb0
Add memcached and sorl thumbnail pour thumbnail management. Set default pict on content, project and user.
cavaliet
parents:
174
diff
changeset
|
78 |
else: |
|
1a8620e5ebb0
Add memcached and sorl thumbnail pour thumbnail management. Set default pict on content, project and user.
cavaliet
parents:
174
diff
changeset
|
79 |
language_form = LanguageChangeForm() |
|
1a8620e5ebb0
Add memcached and sorl thumbnail pour thumbnail management. Set default pict on content, project and user.
cavaliet
parents:
174
diff
changeset
|
80 |
profile_form = ProfileForm() |
|
1a8620e5ebb0
Add memcached and sorl thumbnail pour thumbnail management. Set default pict on content, project and user.
cavaliet
parents:
174
diff
changeset
|
81 |
password_form = PasswordChangeForm(request.user) |
| 325 | 82 |
profile_picture_form = PictureForm() |
|
314
1a8620e5ebb0
Add memcached and sorl thumbnail pour thumbnail management. Set default pict on content, project and user.
cavaliet
parents:
174
diff
changeset
|
83 |
|
|
1a8620e5ebb0
Add memcached and sorl thumbnail pour thumbnail management. Set default pict on content, project and user.
cavaliet
parents:
174
diff
changeset
|
84 |
return render_to_response('ldt/user/change_profile.html', {'profile_form' : profile_form, 'language_form' : language_form, 'password_form' : password_form, 'user_language' : user_language, 'profile_picture_form':profile_picture_form, 'msg' : msg }, context_instance=RequestContext(request)) |
| 169 | 85 |
|
86 |
||
|
111
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
63
diff
changeset
|
87 |
def logout_view(request): |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
63
diff
changeset
|
88 |
logout(request) |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
63
diff
changeset
|
89 |
return HttpResponseRedirect(request.META.get('HTTP_REFERER', '/')) |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
63
diff
changeset
|
90 |
#return HttpResponseRedirect(settings.LOGOUT_URL) |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
63
diff
changeset
|
91 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
63
diff
changeset
|
92 |
|
|
167
fe00e7302efe
Change class and functions names to follow PEP8 formatting standards
verrierj
parents:
165
diff
changeset
|
93 |
def login_ajax(request, loginstate_template_name='ldt/user/login_form.html'): |
|
111
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
63
diff
changeset
|
94 |
if request.method == "POST": |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
63
diff
changeset
|
95 |
username = request.POST["username"] |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
63
diff
changeset
|
96 |
password = request.POST["password"] |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
63
diff
changeset
|
97 |
user = authenticate(username=username, password=password) |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
63
diff
changeset
|
98 |
error_message = _(u"Sorry, that's not a valid username or password.") |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
63
diff
changeset
|
99 |
if user is not None: |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
63
diff
changeset
|
100 |
if user.is_active: |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
63
diff
changeset
|
101 |
login(request, user) |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
63
diff
changeset
|
102 |
context = RequestContext(request, { 'username': user.username, }) |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
63
diff
changeset
|
103 |
template = loader.get_template(loginstate_template_name) |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
63
diff
changeset
|
104 |
html = template.render(context) |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
63
diff
changeset
|
105 |
return HttpResponse(simplejson.dumps({'message': u'successful', 'username': user.username, 'html': html, 'reload': request.POST["reload"], })) |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
63
diff
changeset
|
106 |
else: |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
63
diff
changeset
|
107 |
return HttpResponse(simplejson.dumps({'message': error_message, })) |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
63
diff
changeset
|
108 |
else: |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
63
diff
changeset
|
109 |
return HttpResponse(simplejson.dumps({'message': error_message, })) |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
63
diff
changeset
|
110 |
return render_to_response('ldt/user/login_ajax.html', context_instance=RequestContext(request)) |
|
130
1cc949de2d1f
Useless code removed. Iri group finally removed from the model. User's templates cleaned. Little css changed for home.
cavaliet
parents:
128
diff
changeset
|
111 |
|
| 165 | 112 |