<commit_before>from __future__ import unicode_literals
from . import logger

from collections import namedtuple
from decimal import Decimal
from satchless.item import ItemLine, ItemList, partition
from uuid import uuid4

from django.conf import settings
from django.contrib.postgres.fields import JSONField
from django.core.validators import MaxValueValidator, MinValueValidator
from django.db import models
from django.utils.encoding import python_2_unicode_compatible, smart_str
from django.utils.timezone import now
from django.utils.translation import pgettext_lazy
from django_prices.models import PriceField

from ..discount.models import Voucher
from ..product.models import ProductVariant

CENTS = Decimal('0.01')


SimpleCart = namedtuple('SimpleCart', ('quantity', 'total', 'token'))


class ProductGroup(ItemList):
    def is_shipping_required(self):
        return any(p.is_shipping_required() for p in self)


class CartQueryset(models.QuerySet):

    def anonymous(self):
        return self.filter(user=None)

    def open(self):
        return self.filter(status=Cart.OPEN)

    def saved(self):
        return self.filter(status=Cart.SAVED)

    def waiting_for_payment(self):
        return self.filter(status=Cart.WAITING_FOR_PAYMENT)

    def checkout(self):
        return self.filter(status=Cart.CHECKOUT)

    def canceled(self):
        return self.filter(status=Cart.CANCELED)

    def save(self):
        self.update(status=Cart.SAVED)

    def for_display(self):
        return self.prefetch_related(
            'lines',
            'lines__variant',
            'lines__variant__product',
            'lines__variant__product__images',
            'lines__variant__product__product_class__product_attributes',
            'lines__variant__product__product_class__'
            'product_attributes__values',
            'lines__variant__product__product_class__variant_attributes',
            'lines__variant__product__product_class__'
            'variant_attributes__values',
            'lines__variant__stock')


class Cart(models.Model):

    COOKIE_NAME = 'cart'

    OPEN, SAVED, WAITING_FOR_PAYMENT, ORDERED, CHECKOUT, CANCELED = (
        'open', 'saved', 'payment', 'ordered', 'checkout', 'canceled')

    STATUS_CHOICES = (
        (OPEN, pgettext_lazy('Cart', 'Open - currently active')),
        (WAITING_FOR_PAYMENT, pgettext_lazy('Cart', 'Waiting for payment')),
        (SAVED, pgettext_lazy(
            'Cart', 'Saved - for items to be purchased later')),
        (ORDERED, pgettext_lazy(
            'Cart', 'Submitted - has been ordered at the checkout')),
        (CHECKOUT, pgettext_lazy(
            'Cart', 'Checkout - basket is processed in checkout')),
        (CANCELED, pgettext_lazy(
            'Cart', 'Canceled - basket was canceled by user'))
    )

    status = models.CharField(
        pgettext_lazy('Cart', 'order status'),
        max_length=32, choices=STATUS_CHOICES, default=OPEN)
    created = models.DateTimeField(
        pgettext_lazy('Cart', 'created'), auto_now_add=True)
    last_status_change = models.DateTimeField(<commit_msg>Revert "Fix style"<commit_after>from __future__ import unicode_literals
from . import logger

from collections import namedtuple
from uuid import uuid4

from decimal import Decimal
from django.conf import settings
from django.core.validators import MaxValueValidator, MinValueValidator
from django.db import models
from django.utils.encoding import python_2_unicode_compatible, smart_str
from django.utils.timezone import now
from django.utils.translation import pgettext_lazy
from django_prices.models import PriceField
from django.contrib.postgres.fields import JSONField
from satchless.item import ItemLine, ItemList, partition

from ..discount.models import Voucher
from ..product.models import ProductVariant

CENTS = Decimal('0.01')


SimpleCart = namedtuple('SimpleCart', ('quantity', 'total', 'token'))


class ProductGroup(ItemList):
    def is_shipping_required(self):
        return any(p.is_shipping_required() for p in self)


class CartQueryset(models.QuerySet):

    def anonymous(self):
        return self.filter(user=None)

    def open(self):
        return self.filter(status=Cart.OPEN)

    def saved(self):
        return self.filter(status=Cart.SAVED)

    def waiting_for_payment(self):
        return self.filter(status=Cart.WAITING_FOR_PAYMENT)

    def checkout(self):
        return self.filter(status=Cart.CHECKOUT)

    def canceled(self):
        return self.filter(status=Cart.CANCELED)

    def save(self):
        self.update(status=Cart.SAVED)

    def for_display(self):
        return self.prefetch_related(
            'lines', 'lines__variant',
            'lines__variant__product__product_class__product_attributes',
            'lines__variant__product__product_class__'
            'product_attributes__values',
            'lines__variant__product__product_class__'
            'variant_attributes',
            'lines__variant__product__product_class__variant_attributes__values',
            'lines__variant__stock', 'lines__variant__product__images',
            'lines__variant__product')


class Cart(models.Model):

    COOKIE_NAME = 'cart'

    OPEN, SAVED, WAITING_FOR_PAYMENT, ORDERED, CHECKOUT, CANCELED = (
        'open', 'saved', 'payment', 'ordered', 'checkout', 'canceled')

    STATUS_CHOICES = (
        (OPEN, pgettext_lazy('Cart', 'Open - currently active')),
        (WAITING_FOR_PAYMENT, pgettext_lazy('Cart', 'Waiting for payment')),
        (SAVED, pgettext_lazy(
            'Cart', 'Saved - for items to be purchased later')),
        (ORDERED, pgettext_lazy(
            'Cart', 'Submitted - has been ordered at the checkout')),
        (CHECKOUT, pgettext_lazy(
            'Cart', 'Checkout - basket is processed in checkout')),
        (CANCELED, pgettext_lazy(
            'Cart', 'Canceled - basket was canceled by user'))
    )

    status = models.CharField(
        pgettext_lazy('Cart', 'order status'),
        max_length=32, choices=STATUS_CHOICES, default=OPEN)
    created = models.DateTimeField(
        pgettext_lazy('Cart', 'created'), auto_now_add=True)
    last_status_change = models.DateTimeField(
{'fraction_non_alphanumeric': 0.09559179719037623, 'fraction_numerical': 0.0022606168254480866, 'mean_word_length': 3.5443873807776964, 'pattern_counts': {'":': 0, '<': 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': '6399009', 'n_tokens_mistral': 1843, 'n_tokens_neox': 1795, 'n_words': 417}