<commit_before>import json
from random import shuffle
from AccessControl import getSecurityManager
from Acquisition import aq_inner
from Acquisition import aq_parent
from ZTUtils import make_query
from zope.component import getUtility
from zope.i18nmessageid import MessageFactory
from Products.Five import BrowserView
from Products.CMFCore.utils import getToolByName
from plone.registry.interfaces import IRegistry
#from plone.app.contenttypes.behaviors.leadimage import ILeadImage
from bda.plone.ajax.batch import Batch
from bda.plone.cart import get_object_by_uid
from bda.plone.shop import permissions
from bda.plone.shop.interfaces import IBuyable
from bda.plone.productshop.interfaces import IProduct
from bda.plone.productshop.interfaces import IProductGroup
from bda.plone.productshop.interfaces import IVariant
from bda.plone.productshop.interfaces import IProductShopSettings
from bda.plone.productshop.behaviors import IProductTilesViewSettingsBehavior
from bda.plone.productshop.utils import request_property
from bda.plone.productshop.utils import available_variant_aspects


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


def query_children(context, criteria=dict()):
    cat = getToolByName(context, 'portal_catalog')
    query = {
        'path': {
            'query': '/'.join(context.getPhysicalPath()),
            'depth': 1,
        },
        'sort_on': 'getObjPositionInParent',
    }
    query.update(criteria)
    return cat(**query)


def img_scale(context, scale_name):
    if not context.image:
        return None
    scales = context.restrictedTraverse('@@images')
    return scales.scale('image', scale_name)


def img_tag(context, scale_name, css_class):
    scale = img_scale(context, scale_name)
    if not scale:
        return None
    return scale.tag(css_class=css_class)


class ProductView(BrowserView):
    image_scale = 'mini'

    @property
    def image(self):
        return img_tag(self.context, self.image_scale, 'product_image')

    @property
    def details(self):
        return self.context.details

    @property
    def datasheet(self):
        return self.context.datasheet

    @property
    def manual(self):
        manual = getattr(self.context, 'manual', None)
        if not manual:
            return None
        return {
            'url': '%s/@@download/manual' % self.context.absolute_url(),
            'title': manual.filename,
        }

    @property
    def related_items(self):
        if hasattr(self.context, 'relatedItems'):
            related = [_.to_object for _ in self.context.relatedItems]
            return related
        return None


FALLBACK_TILE_COLUMNS = 4


class ProductTiles(BrowserView):

    def query_tile_items(self, context, tile_items, aggregate=True):
        brains = [brain for brain in query_children(context)]
        if not aggregate:
            shuffle(brains)
        for brain in brains:
            if brain.portal_type == 'bda.plone.productshop.productgroup' \
                    or brain.portal_type == 'bda.plone.productshop.product':
                tile_items.append(brain.getObject())
                if not aggregate:
                    return
            elif brain.portal_type == 'Folder':
                obj = brain.getObject()
                # case leadimage
                if hasattr(obj, 'image'):
                #if ILeadImage.providedBy(obj) and ILeadImage(obj).image:
                    tile_items.append(obj)
                else:
                    count = len(tile_items)
                    self.query_tile_items(brain.getObject(),
                                          tile_items,
                                          aggregate=False)
                    # case multi level folder structure
                    if len(tile_items) > count + 1:
                        del tile_items[count + 1:]

    def tile_item_context(self, tile_item):
        anchor = aq_inner(self.context)
        context = aq_inner(tile_item)
        while True:
            parent = aq_parent(aq_inner(context))<commit_msg>revert leadimage use on product tiles<commit_after>import json
from random import shuffle
from AccessControl import getSecurityManager
from Acquisition import aq_inner
from Acquisition import aq_parent
from ZTUtils import make_query
from zope.component import getUtility
from zope.i18nmessageid import MessageFactory
from Products.Five import BrowserView
from Products.CMFCore.utils import getToolByName
from plone.registry.interfaces import IRegistry
from plone.app.contenttypes.behaviors.leadimage import ILeadImage
from bda.plone.ajax.batch import Batch
from bda.plone.cart import get_object_by_uid
from bda.plone.shop import permissions
from bda.plone.shop.interfaces import IBuyable
from bda.plone.productshop.interfaces import IProduct
from bda.plone.productshop.interfaces import IProductGroup
from bda.plone.productshop.interfaces import IVariant
from bda.plone.productshop.interfaces import IProductShopSettings
from bda.plone.productshop.behaviors import IProductTilesViewSettingsBehavior
from bda.plone.productshop.utils import request_property
from bda.plone.productshop.utils import available_variant_aspects


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


def query_children(context, criteria=dict()):
    cat = getToolByName(context, 'portal_catalog')
    query = {
        'path': {
            'query': '/'.join(context.getPhysicalPath()),
            'depth': 1,
        },
        'sort_on': 'getObjPositionInParent',
    }
    query.update(criteria)
    return cat(**query)


def img_scale(context, scale_name):
    if not context.image:
        return None
    scales = context.restrictedTraverse('@@images')
    return scales.scale('image', scale_name)


def img_tag(context, scale_name, css_class):
    scale = img_scale(context, scale_name)
    if not scale:
        return None
    return scale.tag(css_class=css_class)


class ProductView(BrowserView):
    image_scale = 'mini'

    @property
    def image(self):
        return img_tag(self.context, self.image_scale, 'product_image')

    @property
    def details(self):
        return self.context.details

    @property
    def datasheet(self):
        return self.context.datasheet

    @property
    def manual(self):
        manual = getattr(self.context, 'manual', None)
        if not manual:
            return None
        return {
            'url': '%s/@@download/manual' % self.context.absolute_url(),
            'title': manual.filename,
        }

    @property
    def related_items(self):
        if hasattr(self.context, 'relatedItems'):
            related = [_.to_object for _ in self.context.relatedItems]
            return related
        return None


FALLBACK_TILE_COLUMNS = 4


class ProductTiles(BrowserView):

    def query_tile_items(self, context, tile_items, aggregate=True):
        brains = [brain for brain in query_children(context)]
        if not aggregate:
            shuffle(brains)
        for brain in brains:
            if brain.portal_type == 'bda.plone.productshop.productgroup' \
                    or brain.portal_type == 'bda.plone.productshop.product':
                tile_items.append(brain.getObject())
                if not aggregate:
                    return
            elif brain.portal_type == 'Folder':
                obj = brain.getObject()
                if ILeadImage.providedBy(obj) and ILeadImage(obj).image:
                    tile_items.append(obj)
                else:
                    count = len(tile_items)
                    self.query_tile_items(brain.getObject(),
                                          tile_items,
                                          aggregate=False)
                    # case multi level folder structure
                    if len(tile_items) > count + 1:
                        del tile_items[count + 1:]

    def tile_item_context(self, tile_item):
        anchor = aq_inner(self.context)
        context = aq_inner(tile_item)
        while True:
            parent = aq_parent(aq_inner(context))
{'fraction_non_alphanumeric': 0.08224461863879556, 'fraction_numerical': 0.0014930944382232176, 'mean_word_length': 2.5285338015803336, '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': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5617750', 'n_tokens_mistral': 2299, 'n_tokens_neox': 2202, 'n_words': 533}