def patch_atct_topic_date_indices(): from Products.ATContentTypes import criteria if 'DateRecurringIndex' not in criteria.DATE_INDICES: criteria.DATE_INDICES = tuple( list(criteria.DATE_INDICES) + ['DateRecurringIndex'] ) criteria.registerCriterion( criteria.date.ATDateCriteria, criteria.DATE_INDICES, ) if 'DateRecurringIndex' not in criteria.SORT_INDICES: criteria.SORT_INDICES = tuple( list(criteria.SORT_INDICES) + ['DateRecurringIndex'] ) criteria.registerCriterion( criteria.sort.ATSortCriterion, criteria.SORT_INDICES, )
implements(IATTopicSearchCriterion) security = ClassSecurityInfo() meta_type = 'ATReferenceCriterion' archetype_name = 'Reference Criterion' shortDesc = 'Select referenced content' def getCurrentValues(self): catalog = getToolByName(self, 'portal_catalog') uid_cat = getToolByName(self, 'uid_catalog') putils = getToolByName(self, 'plone_utils') options = catalog.uniqueValuesFor(self.Field()) # If the uid catalog has a Language index restrict the query by it. # We should only shows references to items in the same or the neutral # language. query = dict(UID=options, sort_on='Title') if 'Language' in uid_cat.indexes(): query['Language'] = [self.Language(), ''] brains = uid_cat(**query) display = [((putils.pretty_title_or_id(b)).lower(), b.UID, b.Title or b.id) for b in brains] display.sort() display_list = DisplayList([(d[1], d[2]) for d in display]) return display_list registerCriterion(ATReferenceCriterion, REFERENCE_INDICES)
class ATPeriodCriteria(ATBaseCriterion): """A relative date criterion""" implements(IATPeriodCriteria) security = ClassSecurityInfo() schema = PeriodCriteriaSchema meta_type = 'ATPeriodCriteria' archetype_name = 'Period Date Criteria' shortDesc = _(u'Period of time') security.declareProtected(permissions.View, 'Value') def Value(self): now = DateTime() value = self.getPeriod() return getBounds(now, value) security.declareProtected(permissions.View, 'getCriteriaItems') def getCriteriaItems(self): """Return a sequence of items to be used to build the catalog query. """ field = self.Field() value = self.Value() return ((field, {'query': value, 'range': 'min:max'}), ) registerCriterion(ATPeriodCriteria, DATE_INDICES)
class ATPeriodCriteria(ATBaseCriterion): """A relative date criterion""" implements(IATPeriodCriteria) security = ClassSecurityInfo() schema = PeriodCriteriaSchema meta_type = 'ATPeriodCriteria' archetype_name = 'Period Date Criteria' shortDesc = _(u'Period of time') security.declareProtected(permissions.View, 'Value') def Value(self): now = DateTime() value = self.getPeriod() return getBounds(now, value) security.declareProtected(permissions.View, 'getCriteriaItems') def getCriteriaItems(self): """Return a sequence of items to be used to build the catalog query. """ field = self.Field() value = self.Value() return ( ( field, {'query': value, 'range': 'min:max'} ), ) registerCriterion(ATPeriodCriteria, DATE_INDICES)
mutator="setValue", default="", widget=StringWidget( label=_(u'label_string_criteria_value', default=u'Value'), description=_(u'help_string_criteria_value', default=u'A string value.')) ), )) class ATSimpleStringCriterion(ATBaseCriterion): """A simple string criterion""" __implements__ = ATBaseCriterion.__implements__ + (IATTopicSearchCriterion, ) security = ClassSecurityInfo() schema = ATSimpleStringCriterionSchema meta_type = 'ATSimpleStringCriterion' archetype_name = 'Simple String Criterion' shortDesc = 'Text' security.declareProtected(View, 'getCriteriaItems') def getCriteriaItems(self): result = [] if self.Value() is not '': result.append((self.Field(), self.Value())) return tuple( result ) registerCriterion(ATSimpleStringCriterion, STRING_INDICES)
mutator="setValue", default="", widget=StringWidget( label=_(u'label_string_criteria_value', default=u'Value'), description=_(u'help_string_criteria_value', default=u'A string value.')) ), )) @implementer(IATTopicSearchCriterion) class ATSimpleStringCriterion(ATBaseCriterion): """A simple string criterion""" security = ClassSecurityInfo() schema = ATSimpleStringCriterionSchema meta_type = 'ATSimpleStringCriterion' archetype_name = 'Simple String Criterion' shortDesc = 'Text' @security.protected(View) def getCriteriaItems(self): result = [] if self.Value() is not '': result.append((self.Field(), self.Value())) return tuple(result) registerCriterion(ATSimpleStringCriterion, STRING_INDICES + ('UUIDIndex', ))
ATSimpleStringCriterion) except ImportError: pass else: # If we do not update this, Collections will not be able to use # the SearchableText criterion when that has SolrIndex as # meta_type. TEXT_INDICES += ('SolrIndex', ) STRING_INDICES += ('SolrIndex', ) orig = _criterionRegistry.criterion2index['ATSimpleStringCriterion'] new_indices = orig + ('SolrIndex', ) # Note that simply by importing, the criterion has already been # registered, so our changes above are too late really. We fix # that here. unregisterCriterion(ATSimpleStringCriterion) registerCriterion(ATSimpleStringCriterion, new_indices) from alm.solrindex.interfaces import ISolrConnectionManager from alm.solrindex.interfaces import ISolrIndex from alm.solrindex.interfaces import ISolrIndexingWrapper from alm.solrindex.schema import SolrSchema from alm.solrindex.solrpycore import SolrConnection from alm.solrindex.handlers import PathFieldHandler disable_solr = os.environ.get('DISABLE_SOLR') log = logging.getLogger(__name__) class SolrIndex(PropertyManager, SimpleItem):
"""A selection criterion on all Taxonomy in the site""" try: __implements__ = ATBaseCriterion.__implements__ + (IATTopicSearchCriterion, ) except AttributeError: implements(IATTopicSearchCriterion) security = ClassSecurityInfo() schema = ATAllAreasCriterionSchema meta_type = 'ATAllAreasCriterion' shortDesc = 'Select Taxonomy from list' def getCurrentValues(self): catalog = getToolByName(self, 'portal_catalog') results = catalog(object_provides=IFolderTaxonomy.__identifier__, sort_on='sortable_title') return tuple(set([x.Title for x in results])) security.declareProtected(View, 'getCriteriaItems') def getCriteriaItems(self): # filter out empty strings result = [] value = tuple([ value for value in self.Value() if value ]) if not value: return () result.append((self.Field(), { 'query': value, 'operator': self.getOperator()}),) return tuple(result) registerCriterion(ATAllAreasCriterion, LIST_INDICES)
schema = ATArborealSelectionCriterionSchema meta_type = 'ATArborealSelectionCriterion' archetype_name = 'ArborealSelection Criterion' shortDesc = 'Select values from list' typeDescription= '' security.declareProtected(View, 'getCriteriaItems') def getCriteriaItems(self): result = [] if self.Value() is not '': result.append((self.Field(), self.Value())) return tuple( result ) def getArborealTrees(self): " Get all trees from the tool " portal_arboreal = getToolByName(self, 'portal_arboreal') return portal_arboreal.getTopLevelTreeNames() def getArborealTreeVocabulary(self): " Get vocab for all trees from the tool " return DisplayList([(tree, tree) for tree in self.getArborealTrees()]) def getCurrentTree(self): " fetches the correct tree " return self.getTree() registerCriterion(ATArborealSelectionCriterion, ('MultiPathIndex',))
required=0, mode="rw", write_permission=ChangeTopics, default=0, widget=BooleanWidget(label=_(u'Reverse')), ), )) class ATSortCriterion(ATBaseCriterion): """A sort criterion""" implements(IATTopicSortCriterion) security = ClassSecurityInfo() schema = ATSortCriterionSchema meta_type = 'ATSortCriterion' archetype_name = 'Sort Criterion' shortDesc = 'Sort' security.declareProtected(View, 'getCriteriaItems') def getCriteriaItems(self): result = [('sort_on', self.Field())] if self.getReversed(): result.append(('sort_order', 'reverse')) return tuple(result) registerCriterion(ATSortCriterion, SORT_INDICES)
security = ClassSecurityInfo() schema = ATDateRangeCriterionSchema meta_type = 'monet_ATDateRangeCriterion' archetype_name = 'Calendar Date Range Criterion' shortDesc = 'Calendar date range' security.declareProtected(View, 'getCriteriaItems') def getCriteriaItems(self): items = ATDateRangeCriterion.getCriteriaItems(self) if not items: return () query, range = items[0][1].values() if len(query) < 2: return () result = [] start, end = query value = tuple([a.strftime('%Y-%m-%d') for a in date_range(start, end)]) result.append((self.Field(), { 'query': value}),) return tuple(result) # trick for register the criteria in the project namespace, not Archetpyes ones old = criteria.PROJECTNAME criteria.PROJECTNAME = PROJECTNAME criteria.registerCriterion(MonetATDateCriteria, LIST_INDICES) criteria.registerCriterion(MonetATDateRangeCriterion, LIST_INDICES) criteria.PROJECTNAME = old
from Products.CMFCore.utils import getToolByName from zope.interface import implementer ATCurrentAuthorSchema = ATBaseCriterionSchema @implementer(IATTopicSearchCriterion) class ATCurrentAuthorCriterion(ATBaseCriterion): """A criterion that searches for the currently logged in user's id""" security = ClassSecurityInfo() schema = ATCurrentAuthorSchema meta_type = 'ATCurrentAuthorCriterion' archetype_name = 'Current Author Criterion' shortDesc = 'Restrict to current user' @security.protected(View) def getCriteriaItems(self): result = [] user = getToolByName( self, 'portal_membership').getAuthenticatedMember().getId() if user is not '': result.append((self.Field(), user)) return tuple(result) registerCriterion(ATCurrentAuthorCriterion, LIST_INDICES)
mutator="setValue", default="", widget=StringWidget( label=_(u'label_string_criteria_value', default=u'Value'), description=_(u'help_string_criteria_value', default=u'A string value.'))), )) class ATSimpleStringCriterion(ATBaseCriterion): """A simple string criterion""" implements(IATTopicSearchCriterion) security = ClassSecurityInfo() schema = ATSimpleStringCriterionSchema meta_type = 'ATSimpleStringCriterion' archetype_name = 'Simple String Criterion' shortDesc = 'Text' @security.protected(View) def getCriteriaItems(self): result = [] if self.Value() is not '': result.append((self.Field(), self.Value())) return tuple(result) registerCriterion(ATSimpleStringCriterion, STRING_INDICES + ('UUIDIndex', ))
description=_(u"help_boolean_criteria_bool", default=u"True or false"), ), ), ) ) @implementer(IATTopicSearchCriterion) class ATBooleanCriterion(ATBaseCriterion): """A boolean criterion""" security = ClassSecurityInfo() schema = ATBooleanCriterionSchema meta_type = "ATBooleanCriterion" archetype_name = "Boolean Criterion" shortDesc = "Boolean (True/False)" @security.protected(View) def getCriteriaItems(self): result = [] if self.getBool(): value = [1, True, "1", "True"] else: value = [0, "", False, "0", "False", None, (), [], {}, MV] result.append((self.Field(), value)) return tuple(result) registerCriterion(ATBooleanCriterion, FIELD_INDICES + ("BooleanIndex",))
shortDesc = 'Select values from list' def getCurrentValues(self): catalog = getToolByName(self, 'portal_catalog') options = catalog.uniqueValuesFor(self.Field()) # AT is currently broken, and does not accept ints as # DisplayList keys though it is supposed to (it should # probably accept Booleans as well) so we only accept strings # for now options = sorted([(o.lower(), o) for o in options if isinstance(o, basestring)]) return [o[1] for o in options] @security.protected(View) def getCriteriaItems(self): # filter out empty strings result = [] value = tuple([value for value in self.Value() if value]) if not value: return () result.append((self.Field(), { 'query': value, 'operator': self.getOperator() }), ) return tuple(result) registerCriterion(ATSelectionCriterion, LIST_INDICES)
security = ClassSecurityInfo() schema = ATSelectionCriterionSchema meta_type = 'ATSelectionCriterion' archetype_name = 'Selection Criterion' shortDesc = 'Select values from list' def getCurrentValues(self): catalog = getToolByName(self, 'portal_catalog') options = catalog.uniqueValuesFor(self.Field()) # AT is currently broken, and does not accept ints as # DisplayList keys though it is supposed to (it should # probably accept Booleans as well) so we only accept strings # for now options = [(o.lower(),o) for o in options if isinstance(o, basestring)] options.sort() return [o[1] for o in options] security.declareProtected(View, 'getCriteriaItems') def getCriteriaItems(self): # filter out empty strings result = [] value = tuple([ value for value in self.Value() if value ]) if not value: return () result.append((self.Field(), { 'query': value, 'operator': self.getOperator()}),) return tuple(result) registerCriterion(ATSelectionCriterion, LIST_INDICES)
result = [] val = self.Value() direction = self.getDirection() if val or val == 0: if direction == 'min:max': val = tuple([int(val), int(self.Value2())]) else: val = int(val) if direction: result.append((self.Field(), { 'query': val, 'range': direction })) else: result.append((self.Field(), {'query': val})) return tuple(result) @security.protected(View) def post_validate(self, REQUEST, errors): # Check that Value2 is set if range is set to min:max. direction = REQUEST.get('direction', self.getDirection()) val2 = REQUEST.get('value2', self.Value2()) if direction == 'min:max' and not val2 and not val2 == 0: errors['value2'] = ( 'You must enter a second value to do a "Between" search.') return errors registerCriterion(ATSimpleIntCriterion, LIST_INDICES)
STRING_INDICES, TEXT_INDICES, ATSimpleStringCriterion) except ImportError: pass else: # If we do not update this, Collections will not be able to use # the SearchableText criterion when that has SolrIndex as # meta_type. TEXT_INDICES += ('SolrIndex', ) STRING_INDICES += ('SolrIndex', ) orig = _criterionRegistry.criterion2index['ATSimpleStringCriterion'] new_indices = orig + ('SolrIndex', ) # Note that simply by importing, the criterion has already been # registered, so our changes above are too late really. We fix # that here. unregisterCriterion(ATSimpleStringCriterion) registerCriterion(ATSimpleStringCriterion, new_indices) from alm.solrindex.interfaces import ISolrConnectionManager from alm.solrindex.interfaces import ISolrIndex from alm.solrindex.interfaces import ISolrIndexingWrapper from alm.solrindex.schema import SolrSchema from alm.solrindex.solrpycore import SolrConnection disable_solr = os.environ.get('DISABLE_SOLR') log = logging.getLogger(__name__) class SolrIndex(PropertyManager, SimpleItem): implements(ISolrIndex)
"""A reference criterion""" implements(IATTopicSearchCriterion) security = ClassSecurityInfo() meta_type = 'ATReferenceCriterion' archetype_name = 'Reference Criterion' shortDesc = 'Select referenced content' def getCurrentValues(self): catalog = getToolByName(self, 'portal_catalog') uid_cat = getToolByName(self, 'uid_catalog') putils = getToolByName(self, 'plone_utils') options = catalog.uniqueValuesFor(self.Field()) # If the uid catalog has a Language index restrict the query by it. # We should only shows references to items in the same or the neutral # language. query = dict(UID=options, sort_on='Title') if 'Language' in uid_cat.indexes(): query['Language'] = [self.Language(), ''] brains = uid_cat(**query) display = [((putils.pretty_title_or_id(b)).lower(), b.UID, b.Title or b.id) for b in brains] display.sort() display_list = DisplayList([(d[1], d[2]) for d in display]) return display_list registerCriterion(ATReferenceCriterion, REFERENCE_INDICES)
operation = self.getOperation() if operation == 'within_day': date_range = (date.earliestTime(), date.latestTime()) return ((field, {'query': date_range, 'range': 'min:max'}), ) elif operation == 'more': if value != 0: range_op = (self.getDateRange() == '-' and 'max') or 'min' return ((field, { 'query': date.earliestTime(), 'range': range_op }), ) else: return ((field, {'query': date, 'range': 'min'}), ) elif operation == 'less': if value != 0: date_range = (self.getDateRange() == '-' and (date.earliestTime(), current_date)) or ( current_date, date.latestTime()) return ((field, { 'query': date_range, 'range': 'min:max' }), ) else: return ((field, {'query': date, 'range': 'max'}), ) else: return () registerCriterion(ATDateCriteria, DATE_INDICES)
class ATListCriterion(ATBaseCriterion): """A list criterion""" implements(IATTopicSearchCriterion) security = ClassSecurityInfo() schema = ATListCriterionSchema meta_type = 'ATListCriterion' archetype_name = 'List Criterion' shortDesc = 'List of values' security.declareProtected(View, 'getCriteriaItems') def getCriteriaItems(self): # filter out empty strings result = [] value = tuple([value for value in self.Value() if value]) if not value: return () result.append((self.Field(), { 'query': value, 'operator': self.getOperator() }), ) return tuple(result) registerCriterion(ATListCriterion, LIST_INDICES)
from Products.ATContentTypes.criteria import registerCriterion, \ LIST_INDICES from Products.ATContentTypes.interfaces import IATTopicSearchCriterion from Products.ATContentTypes.criteria.base import ATBaseCriterion from Products.ATContentTypes.criteria.schemata import ATBaseCriterionSchema ATCurrentAuthorSchema = ATBaseCriterionSchema class ATCurrentAuthorCriterion(ATBaseCriterion): """A criterion that searches for the currently logged in user's id""" __implements__ = ATBaseCriterion.__implements__ + (IATTopicSearchCriterion, ) security = ClassSecurityInfo() schema = ATCurrentAuthorSchema meta_type = 'ATCurrentAuthorCriterion' archetype_name = 'Current Author Criterion' shortDesc = 'Restrict to current user' security.declareProtected(View, 'getCriteriaItems') def getCriteriaItems(self): result = [] user = getToolByName(self, 'portal_membership').getAuthenticatedMember().getId() if user is not '': result.append((self.Field(), user)) return tuple( result ) registerCriterion(ATCurrentAuthorCriterion, LIST_INDICES)
description=_(u'help_date_range_criteria_end', default=u'The ending of the date range to search.')), ), )) class ATDateRangeCriterion(ATBaseCriterion): """A date range criterion""" implements(IATTopicSearchCriterion) security = ClassSecurityInfo() schema = ATDateRangeCriterionSchema meta_type = 'ATDateRangeCriterion' archetype_name = 'Date Range Criterion' shortDesc = 'Date range' @security.protected(View) def Value(self): return (self.getStart(), self.getEnd()) @security.protected(View) def getCriteriaItems(self): field = self.Field() value = self.Value() return ((field, {'query': value, 'range': 'min:max'}), ) registerCriterion(ATDateRangeCriterion, RELEVANT_INDICES)
security.declareProtected(View, 'getCurrentValues') def getCurrentValues(self): """Return enabled portal types""" vocab = queryUtility(IVocabularyFactory, name=VOCAB_ID)(self) portal_types = getToolByName(self, 'portal_types', None) result = [] # the vocabulary returns the values sorted by their translated title for term in vocab._terms: value = term.value # portal_type title = term.title # already translated title if self.Field() == 'Type': # Switch the value from portal_type to the Title msgid # since that is stored in the Type-index in portal_catalog # TODO: we should really use the portal_type index here and # remove the Type index value = unicode(portal_types[value].Title()) result.append((value, title)) return DisplayList(result) security.declareProtected(View, 'getCriteriaItems') def getCriteriaItems(self): result = [] if self.Value() is not '': result.append((self.Field(), self.Value())) return tuple(result) registerCriterion(ATPortalTypeCriterion, FIELD_INDICES)
# Negate the value for 'old' days if self.getDateRange() == '-': value = -value date = DateTime() + value current_date = DateTime() operation = self.getOperation() if operation == 'within_day': date_range = ( date.earliestTime(), date.latestTime() ) return ( ( field, {'query': date_range, 'range': 'min:max'} ), ) elif operation == 'more': if value != 0: range_op = (self.getDateRange() == '-' and 'max') or 'min' return ( ( field, {'query': date.earliestTime(), 'range': range_op} ), ) else: return ( ( field, {'query': date, 'range': 'min'} ), ) elif operation == 'less': if value != 0: date_range = (self.getDateRange() == '-' and (date.earliestTime(), current_date) ) or (current_date, date.latestTime()) return ( ( field, {'query': date_range, 'range': 'min:max'} ), ) else: return ( ( field, {'query': date, 'range': 'max'} ), ) else: return () registerCriterion(ATDateCriteria, DATE_INDICES)
schema = GeolocationCriterionSchema meta_type = "GeolocationCriterion" archetype_name = "Geolocation Criterion" shortDesc = "Spatial search criterion" security.declareProtected(View, "Value") def Value(self): val = map(float, self.getLowerLeft().split(",")) ur = self.getUpperRight() if ur: val += map(float, ur.split(",")) return tuple(val) security.declareProtected(View, "getCriteriaItems") def getCriteriaItems(self): result = [] val = self.Value() predicate = self.getPredicate() if predicate == "intersection": result.append((self.Field(), {"query": val, "range": predicate})) elif predicate == "distance": result.append((self.Field(), {"query": (val, self.getTolerance() * 1000.0), "range": predicate})) elif predicate == "nearest": result.append((self.Field(), {"query": (val, self.getLimit()), "range": predicate})) return tuple(result) registerCriterion(GeolocationCriterion, ("VaytrouIndex", "LocationQueryIndex"))
BooleanField('reversed', required=0, mode="rw", write_permission=ChangeTopics, default=0, widget=BooleanWidget(label=_(u'Reverse')), ), )) @implementer(IATTopicSortCriterion) class ATSortCriterion(ATBaseCriterion): """A sort criterion""" security = ClassSecurityInfo() schema = ATSortCriterionSchema meta_type = 'ATSortCriterion' archetype_name = 'Sort Criterion' shortDesc = 'Sort' @security.protected(View) def getCriteriaItems(self): result = [('sort_on', self.Field())] if self.getReversed(): result.append(('sort_order', 'reverse')) return tuple(result) registerCriterion(ATSortCriterion, SORT_INDICES)
depth = (not self.Recurse() and 1) or -1 paths = ['/'.join(o.getPhysicalPath()) for o in self.Value() if o is not None] if paths is not '': result.append((self.Field(), {'query': paths, 'depth': depth})) return tuple(result) # We need references, so we need to be partly cataloged _catalogUID = Referenceable._catalogUID _catalogRefs = Referenceable._catalogRefs _unregister = Referenceable._unregister _updateCatalog = Referenceable._updateCatalog _referenceApply = Referenceable._referenceApply _uncatalogUID = Referenceable._uncatalogUID _uncatalogRefs = Referenceable._uncatalogRefs def reindexObject(self, *args, **kwargs): self._catalogUID(self) self._catalogRefs(self) def unindexObject(self, *args, **kwargs): self._uncatalogUID(self) self._uncatalogRefs(self) def indexObject(self, *args, **kwargs): self._catalogUID(self) self._catalogRefs(self) registerCriterion(ATPathCriterion, PATH_INDICES)
description=_(u'help_list_criteria_operator', default=u'Operator used to join the tests on each value.') ), ), )) class ATListCriterion(ATBaseCriterion): """A list criterion""" implements(IATTopicSearchCriterion) security = ClassSecurityInfo() schema = ATListCriterionSchema meta_type = 'ATListCriterion' archetype_name = 'List Criterion' shortDesc = 'List of values' security.declareProtected(View, 'getCriteriaItems') def getCriteriaItems(self): # filter out empty strings result = [] value = tuple([ value for value in self.Value() if value ]) if not value: return () result.append((self.Field(), { 'query': value, 'operator': self.getOperator()}),) return tuple(result) registerCriterion(ATListCriterion, LIST_INDICES)
def getCurrentValues(self): """Return enabled portal types""" vocab = queryUtility(IVocabularyFactory, name=VOCAB_ID)(self) portal_types = getToolByName(self, 'portal_types', None) result = [] # the vocabulary returns the values sorted by their translated title for term in vocab._terms: value = term.value # portal_type title = term.title # already translated title if self.Field() == 'Type': # Switch the value from portal_type to the Title msgid # since that is stored in the Type-index in portal_catalog # TODO: we should really use the portal_type index here and # remove the Type index value = unicode(portal_types[value].Title()) result.append((value, title)) return DisplayList(result) security.declareProtected(View, 'getCriteriaItems') def getCriteriaItems(self): result = [] if self.Value() is not '': result.append((self.Field(), self.Value())) return tuple(result) registerCriterion(ATPortalTypeCriterion, FIELD_INDICES)
# set the path to the collections path path = list(aq_parent(self).getPhysicalPath()) # Now construct an absolute path based on the relative custom path. # Eat away from 'path' whenever we encounter a '..' in the relative # path. Append all other elements other than '..'. for folder in folders: if folder == '..': # chop off one level from path if path == portalPath: # can't chop off more # just return this path and leave the loop break else: path = path[:-1] elif folder == '.': # don't really need this but for being complete # strictly speaking some user may use a . aswell pass # do nothing else: path.append(folder) path = '/'.join(path) if path is not '': result.append((self.Field(), {'query': path, 'depth': depth})) return tuple(result) registerCriterion(ATRelativePathCriterion, PATH_INDICES)
), ), )) class ATDateRangeCriterion(ATBaseCriterion): """A date range criterion""" implements(IATTopicSearchCriterion) security = ClassSecurityInfo() schema = ATDateRangeCriterionSchema meta_type = 'ATDateRangeCriterion' archetype_name = 'Date Range Criterion' shortDesc = 'Date range' security.declareProtected(View, 'Value') def Value(self): return (self.getStart(), self.getEnd()) security.declareProtected(View, 'getCriteriaItems') def getCriteriaItems(self): result = [] field = self.Field() value = self.Value() return ( ( field, {'query': value, 'range': 'min:max'} ), ) registerCriterion(ATDateRangeCriterion, RELEVANT_INDICES)
shortDesc = 'Integer value or range' security.declareProtected(View, 'getCriteriaItems') def getCriteriaItems(self): result = [] val = self.Value() direction = self.getDirection() if val or val == 0: if direction == 'min:max': val = tuple([int(val), int(self.Value2())]) else: val = int(val) if direction: result.append((self.Field(), {'query': val, 'range': direction})) else: result.append((self.Field(), {'query': val})) return tuple(result) security.declareProtected(View, 'post_validate') def post_validate(self, REQUEST, errors): """Check that Value2 is set if range is set to min:max""" direction = REQUEST.get('direction', self.getDirection()) val2 = REQUEST.get('value2', self.Value2()) if direction == 'min:max' and not val2 and not val2 == 0: errors['value2']='You must enter a second value to do a "Between" search.' errors['value2']='You must enter a second value to do a "Between" search.' return errors registerCriterion(ATSimpleIntCriterion, LIST_INDICES)
] if paths is not '': result.append((self.Field(), {'query': paths, 'depth': depth})) return tuple(result) # We need references, so we need to be partly cataloged _catalogUID = Referenceable._catalogUID _catalogRefs = Referenceable._catalogRefs _unregister = Referenceable._unregister _updateCatalog = Referenceable._updateCatalog _referenceApply = Referenceable._referenceApply _uncatalogUID = Referenceable._uncatalogUID _uncatalogRefs = Referenceable._uncatalogRefs def reindexObject(self, *args, **kwargs): self._catalogUID(self) self._catalogRefs(self) def unindexObject(self, *args, **kwargs): self._uncatalogUID(self) self._uncatalogRefs(self) def indexObject(self, *args, **kwargs): self._catalogUID(self) self._catalogRefs(self) registerCriterion(ATPathCriterion, PATH_INDICES)
default=u'Value'), description=_(u'help_boolean_criteria_bool', default=u'True or false')), ), )) class ATBooleanCriterion(ATBaseCriterion): """A boolean criterion""" implements(IATTopicSearchCriterion) security = ClassSecurityInfo() schema = ATBooleanCriterionSchema meta_type = 'ATBooleanCriterion' archetype_name = 'Boolean Criterion' shortDesc = 'Boolean (True/False)' @security.protected(View) def getCriteriaItems(self): result = [] if self.getBool(): value = [1, True, '1', 'True'] else: value = [0, '', False, '0', 'False', None, (), [], {}, MV] result.append((self.Field(), value)) return tuple(result) registerCriterion(ATBooleanCriterion, FIELD_INDICES + ('BooleanIndex', ))
), ), ) ) class ATBooleanCriterion(ATBaseCriterion): """A boolean criterion""" __implements__ = ATBaseCriterion.__implements__ + (IATTopicSearchCriterion,) security = ClassSecurityInfo() schema = ATBooleanCriterionSchema meta_type = "ATBooleanCriterion" archetype_name = "Boolean Criterion" shortDesc = "Boolean (True/False)" security.declareProtected(View, "getCriteriaItems") def getCriteriaItems(self): result = [] if self.getBool(): value = [1, True, "1", "True"] else: value = [0, "", False, "0", "False", None, (), [], {}, MV] result.append((self.Field(), value)) return tuple(result) registerCriterion(ATBooleanCriterion, FIELD_INDICES)