remove redmine link, add new link to redakcja
[cas.git] / src / accounts / views.py
1 # Create your views here.
2 from django import http
3 from django.utils.translation import ugettext as __
4 from django.views.generic.simple import direct_to_template
5 from django.views.decorators.http import require_POST
6 from django.contrib.auth.decorators import login_required
7 from accounts.forms import UserBasicForm, UserPasswordForm
8
9 @login_required
10 def account_profile(request, basic_form=None, pass_form=None):
11     return direct_to_template(request, "account/profile.html", {
12         "basic_form": basic_form or UserBasicForm(instance=request.user),
13         "pass_form": pass_form or UserPasswordForm(),
14     })
15
16
17 @require_POST
18 @login_required
19 def account_change_basic_profile(request):
20     form = UserBasicForm(request.POST, instance=request.user)
21
22     if form.is_valid():
23         form.save()
24         request.user.message_set.create(message=__("Profile has been changed."))
25         return http.HttpResponseRedirect('/accounts/')
26
27     return account_profile(request, basic_form=form)
28
29 @require_POST
30 @login_required
31 def account_change_password(request):
32     form = UserPasswordForm(request.POST)
33
34     if form.is_valid():
35         request.user.set_password(form.cleaned_data['new_password'])
36         request.user.save()
37
38         request.user.message_set.create(message=__("Password has been changed."))
39         return http.HttpResponseRedirect('/accounts/')
40
41     return account_profile(request, pass_form=form)