from django import forms
from django.http import HttpResponseRedirect
from django.utils.translation import gettext_lazy as _
from enumfields import Enum
from shuup.front.apps.auth.views import LoginView
from shuup.front.apps.registration.views import RegistrationNoActivationView
from shuup.front.checkout import CheckoutPhaseViewMixin
from shuup.utils.form_group import FormGroup
CHECKOUT_CHOICE_STORAGE_KEY = "checkout_method:checkout_method_choice"
[docs]
class CheckoutMethodChoices(Enum):
CHECKOUT_AS_GUEST = 0
REGISTER = 1
class Labels:
CHECKOUT_AS_GUEST = _("Checkout as Guest")
REGISTER = _("Register")
[docs]
class CheckoutMethodPhase(CheckoutPhaseViewMixin, LoginView):
identifier = "checkout_method"
title = _("Checkout Method Choice")
template_name = "shuup/front/checkout/checkout_method.jinja"
login_form_key = "login"
checkout_method_choice_key = "checkout_method_choice"
[docs]
def is_visible_for_user(self):
return bool(not self.request.customer or self.request.customer.is_all_seeing)
[docs]
def should_skip(self):
return not self.is_visible_for_user()
[docs]
def is_valid(self):
checkout_method_choice = bool(self.storage.get(CHECKOUT_CHOICE_STORAGE_KEY, None) is not None)
return bool(checkout_method_choice or self.request.customer)
[docs]
def process(self):
return
[docs]
class RegisterPhase(CheckoutPhaseViewMixin, RegistrationNoActivationView):
identifier = "register"
title = _("Register")
template_name = "shuup/front/checkout/register.jinja"
[docs]
def is_visible_for_user(self):
checkout_method_choice_is_registered = bool(self.storage.get(CHECKOUT_CHOICE_STORAGE_KEY, None))
return bool(not self.request.customer and checkout_method_choice_is_registered)
[docs]
def should_skip(self):
return not self.is_visible_for_user()
[docs]
def is_valid(self):
checkout_method_choice_is_registered = bool(self.storage.get(CHECKOUT_CHOICE_STORAGE_KEY, None))
return bool(self.request.customer and checkout_method_choice_is_registered)
[docs]
def process(self):
return