<commit_before>from django.db.models import Sum
from .models import CartItem
import uuid


class ShoppingCart(object):

    def __init__(self, request):
        self.cart_id = request.session.get('cart', str(uuid.uuid4()))
        request.session['cart'] = self.cart_id

    def add(self,  first_name, last_name, email, product):
        basket_item, created = CartItem.objects.get_or_create(cart=self.cart_id,
                                                              first_name=first_name,
                                                              last_name=last_name,
                                                              email=email,
                                                              product=product)
        return created

    def remove(self, cart_item):
        basket_item = CartItem.objects.get(id=cart_item)
        basket_item.delete()

    def clear(self):
        CartItem.objects.filter(cart=self.cart_id).delete()

    def __len__(self):
        return CartItem.objects.filter(cart=self.cart_id).count()

    def total(self):
        total = dict()
        total['product__price__sum'] = 0
        if CartItem.objects.filter(cart=self.cart_id).exists:
            total = CartItem.objects.filter(cart=self.cart_id).aggregate(Sum('product__price'))
        return total['product__price__sum']

    def get_basket(self):
        return CartItem.objects.filter(cart=self.cart_id)<commit_msg>* Fix variable initialization problem for cart.<commit_after>from django.db.models import Sum
from .models import CartItem
import uuid


class ShoppingCart(object):

    def __init__(self, request):
        self.cart_id = request.session.get('cart', str(uuid.uuid4()))
        request.session['cart'] = self.cart_id

    def add(self,  first_name, last_name, email, product):
        basket_item, created = CartItem.objects.get_or_create(cart=self.cart_id,
                                                              first_name=first_name,
                                                              last_name=last_name,
                                                              email=email,
                                                              product=product)
        return created

    def remove(self, cart_item):
        basket_item = CartItem.objects.get(id=cart_item)
        basket_item.delete()

    def clear(self):
        CartItem.objects.filter(cart=self.cart_id).delete()

    def __len__(self):
        return CartItem.objects.filter(cart=self.cart_id).count()

    def total(self):
        total = dict()
        total['product__price__sum'] = 0.0
        if CartItem.objects.filter(cart=self.cart_id).exists():
            total = CartItem.objects.filter(cart=self.cart_id).aggregate(Sum('product__price'))
        return total['product__price__sum']

    def get_basket(self):
        return CartItem.objects.filter(cart=self.cart_id)
{'fraction_non_alphanumeric': 0.09820813232253618, 'fraction_numerical': 0.0017229496898690559, 'mean_word_length': 1.843290891283056, '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': 16, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6833761', 'n_tokens_mistral': 759, 'n_tokens_neox': 745, 'n_words': 133}