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
9 from .models import Service
12 def account_profile(request, basic_form=None, pass_form=None):
13 return render(request, "account/profile.html", {
14 "basic_form": basic_form or UserBasicForm(instance=request.user),
15 "pass_form": pass_form or UserPasswordForm(),
16 "services": Service.objects.all(),
22 def account_change_basic_profile(request):
23 form = UserBasicForm(request.POST, instance=request.user)
27 messages.add_message(request, messages.INFO, _("Profile has been changed."))
28 return http.HttpResponseRedirect('/accounts/')
30 return account_profile(request, basic_form=form)
34 def account_change_password(request):
35 form = UserPasswordForm(request.POST)
38 request.user.set_password(form.cleaned_data['new_password'])
41 messages.add_message(request, messages.INFO, _("Password has been changed."))
42 return http.HttpResponseRedirect('/accounts/')
44 return account_profile(request, pass_form=form)