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
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(),
19 def account_change_basic_profile(request):
20 form = UserBasicForm(request.POST, instance=request.user)
24 request.user.message_set.create(message=__("Profile has been changed."))
25 return http.HttpResponseRedirect('/accounts/')
27 return account_profile(request, basic_form=form)
31 def account_change_password(request):
32 form = UserPasswordForm(request.POST)
35 request.user.set_password(form.cleaned_data['new_password'])
38 request.user.message_set.create(message=__("Password has been changed."))
39 return http.HttpResponseRedirect('/accounts/')
41 return account_profile(request, pass_form=form)