<commit_before># -*- coding: utf-8 -*-
from bda.plone.cart import extractitems
from bda.plone.cart import readcookie
from bda.plone.cart.browser import CartMixin
from decimal import Decimal
from plone.app.layout.viewlets.common import ViewletBase
from plone.app.portlets.portlets import base
from plone.portlets.interfaces import IPortletDataProvider
from plone.portlets.interfaces import IPortletManager
from plone.portlets.interfaces import IPortletRetriever
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
from zope.component import getMultiAdapter
from zope.component import getUtilitiesFor
from zope.i18nmessageid import MessageFactory
from zope.interface import implementer

import pkg_resources


if pkg_resources.get_distribution("Products.CMFPlone").version > '4.99':
    PLONE5 = 1
else:
    PLONE5 = 0


_ = MessageFactory('bda.plone.cart')


class ICartPortlet(IPortletDataProvider):
    pass


@implementer(ICartPortlet)
class CartAssignment(base.Assignment):

    @property
    def title(self):
        return _(u'cart', u'Cart')


def render_cart(context):
    url = context.restrictedTraverse('@@plone').getCurrentUrl()
    if url.endswith('@@cart') \
       or url.find('@@checkout') != -1 \
       or url.find('@@confirm_order') != -1 \
       or url.find('/portal_factory/') != -1:
        return False
    return True


class CartRenderer(base.Renderer, CartMixin):
    if PLONE5:
        template = ViewPageTemplateFile('portlet_p5.pt')
    else:
        template = ViewPageTemplateFile('portlet_p4.pt')

    @property
    def available(self):
        # XXX: is customer somewhere in portal
        return True

    def update(self):
        if render_cart(self.context):
            self.show = True
        else:
            self.show = False

    def render(self):
        if not self.show:
            return u''
        return self.template()


class CartAddForm(base.NullAddForm):
    label = _(u"Add Cart Portlet")
    description = _(u"This portlet displays the shopping cart.")

    def create(self):
        return CartAssignment()


class CartViewlet(ViewletBase, CartMixin):
<commit_msg>hide cart portlet when @@cart is in URL without being at the end of URL for @@add_to_cart<commit_after># -*- coding: utf-8 -*-
from bda.plone.cart import extractitems
from bda.plone.cart import readcookie
from bda.plone.cart.browser import CartMixin
from decimal import Decimal
from plone.app.layout.viewlets.common import ViewletBase
from plone.app.portlets.portlets import base
from plone.portlets.interfaces import IPortletDataProvider
from plone.portlets.interfaces import IPortletManager
from plone.portlets.interfaces import IPortletRetriever
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
from zope.component import getMultiAdapter
from zope.component import getUtilitiesFor
from zope.i18nmessageid import MessageFactory
from zope.interface import implementer

import pkg_resources


if pkg_resources.get_distribution("Products.CMFPlone").version > '4.99':
    PLONE5 = 1
else:
    PLONE5 = 0


_ = MessageFactory('bda.plone.cart')


class ICartPortlet(IPortletDataProvider):
    pass


@implementer(ICartPortlet)
class CartAssignment(base.Assignment):

    @property
    def title(self):
        return _(u'cart', u'Cart')


def render_cart(context):
    url = context.restrictedTraverse('@@plone').getCurrentUrl()
    if url.find('@@cart') != -1 \
       or url.find('@@checkout') != -1 \
       or url.find('@@confirm_order') != -1 \
       or url.find('/portal_factory/') != -1:
        return False
    return True


class CartRenderer(base.Renderer, CartMixin):
    if PLONE5:
        template = ViewPageTemplateFile('portlet_p5.pt')
    else:
        template = ViewPageTemplateFile('portlet_p4.pt')

    @property
    def available(self):
        # XXX: is customer somewhere in portal
        return render_cart(self.context)

    def update(self):
        if render_cart(self.context):
            self.show = True
        else:
            self.show = False

    def render(self):
        if not self.show:
            return u''
        return self.template()


class CartAddForm(base.NullAddForm):
    label = _(u"Add Cart Portlet")
    description = _(u"This portlet displays the shopping cart.")

    def create(self):
        return CartAssignment()


class CartViewlet(ViewletBase, CartMixin):

{'fraction_non_alphanumeric': 0.09710508320036472, 'fraction_numerical': 0.00752222475495783, 'mean_word_length': 3.4821246169560776, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4136619', 'n_tokens_mistral': 1346, 'n_tokens_neox': 1310, 'n_words': 337}