本文整理汇总了Python中eea.facetednavigation.interfaces.ICriteria.items方法的典型用法代码示例。如果您正苦于以下问题:Python ICriteria.items方法的具体用法?Python ICriteria.items怎么用?Python ICriteria.items使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类eea.facetednavigation.interfaces.ICriteria
的用法示例。
在下文中一共展示了ICriteria.items方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: criteria
# 需要导入模块: from eea.facetednavigation.interfaces import ICriteria [as 别名]
# 或者: from eea.facetednavigation.interfaces.ICriteria import items [as 别名]
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
示例2: criteria
# 需要导入模块: from eea.facetednavigation.interfaces import ICriteria [as 别名]
# 或者: from eea.facetednavigation.interfaces.ICriteria import items [as 别名]
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
示例3: upgrade_to_3
# 需要导入模块: from eea.facetednavigation.interfaces import ICriteria [as 别名]
# 或者: from eea.facetednavigation.interfaces.ICriteria import items [as 别名]
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
示例4: query
# 需要导入模块: from eea.facetednavigation.interfaces import ICriteria [as 别名]
# 或者: from eea.facetednavigation.interfaces.ICriteria import items [as 别名]
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)
示例5: CollectionWidget
# 需要导入模块: from eea.facetednavigation.interfaces import ICriteria [as 别名]
# 或者: from eea.facetednavigation.interfaces.ICriteria import items [as 别名]
class CollectionWidget(RadioWidget):
"""A widget listing collections used as base query."""
widget_type = 'collection-link'
widget_label = 'Collection Link'
faceted_field = False
index = ViewPageTemplateFile('widget.pt')
css_class = 'faceted-tagscloud-collection-widget'
category_vocabulary = (
'collective.eeafaceted.collectionwidget.collectioncategoryvocabulary'
)
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
def update(self):
"""Remove fields 'index' and 'catalog', unused."""
super(CollectionWidget, self).update()
default_group = self.groups[0]
if 'index' in default_group.fields:
del default_group.fields['index']
if 'catalog' in default_group.widgets:
del default_group.fields['catalog']
if 'index' in default_group.widgets:
del default_group.widgets['index']
if 'catalog' in default_group.widgets:
del default_group.widgets['catalog']
def _initialize_widget(self):
""" """
self.grouped_vocabulary = self._generate_vocabulary()
def __call__(self, **kwargs):
# compute the vocabulary used in the widget
self._initialize_widget()
return super(CollectionWidget, self).__call__(**kwargs)
def query(self, form):
""" Get value from form and return a catalog dict query """
# we receive the UID of the selected Collection
# get the collection, compute the query and return it
collection_uid = form.get(self.data.__name__, '')
if collection_uid and not collection_uid == 'all':
# get the collection and compute the query
catalog = getToolByName(self.context, 'portal_catalog')
brains = catalog(UID=collection_uid)
collection = brains[0].getObject()
query = queryparser.parseFormquery(collection, collection.query)
# use sort_on defined on the collection if it is
# not already in the request.form
# get the sort_on criterion and look in the request.form if it is used
sort_on_is_used = False
for criterion_id, criterion in self.criteria.items():
if criterion.widget == SortingWidget.widget_type:
# criterion id in the request.form is like c0[]
if "{0}[]".format(criterion_id) in self.request.form:
sort_on_is_used = True
break
if not sort_on_is_used:
if collection.sort_on:
query['sort_on'] = collection.sort_on
if collection.sort_reversed:
query['sort_order'] = collection.sort_reversed and 'descending' or ''
return query
return {}
def count(self, brains, sequence=None):
"""
"""
res = {}
if not sequence:
sequence = [term.token for term in self.vocabulary()]
catalog = getToolByName(self.context, 'portal_catalog')
for value in sequence:
if not value:
res[value] = len(brains)
continue
res[value] = len(
catalog(self.query(form={self.data.__name__: value})))
return res
@property
@memoize
def default(self):
"""Return the default value"""
default = super(CollectionWidget, self).default
if not default:
# it is possible to not select a default, it will have
# same behaviour as selecting option "All"
return default
#.........这里部分代码省略.........