icsemantic.catalog.criteria.related

Package platecom :: Package ontocatalog :: Package criteria :: Module related |
[hide private]
[frames] | no frames]

# Source Code for Module icsemantic.catalog.criteria.related

     1  """A friendly criterion for ATTopic that matches the
     2  SearchableRelatedText index parameters
     3  """
     4
     5  from Products.CMFCore.permissions import View
     6  from AccessControl import ClassSecurityInfo
     7
     8  from Products.Archetypes.atapi import Schema
     9  from Products.Archetypes.atapi import StringField, StringWidget
    10
    11  from Products.ATContentTypes.criteria import registerCriterion
    12  from Products.ATContentTypes.interfaces import IATTopicSearchCriterion
    13  from Products.ATContentTypes.permission import ChangeTopics
    14  from Products.ATContentTypes.criteria.base import ATBaseCriterion
    15  from Products.ATContentTypes.criteria.schemata import ATBaseCriterionSchema
    16
    17  from platecom.ontocatalog import OntoCatalogMessageFactory as _
    18
    19
    20  ATRelatedCriterionSchema = ATBaseCriterionSchema + Schema((
    21      StringField('value',
    22                  required=1,
    23                  mode="rw",
    24                  write_permission=ChangeTopics,
    25                  accessor="Value",
    26                  mutator="setValue",
    27                  default="",
    28                  widget=StringWidget(
    29                      label=_(u'label_related_criterion_value', default=u'Value'),
    30                      description=_(u'help_related_criterion_value',
    31                                    default=u'A string value.'))
    32                  ),
    33      StringField('context',
    34                  required=0,
    35                  mode="rw",
    36                  write_permission=ChangeTopics,
    37                  accessor="Context",
    38                  mutator="setContext",
    39                  default="",
    40                  widget=StringWidget(
    41                      label=_(u'label_related_criterion_value',
    42                              default=u'Context'),
    43                      description=_(u'help_related_criterion_value',
    44                                    default=u'A string value for the context.'))
    45                  ),
    46      ))
    47
    48
    49 -class ATRelatedCriterion(ATBaseCriterion):
    50      """A related text criterion"""
    51
    52      __implements__ = ATBaseCriterion.__implements__ + (IATTopicSearchCriterion,)
    53
    54      security       = ClassSecurityInfo()
    55      schema         = ATRelatedCriterionSchema
    56      meta_type      = 'ATRelatedCriterion'
    57      archetype_name = 'Friendly Related Criterion'
    58      shortDesc      = 'Related Criterion'
    59
    60      security.declareProtected(View, 'getCriteriaItems')
    61 -    def getCriteriaItems(self):
    62          result = []
    63          value = self.Value()
    64          context = self.Context()
    65
    66          if value is not '':
    67              result.append((self.Field(), value))
    68
    69          if context is not '':
    70              result.append((self.Field(), {'query': value, 'context': context}))
    71
    72          return tuple(result)
    73
    74  registerCriterion(ATRelatedCriterion, ['RelatedIndex'])
    75