当前位置: 首页>>代码示例>>Python>>正文


Python interfaces.ICriteria类代码示例

本文整理汇总了Python中eea.facetednavigation.interfaces.ICriteria的典型用法代码示例。如果您正苦于以下问题:Python ICriteria类的具体用法?Python ICriteria怎么用?Python ICriteria使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了ICriteria类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: query

    def query(self, cid, **kwargs):
        """ Count catalog items
        """
        # Cleanup query
        kwargs.pop('sort_on', None)
        kwargs.pop('sort_order', None)

        kwargs.pop(cid, None)
        self.request.form.pop(cid, None)
        # jQuery >= 1.4 adds type to params keys
        # $.param({ a: [2,3,4] }) // "a[]=2&a[]=3&a[]=4"
        # Let's fix this
        kwargs.pop(cid + '[]', None)
        self.request.form.pop(cid + '[]', None)

        criteria = ICriteria(self.context)
        criterion = criteria.get(cid)

        start = time.time()
        # Query catalog
        handler = getMultiAdapter((self.context, self.request),
                                  name=u'faceted_query')

        if criterion.get('index', '') == 'Language':
            kwargs['_language_count_'] = True
        brains = handler.query(batch=False, sort=False, **kwargs)

        # Get index
        widget = criteria.widget(cid=cid)(self.context, self.request, criterion)
        res = widget.count(brains)
        logger.debug('Benchmark %s: %s', cid, time.time() - start)
        return res
开发者ID:ichim-david,项目名称:eea.facetednavigation,代码行数:32,代码来源:counter.py

示例2: edit

    def edit(self, cid, **kwargs):
        """ See IFacetedCriterionHandler
        """
        criteria = ICriteria(self.context)
        widget = criteria.widget(cid=cid)
        criterion = criteria.get(cid)
        if kwargs.pop('__new__', False):
            criterion = criterion.__class__(cid='c0')
        widget = widget(self.context, self.request, criterion)

        wid = kwargs.pop('widget', None)
        properties = self.extractData(widget, **kwargs)
        if wid:
            properties['widget'] = wid

        update = {}
        for prop, value in properties.items():
            form_key =  'faceted.%s.%s' % (cid, prop)
            if form_key not in kwargs and value is None:
                continue
            update[prop] = value

        if update:
            criteria.edit(cid, **update)
            if widget.hidden:
                notify(FacetedGlobalSettingsChangedEvent(self.context))
            elif set(['hidden', 'operator']).intersection(update.keys()):
                notify(FacetedGlobalSettingsChangedEvent(self.context))

        return self._redirect('Changes saved')
开发者ID:Martronic-SA,项目名称:eea.facetednavigation,代码行数:30,代码来源:configure.py

示例3: add_sorting_widget

def add_sorting_widget(context):
    """
    As in version 7.1 we removed default sorting by effective date, in order
    to maintain backward compatibility we will add a sorting widget, hidden
    for all faceted navigable items where this widget is not present
    """
    ctool = getToolByName(context, 'portal_catalog')
    iface = interfaceToName(context, IFacetedNavigable)
    brains = ctool.unrestrictedSearchResults(object_provides=iface)

    count = 0
    for brain in brains:
        try:
            doc = brain.getObject()
            settings = ICriteria(doc)
            sorting = [criterion for criterion in settings.values()
                       if criterion.widget == 'sorting']
            if sorting:
                continue

            settings.add(
                'sorting', 'right',
                 title='Sort on', default='effective(reverse)',
                 hidden=True
            )
        except Exception, err:
            logger.exception(err)
        else:
            logger.info('Added sorting widget for: %s', doc.absolute_url())
            count += 1
开发者ID:Martronic-SA,项目名称:eea.facetednavigation,代码行数:30,代码来源:evolve71.py

示例4: migrate_autocomplete_widget

def migrate_autocomplete_widget(context):
    """
    As in version 8.4 we added selection of the autocomplete suggestion
    view. To maintain backward compatibility we will set the value of
    this 'autocomplete_view' field to solr suggestions view.
    """
    ctool = getToolByName(context, 'portal_catalog')
    iface = interfaceToName(context, IFacetedNavigable)
    brains = ctool.unrestrictedSearchResults(object_provides=iface)

    count = 0
    for brain in brains:
        doc = brain.getObject()
        settings = ICriteria(doc)

        for criterion in settings.values():
            if criterion.widget == 'autocomplete':
                criterion.autocomplete_view = u'solr-autocomplete-suggest'
                logger.info(
                    'Set defaut autocomplete view of widget: %s',
                    criterion.title
                )
                count += 1

    logger.info('Migrated %s autocomplete widgets', count)
开发者ID:Martronic-SA,项目名称:eea.facetednavigation,代码行数:25,代码来源:evolve84.py

示例5: language_present

    def language_present(self):
        """ Is there any widget for Language index?
        """

        criteria = ICriteria(self.context)
        for criterion in criteria.values():
            if criterion.get('index', None) == 'Language':
                if not criterion.hidden:
                    return True
        return False
开发者ID:Martronic-SA,项目名称:eea.facetednavigation,代码行数:10,代码来源:view.py

示例6: get_widgets

 def get_widgets(self, position='', section=''):
     """ Get all widgets
     """
     criteria = ICriteria(self.context)
     for criterion in criteria.values():
         if position and criterion.get('position', 'right') != position:
             continue
         if section and criterion.get('section', 'default') != section:
             continue
         widget = criteria.widget(wid=criterion.get('widget'))
         yield widget(self.context, self.request, criterion)
开发者ID:Martronic-SA,项目名称:eea.facetednavigation,代码行数:11,代码来源:view.py

示例7: get_widgets

 def get_widgets(self, position="", section=""):
     """ Get all widgets
     """
     criteria = ICriteria(self.context)
     for criterion in criteria.values():
         if position and criterion.get("position", "right") != position:
             continue
         if section and criterion.get("section", "default") != section:
             continue
         widget = criteria.widget(wid=criterion.get("widget"))
         yield widget(self.context, self.request, criterion)
开发者ID:david-batranu,项目名称:eea.facetednavigation,代码行数:11,代码来源:view.py

示例8: criteria

    def criteria(self, sort=False, **kwargs):
        """ Process catalog query
        """
        if self.request:
            kwargs.update(self.request.form)

        # jQuery >= 1.4 adds type to params keys
        # $.param({ a: [2,3,4] }) // "a[]=2&a[]=3&a[]=4"
        # Let's fix this
        kwargs = dict((key.replace('[]', ''), val)
                      for key, val in kwargs.items())

        logger.debug("REQUEST: %r", kwargs)

        # Generate the catalog query
        criteria = ICriteria(self.context)
        query = {}
        for cid, criterion in criteria.items():
            widget = criteria.widget(cid=cid)
            widget = widget(self.context, self.request, criterion)

            widget_query = widget.query(kwargs)
            if getattr(widget, 'faceted_field', False):
                widget_index = widget.data.get('index', '')
                if ('facet.field' in query and
                            widget_index not in query['facet.field']):
                    query['facet.field'].append(widget_index)
                else:
                    query['facet.field'] = [widget_index]
            query.update(widget_query)

            # Handle language widgets
            if criterion.get('index', '') == 'Language':
                language_widget = queryMultiAdapter((widget, self.context),
                                                    ILanguageWidgetAdapter)
                if not language_widget:
                    continue
                query.update(language_widget(kwargs))

        # Add default sorting criteria
        if sort and not query.has_key('sort_on'):
            query['sort_on'] = 'effective'
            query['sort_order'] = 'reverse'

        # Add default language.
        # Also make sure to return language-independent content.
        lang = self.language
        if lang:
            lang = [lang, '']
        query.setdefault('Language', lang)

        logger.debug('QUERY: %s', query)
        return query
开发者ID:cedricmessiant,项目名称:eea.facetednavigation,代码行数:53,代码来源:query.py

示例9: add

    def add(self, **kwargs):
        """ See IFacetedCriterionHandler
        """
        kwargs = self._request_form(kwargs)

        wid = kwargs.pop('wtype', None)
        position = kwargs.pop('wposition', 'right')
        section = kwargs.pop('wsection', 'default')

        criteria = ICriteria(self.context)
        cid = criteria.add(wid, position, section)
        return self.edit(cid, **kwargs)
开发者ID:Conectivo,项目名称:eea.facetednavigation,代码行数:12,代码来源:configure.py

示例10: add

    def add(self, **kwargs):
        """ See IFacetedCriterionHandler
        """
        wid = kwargs.pop('wtype',
                         self.request.get('wtype', None))
        position = kwargs.pop('wposition',
                              self.request.get('wposition', 'right'))
        section = kwargs.pop('wsection',
                             self.request.get('wsection', 'default'))

        criteria = ICriteria(self.context)
        cid = criteria.add(wid, position, section)
        return self.edit(cid, __new__=True, **kwargs)
开发者ID:Martronic-SA,项目名称:eea.facetednavigation,代码行数:13,代码来源:configure.py

示例11: criteria

    def criteria(self, sort=True, **kwargs):
        """ Process catalog query
        """
        if self.request:
            kwargs.update(self.request.form)

        # jQuery >= 1.4 adds type to params keys
        # $.param({ a: [2,3,4] }) // "a[]=2&a[]=3&a[]=4"
        # Let's fix this
        kwargs = dict((key.replace('[]', ''), val)
                      for key, val in kwargs.items())

        logger.debug("REQUEST: %r", kwargs)

        # Generate the catalog query
        mtool = getToolByName(self.context, 'portal_membership', None)
        criteria = ICriteria(self.context)

        query = {}
        if mtool.isAnonymousUser():
            query['review_state'] = 'published'

        for cid, criterion in criteria.items():
            widget = criteria.widget(cid=cid)
            widget = widget(self.context, self.request, criterion)

            query.update(widget.query(kwargs))

            # Handle language widgets
            if criterion.get('index', '') == 'Language':
                language_widget = queryMultiAdapter((widget, self.context),
                                                    ILanguageWidgetAdapter)
                if not language_widget:
                    continue
                query.update(language_widget(kwargs))

        # Add default sorting criteria
        if sort and not query.has_key('sort_on'):
            query['sort_on'] = 'effective'
            query['sort_order'] = 'reverse'

        # Add default language.
        # Also make sure to return language-independent content.
        lang = self.language
        if lang:
            lang = [lang, '']
        query.setdefault('Language', lang)

        logger.debug('QUERY: %s', query)
        return query
开发者ID:TobiasWeigel,项目名称:eea.facetednavigation,代码行数:50,代码来源:query.py

示例12: upgrade_to_3

def upgrade_to_3(context):
    catalog = api.portal.get_tool('portal_catalog')
    brains = catalog(object_provides=IFacetedNavigable.__identifier__)
    for brain in brains:
        obj = brain.getObject()
        criterias = ICriteria(obj)
        changes = False
        for cid, crit in criterias.items():
            if crit.get('vocabulary', u'') in (u'imio.dashboard.conditionawarecollectionvocabulary',
                                               u'imio.dashboard.cachedcollectionvocabulary'):
                crit.vocabulary = u'collective.eeafaceted.collectionwidget.cachedcollectionvocabulary'
                changes = True
                logger.info('Criterion {} updated on object {}'.format(cid, brain.getPath()))
        if changes:
            criterias.criteria._p_changed = 1
开发者ID:collective,项目名称:collective.eeafaceted.collectionwidget,代码行数:15,代码来源:upgrades.py

示例13: query

    def query(self, batch=True, sort=False, **kwargs):
        """ Search using given criteria
        """
        if self.request:
            kwargs.update(self.request.form)
            kwargs.pop('sort[]', None)
            kwargs.pop('sort', None)

        # jQuery >= 1.4 adds type to params keys
        # $.param({ a: [2,3,4] }) // "a[]=2&a[]=3&a[]=4"
        # Let's fix this
        kwargs = dict((key.replace('[]', ''), val)
                      for key, val in kwargs.items())

        query = self.criteria(sort=sort, **kwargs)
        # We don't want to do an unnecessary sort for a counter query
        counter_query = kwargs.pop('counter_query', False)
        if counter_query:
            query.pop('sort_on', None)
            query.pop('sort_order', None)

        catalog = getUtility(IFacetedCatalog)
        num_per_page = 20
        criteria = ICriteria(self.context)
        brains_filters = []
        for cid, criterion in criteria.items():
            widgetclass = criteria.widget(cid=cid)
            widget = widgetclass(self.context, self.request, criterion)

            if widget.widget_type == 'resultsperpage':
                num_per_page = widget.results_per_page(kwargs)

            brains_filter = queryAdapter(widget, IWidgetFilterBrains)
            if brains_filter:
                brains_filters.append(brains_filter)

        b_start = safeToInt(kwargs.get('b_start', 0))
        orphans = num_per_page * 20 / 100 # orphans = 20% of items per page
        if batch and not brains_filters:
            # add b_start and b_size to query to use better sort algorithm
            query['b_start'] = b_start
            query['b_size'] = num_per_page + orphans

        try:
            brains = catalog(self.context, **query)
        except Exception, err:
            logger.exception(err)
            return Batch([], 20, 0)
开发者ID:cedricmessiant,项目名称:eea.facetednavigation,代码行数:48,代码来源:query.py

示例14: __call__

    def __call__(self, **kwargs):
        if self.request:
            kwargs.update(self.request.form)

        # Calling self.index() will set cache headers for varnish
        self.index()

        cid = kwargs.pop('cid', None)
        if not cid:
            return {}

        res = self.query(cid, **kwargs)

        criteria = ICriteria(self.context)
        criterion = criteria.get(cid)
        widget = criteria.widget(cid=cid)(self.context, self.request, criterion)
        return widget(vocabulary=res)
开发者ID:Conectivo,项目名称:eea.facetednavigation,代码行数:17,代码来源:counter.py

示例15: __init__

 def __init__(self, context, request, data=None):
     super(CollectionWidget, self).__init__(context, request, data)
     # real context could not be current context but some distant context
     # look in eea.facetednavigation.criteria.handler.Criteria
     self.criteria = ICriteria(self.context)
     self.context = self.criteria.context
     # display the fieldset around the widget when rendered?
     self.display_fieldset = True
开发者ID:collective,项目名称:collective.eeafaceted.collectionwidget,代码行数:8,代码来源:widget.py


注:本文中的eea.facetednavigation.interfaces.ICriteria类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。