| author | cavaliet |
| Fri, 30 Dec 2011 18:16:44 +0100 | |
| changeset 314 | 1a8620e5ebb0 |
| parent 174 | 43748b6b0678 |
| child 325 | f4cb93c06b42 |
| 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 _ |
|
314
1a8620e5ebb0
Add memcached and sorl thumbnail pour thumbnail management. Set default pict on content, project and user.
cavaliet
parents:
174
diff
changeset
|
9 |
from forms import ProfileForm, LanguageChangeForm, ProfilePictureForm |
| 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 = '' |
|
174
43748b6b0678
Add a default profile instead of get_or_create_profile
verrierj
parents:
169
diff
changeset
|
16 |
user_language = request.user.get_profile().language |
| 169 | 17 |
|
| 165 | 18 |
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
|
19 |
profile_form = ProfileForm(request.user, request.POST, instance=request.user) |
| 169 | 20 |
language_form = LanguageChangeForm(request.user, request.POST) |
21 |
password_form = PasswordChangeForm(request.user) |
|
22 |
||
23 |
#assert False, "before : %s " % request.user.username |
|
24 |
||
25 |
if profile_form.is_valid() and language_form.is_valid(): |
|
26 |
profile_form.save() |
|
27 |
language_form.save() |
|
28 |
set_language(request) |
|
29 |
msg = _("Your profile has been updated.") |
|
|
174
43748b6b0678
Add a default profile instead of get_or_create_profile
verrierj
parents:
169
diff
changeset
|
30 |
user_language = request.user.get_profile().language |
| 169 | 31 |
|
32 |
||
33 |
#assert False, "after: %s " % request.user.username |
|
34 |
||
| 165 | 35 |
else: |
| 169 | 36 |
language_form = LanguageChangeForm() |
37 |
profile_form = ProfileForm(instance=request.user) |
|
38 |
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
|
39 |
|
|
1a8620e5ebb0
Add memcached and sorl thumbnail pour thumbnail management. Set default pict on content, project and user.
cavaliet
parents:
174
diff
changeset
|
40 |
profile_picture_form = ProfilePictureForm() |
|
1a8620e5ebb0
Add memcached and sorl thumbnail pour thumbnail management. Set default pict on content, project and user.
cavaliet
parents:
174
diff
changeset
|
41 |
|
|
1a8620e5ebb0
Add memcached and sorl thumbnail pour thumbnail management. Set default pict on content, project and user.
cavaliet
parents:
174
diff
changeset
|
42 |
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
|
43 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
63
diff
changeset
|
44 |
|
| 169 | 45 |
@login_required |
46 |
def password(request): |
|
47 |
msg = '' |
|
|
174
43748b6b0678
Add a default profile instead of get_or_create_profile
verrierj
parents:
169
diff
changeset
|
48 |
user_language = request.user.get_profile().language |
| 169 | 49 |
|
50 |
if request.method == "POST": |
|
51 |
password_form = PasswordChangeForm(request.user, request.POST) |
|
52 |
profile_form = ProfileForm(instance=request.user) |
|
53 |
language_form = LanguageChangeForm() |
|
54 |
if password_form.is_valid(): |
|
55 |
password_form.save() |
|
56 |
msg = _("Your password has been updated.") |
|
57 |
||
58 |
else: |
|
59 |
language_form = LanguageChangeForm() |
|
60 |
profile_form = ProfileForm() |
|
61 |
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
|
62 |
|
|
1a8620e5ebb0
Add memcached and sorl thumbnail pour thumbnail management. Set default pict on content, project and user.
cavaliet
parents:
174
diff
changeset
|
63 |
profile_picture_form = ProfilePictureForm() |
|
1a8620e5ebb0
Add memcached and sorl thumbnail pour thumbnail management. Set default pict on content, project and user.
cavaliet
parents:
174
diff
changeset
|
64 |
|
|
1a8620e5ebb0
Add memcached and sorl thumbnail pour thumbnail management. Set default pict on content, project and user.
cavaliet
parents:
174
diff
changeset
|
65 |
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
|
66 |
|
|
1a8620e5ebb0
Add memcached and sorl thumbnail pour thumbnail management. Set default pict on content, project and user.
cavaliet
parents:
174
diff
changeset
|
67 |
|
|
1a8620e5ebb0
Add memcached and sorl thumbnail pour thumbnail management. Set default pict on content, project and user.
cavaliet
parents:
174
diff
changeset
|
68 |
@login_required |
|
1a8620e5ebb0
Add memcached and sorl thumbnail pour thumbnail management. Set default pict on content, project and user.
cavaliet
parents:
174
diff
changeset
|
69 |
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
|
70 |
msg = '' |
|
1a8620e5ebb0
Add memcached and sorl thumbnail pour thumbnail management. Set default pict on content, project and user.
cavaliet
parents:
174
diff
changeset
|
71 |
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
|
72 |
|
|
1a8620e5ebb0
Add memcached and sorl thumbnail pour thumbnail management. Set default pict on content, project and user.
cavaliet
parents:
174
diff
changeset
|
73 |
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
|
74 |
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
|
75 |
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
|
76 |
password_form = PasswordChangeForm(request.user) |
|
1a8620e5ebb0
Add memcached and sorl thumbnail pour thumbnail management. Set default pict on content, project and user.
cavaliet
parents:
174
diff
changeset
|
77 |
profile_picture_form = ProfilePictureForm(request.user, request.POST, request.FILES) |
|
1a8620e5ebb0
Add memcached and sorl thumbnail pour thumbnail management. Set default pict on content, project and user.
cavaliet
parents:
174
diff
changeset
|
78 |
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
|
79 |
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
|
80 |
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
|
81 |
|
|
1a8620e5ebb0
Add memcached and sorl thumbnail pour thumbnail management. Set default pict on content, project and user.
cavaliet
parents:
174
diff
changeset
|
82 |
else: |
|
1a8620e5ebb0
Add memcached and sorl thumbnail pour thumbnail management. Set default pict on content, project and user.
cavaliet
parents:
174
diff
changeset
|
83 |
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
|
84 |
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
|
85 |
password_form = PasswordChangeForm(request.user) |
|
1a8620e5ebb0
Add memcached and sorl thumbnail pour thumbnail management. Set default pict on content, project and user.
cavaliet
parents:
174
diff
changeset
|
86 |
profile_picture_form = ProfilePictureForm() |
|
1a8620e5ebb0
Add memcached and sorl thumbnail pour thumbnail management. Set default pict on content, project and user.
cavaliet
parents:
174
diff
changeset
|
87 |
|
|
1a8620e5ebb0
Add memcached and sorl thumbnail pour thumbnail management. Set default pict on content, project and user.
cavaliet
parents:
174
diff
changeset
|
88 |
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 | 89 |
|
90 |
||
|
111
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
63
diff
changeset
|
91 |
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
|
92 |
logout(request) |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
63
diff
changeset
|
93 |
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
|
94 |
#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
|
95 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
63
diff
changeset
|
96 |
|
|
167
fe00e7302efe
Change class and functions names to follow PEP8 formatting standards
verrierj
parents:
165
diff
changeset
|
97 |
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
|
98 |
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
|
99 |
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
|
100 |
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
|
101 |
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
|
102 |
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
|
103 |
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
|
104 |
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
|
105 |
login(request, user) |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
63
diff
changeset
|
106 |
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
|
107 |
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
|
108 |
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
|
109 |
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
|
110 |
else: |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
63
diff
changeset
|
111 |
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
|
112 |
else: |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
63
diff
changeset
|
113 |
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
|
114 |
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
|
115 |
|
| 165 | 116 |