def _get_collection(self, name):
        cid = self.data.collections
        if cid:
            collection = getUtility(ISearchEventCollection)(cid)
            if collection.get(name):

                checked = self.request.form.get(name, [])
                names = []

                attr = name
                if name == 'paths':
                    attr = 'folders'
                    adapter = IAdapter(self.context)
                    portal_path = adapter.portal_path()
                    for nam in collection.get(name):
                        path = '{}{}'.format(portal_path, nam)
                        title = adapter.get_brain(path=path, depth=0).Title
                        names.append({
                            'checked': nam in checked,
                            'key': path,
                            'title': title,
                        })
                else:

                    for nam in collection.get(name):
                        names.append({'checked': nam in checked, 'key': nam})

                return {'names': names, 'title': getattr(self.data, attr)}
    def __call__(self, paths=None, limit=0, b_start=0, b_size=10, b_orphan=1):
        """Returns limited number of brains.

        :param limit: Integer number.
        :type limit: int

        :param b_start: batching start.
        :type b_start: int

        :param b_size: batch size.
        :type b_size: int

        :param b_orphan: batch orphan.
        :type b_orphan: int

        :rtype: plone.app.contentlisting.contentlisting.ContentListing
        """
        form = self.request.form

        start = form.get('start')
        if start:
            start = DateTime(start)

        end = form.get('end')
        if end:
            end = DateTime(end) + 1

        if not (start or end):
            start = DateTime()

        adapter = IAdapter(self.context)

        query = dict(
            SearchableText=form.get('words', ''),
            sort_on='start',
            start={
                'query': [end, ],
                'range': 'max',
            },
            end={
                'query': [start, ],
                'range': 'min',
            },
            path=adapter.portal_path(),
        )
        Subject = form.get('tags', None)
        if Subject:
            query.update({'Subject': Subject})
        paths = form.get('paths', paths)
        if paths:
            query.update({'path': paths})
        if limit:
            query.update({'sort_limit': limit})
        # Add b_start and b_size to the query.
        if b_size:
            query['b_start'] = b_start
            query['b_size'] = b_size

        return adapter.get_content_listing(IATEvent, **query)
    def validate(self, value):
        super(ValidateSKUUniqueness, self).validate(value)

        if getattr(self.context, 'sku', u'') != value:
            adapter = IAdapter(self.context)
            brains = adapter.get_brains(IArticle, path=adapter.portal_path(), sku=value)

            if brains:
                raise Invalid(_(u'The SKU is already in use.'))
def upgrade_14_to_15(context, logger=None):
    """Set article attribute: vat_rate"""
    if logger is None:
        logger = logging.getLogger(__name__)
    from collective.base.interfaces import IAdapter
    from collective.cart.shopping.interfaces import IArticle
    from zope.lifecycleevent import modified
    adapter = IAdapter(context)
    for brain in adapter.get_brains(IArticle, path=adapter.portal_path()):
        obj = brain.getObject()
        setattr(obj, 'vat_rate', obj.vat)
        modified(obj)

    from collective.cart.shipping.interfaces import IShippingMethod
    for brain in adapter.get_brains(IShippingMethod, path=adapter.portal_path()):
        obj = brain.getObject()
        setattr(obj, 'vat', obj.vat)
        obj.reindexObject(idxs=['vat'])
Example #5
0
    def items(self):
        """Returns list of dictionary of footer infos

        :rtype: list
        """
        res = []
        adapter = IAdapter(self.context)
        path = '{}/footer-info'.format(adapter.portal_path())
        for item in adapter.get_content_listing(IATDocument, path=path, depth=1, sort_on='getObjPositionInParent'):
            res.append({
                'id': item.id,
                'title': item.Title(),
                'url': item.getURL(),
                'description': item.Description(),
                'text': item.getObject().CookedBody(),
            })
        return res