1 # Create your views here.
2 from django import http
3 from django.contrib.auth.decorators import login_required
4 from django.contrib import messages
5 from django.shortcuts import render
6 from django.utils.translation import ugettext as __
7 from django.views.decorators.http import require_POST
8 from accounts.forms import UserBasicForm, UserPasswordForm
11 def account_profile(request, basic_form=None, pass_form=None):
12 return render(request, "account/profile.html", {
13 "basic_form": basic_form or UserBasicForm(instance=request.user),
14 "pass_form": pass_form or UserPasswordForm(),
20 def account_change_basic_profile(request):
21 form = UserBasicForm(request.POST, instance=request.user)
25 messages.add_message(request, messages.INFO, __("Profile has been changed."))
26 return http.HttpResponseRedirect('/accounts/')
28 return account_profile(request, basic_form=form)
32 def account_change_password(request):
33 form = UserPasswordForm(request.POST)
36 request.user.set_password(form.cleaned_data['new_password'])
39 messages.add_message(request, messages.INFO, __("Password has been changed."))
40 return http.HttpResponseRedirect('/accounts/')
42 return account_profile(request, pass_form=form)