<commit_before># This file is part of Shuup.
#
# Copyright (c) 2012-2017, Shoop Commerce Ltd. All rights reserved.
#
# This source code is licensed under the OSL-3.0 license found in the
# LICENSE file in the root directory of this source tree.
from __future__ import unicode_literals

from django.core.urlresolvers import reverse

from shuup.front.basket import get_basket
from shuup.front.basket.objects import BaseBasket

from ._storage import CheckoutPhaseStorage


class CheckoutPhaseViewMixin(object):
    identifier = None
    title = None  # User-visible
    final = False  # Should be set for final steps (those that may be accessed via the previous step's URL)

    horizontal_template = True  # Set this to False if you want to use single page checkout

    checkout_process = None  # set as an instance variable
    phases = ()  # set as an instance variable; likely accessed via template (`view.phases`)
    next_phase = None  # set as an instance variable
    previous_phase = None  # set as an instance variable
    request = None  # exists via being a view

    basket_class = BaseBasket
    basket_name_attr = "basket"

    def is_visible_for_user(self):
        return bool(self.title)

    def is_valid(self):
        return True

    def should_skip(self):
        return False

    def process(self):
        raise NotImplementedError("`process` MUST be overridden in %r" % self.__class__)

    def reset(self):
        self.storage.reset()

    def get_success_url(self):
        if self.next_phase:
            return reverse("shuup:checkout", kwargs={"phase": self.next_phase.identifier})

    def get_url(self, request):
        return reverse("shuup:checkout", kwargs={"phase": self.identifier})

    @property
    def basket(self):
        """
        :rtype: BaseBasket
        :return:
        """
        return self._get_basket_from_request(self.request)

    @property
    def storage(self):
        if not hasattr(self, "_storage"):
            self._storage = CheckoutPhaseStorage(request=self.request, phase_identifier=self.identifier)
        return self._storage

    def _get_basket_from_request(self, request):

        """
        :rtype: BaseBasket<commit_msg>Fix registration while ordering<commit_after># This file is part of Shuup.
#
# Copyright (c) 2012-2017, Shoop Commerce Ltd. All rights reserved.
#
# This source code is licensed under the OSL-3.0 license found in the
# LICENSE file in the root directory of this source tree.
from __future__ import unicode_literals

from django.core.urlresolvers import reverse

from shuup.front.basket import get_basket
from shuup.front.basket.objects import BaseBasket

from ._storage import CheckoutPhaseStorage


class CheckoutPhaseViewMixin(object):
    identifier = None
    title = None  # User-visible
    final = False  # Should be set for final steps (those that may be accessed via the previous step's URL)

    horizontal_template = True  # Set this to False if you want to use single page checkout

    checkout_process = None  # set as an instance variable
    phases = ()  # set as an instance variable; likely accessed via template (`view.phases`)
    next_phase = None  # set as an instance variable
    previous_phase = None  # set as an instance variable
    request = None  # exists via being a view

    basket_class = BaseBasket
    basket_name_attr = "basket"

    def is_visible_for_user(self):
        return bool(self.title)

    def is_valid(self):
        return True

    def should_skip(self):
        return False

    def process(self):
        raise NotImplementedError("`process` MUST be overridden in %r" % self.__class__)

    def reset(self):
        self.storage.reset()

    def get_success_url(self, *args, **kwargs):
        if self.next_phase:
            return reverse("shuup:checkout", kwargs={"phase": self.next_phase.identifier})
        next_obj = super(CheckoutPhaseViewMixin, self)
        if hasattr(next_obj, 'get_success_url'):
            return next_obj.get_success_url(*args, **kwargs)

    def get_url(self, request):
        return reverse("shuup:checkout", kwargs={"phase": self.identifier})

    @property
    def basket(self):
        """
        :rtype: BaseBasket
        :return:
        """
        return self._get_basket_from_request(self.request)

    @property
    def storage(self):
        if not hasattr(self, "_storage"):
            self._storage = CheckoutPhaseStorage(request=self.request, phase_identifier=self.identifier)
        return self._storage

    def _get_basket_from_request(self, request):

        """
        :rtype: BaseBasket
{'fraction_non_alphanumeric': 0.08170360712733594, 'fraction_numerical': 0.004345936549326379, 'mean_word_length': 3.1208594449418086, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7230922', 'n_tokens_mistral': 1350, 'n_tokens_neox': 1303, 'n_words': 423}