<commit_before>from pyramid.view import view_config, view_defaults
from pyramid.httpexceptions import HTTPFound

from phoenix.views import MyView


@view_defaults(permission='submit')
class CartActions(object):
    """Actions related to cart."""

    def __init__(self, context, request):
        self.context = context
        self.request = request
        self.session = self.request.session

    @view_config(renderer='json', name='list_cart.json')
    def list_cart(self):
        limit = self.request.params.get('limit', 100)
        items = list()
        for item in self.request.cart:
            if len(items) >= limit:
                break
            items.append(dict(title=item.filename, url=item.download_url()))
        return items

    @view_config(renderer='json', name='add_to_cart.json')
    def add_to_cart(self):
        url = self.request.params.get('url')
        title = self.request.params.get('title')
        abstract = self.request.params.get('abstract')
        self.request.cart.add_item(url, title=title, abstract=abstract)
        return {}

    @view_config(renderer='json', name='remove_from_cart.json')
    def remove_from_cart(self):
        url = self.request.params.get('url')
        self.request.cart.remove_item(url)
        return {}

    @view_config(route_name='clear_cart')
    def clear_cart(self):
        self.request.cart.clear()
        self.session.flash("Cart is empty", queue='warning')
        return HTTPFound(self.request.route_path('cart'))

    @view_config(route_name='remove_cart_item')
    def remove_item(self):
        url = self.request.params.get('url')
        if url:
            self.request.cart.remove_item(url)<commit_msg>fixed limit<commit_after>from pyramid.view import view_config, view_defaults
from pyramid.httpexceptions import HTTPFound

from phoenix.views import MyView

import logging
logger = logging.getLogger(__name__)


@view_defaults(permission='submit')
class CartActions(object):
    """Actions related to cart."""

    def __init__(self, context, request):
        self.context = context
        self.request = request
        self.session = self.request.session

    @view_config(renderer='json', name='list_cart.json')
    def list_cart(self):
        limit = int(self.request.params.get('limit', '100'))
        items = list()
        for item in self.request.cart:
            if limit and len(items) >= limit:
                break
            items.append(dict(title=item.filename, url=item.download_url()))
        return items

    @view_config(renderer='json', name='add_to_cart.json')
    def add_to_cart(self):
        url = self.request.params.get('url')
        title = self.request.params.get('title')
        abstract = self.request.params.get('abstract')
        self.request.cart.add_item(url, title=title, abstract=abstract)
        return {}

    @view_config(renderer='json', name='remove_from_cart.json')
    def remove_from_cart(self):
        url = self.request.params.get('url')
        self.request.cart.remove_item(url)
        return {}

    @view_config(route_name='clear_cart')
    def clear_cart(self):
        self.request.cart.clear()
        self.session.flash("Cart is empty", queue='warning')
        return HTTPFound(self.request.route_path('cart'))

    @view_config(route_name='remove_cart_item')
    def remove_item(self):
        url = self.request.params.get('url')
        if url:
            self.request.cart.remove_item(url)
{'fraction_non_alphanumeric': 0.12658959537572254, 'fraction_numerical': 0.0017341040462427746, 'mean_word_length': 3.0385064177362895, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2186713', 'n_tokens_mistral': 1036, 'n_tokens_neox': 1011, 'n_words': 188}