Source code for shoop.front.apps.customer_information.views
# This file is part of Shoop.
#
# Copyright (c) 2012-2016, Shoop Ltd. All rights reserved.
#
# This source code is licensed under the AGPLv3 license found in the
# LICENSE file in the root directory of this source tree.
from django.contrib import messages
from django.contrib.auth.views import password_change
from django.shortcuts import redirect
from django.utils.translation import ugettext_lazy as _
from django.views.generic import FormView
from shoop.core.models import get_company_contact, get_person_contact
from shoop.utils.form_group import FormGroup
from .forms import AddressForm, CompanyContactForm, PersonContactForm
[docs]def change_password(request):
template_name = "shoop/customer_information/change_password.jinja"
response = password_change(
request,
post_change_redirect="shoop:customer_edit",
template_name=template_name
)
if response.status_code == 302:
messages.success(request, _("Password successfully changed."))
return response
[docs]class CustomerEditView(FormView):
template_name = "shoop/customer_information/edit_customer.jinja"
def get_form(self, form_class):
contact = get_person_contact(self.request.user)
form_group = FormGroup(**self.get_form_kwargs())
form_group.add_form_def("billing", AddressForm, kwargs={"instance": contact.default_billing_address})
form_group.add_form_def("shipping", AddressForm, kwargs={"instance": contact.default_shipping_address})
form_group.add_form_def("contact", PersonContactForm, kwargs={"instance": contact})
return form_group
[docs]class CompanyEditView(FormView):
template_name = "shoop/customer_information/edit_company.jinja"
def get_form(self, form_class):
contact = get_company_contact(self.request.user)
form_group = FormGroup(**self.get_form_kwargs())
form_group.add_form_def(
"billing", AddressForm, kwargs={"instance": contact.default_billing_address if contact else None}
)
form_group.add_form_def(
"shipping", AddressForm, kwargs={"instance": contact.default_shipping_address if contact else None}
)
form_group.add_form_def("contact", CompanyContactForm, kwargs={"instance": contact})
return form_group