icsemantic.catalog.criteria.translation

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

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

     1  """A friendly criterion for ATTopic that matches the
     2  SearchableTranslatedText 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  from Products.Archetypes.atapi import LinesField, MultiSelectionWidget
    11
    12  from Products.ATContentTypes.criteria import registerCriterion
    13  from Products.ATContentTypes.interfaces import IATTopicSearchCriterion
    14  from Products.ATContentTypes.permission import ChangeTopics
    15  from Products.ATContentTypes.criteria.base import ATBaseCriterion
    16  from Products.ATContentTypes.criteria.schemata import ATBaseCriterionSchema
    17
    18  from Products.Archetypes.atapi import DisplayList
    19
    20  from platecom.ontocatalog import OntoCatalogMessageFactory as _
    21
    22
    23  ATTranslationCriterionSchema = ATBaseCriterionSchema + Schema((
    24      StringField('value',
    25                  required=1,
    26                  mode="rw",
    27                  write_permission=ChangeTopics,
    28                  accessor="Value",
    29                  mutator="setValue",
    30                  default="",
    31                  widget=StringWidget(
    32                      label=_(u'label_translation_criterion_value',
    33                              default=u'Value'),
    34                      description=_(u'help_translation_criterion_value',
    35                                    default=u'A string value.'))
    36                  ),
    37      LinesField('language',
    38                  required=1,
    39                  mode="rw",
    40                  write_permission=ChangeTopics,
    41                  accessor="Language",
    42                  mutator="setLanguage",
    43                  default=[],
    44                  vocabulary="getLanguages",
    45                  widget=MultiSelectionWidget(
    46                      label=_(u'label_translation_criterion_value',
    47                              default=u'Language'),
    48                      description=_(u'help_translation_criterion_value',
    49                                    default=u'A list of languages.'))
    50                  ),
    51
    52      ))
    53
    54
    55 -class ATTranslationCriterion(ATBaseCriterion):
    56      """A translation text criterion"""
    57
    58      __implements__ = ATBaseCriterion.__implements__ + (IATTopicSearchCriterion,)
    59
    60      security       = ClassSecurityInfo()
    61      schema         = ATTranslationCriterionSchema
    62      meta_type      = 'ATTranslationCriterion'
    63      archetype_name = 'Friendly Translation Criterion'
    64      shortDesc      = 'Translation Criterion'
    65
    66 -    def getLanguages(self):
    67          langs = self.portal_languages.getAvailableLanguages()
    68
    69          try:
    70              display_list = DisplayList(zip(langs.keys(), \
    71                                         [i['name'] for i in langs.values()]))
    72          except:
    73              display_list = DisplayList(zip(langs.keys(), \
    74                                         [i for i in langs.values()]))
    75
    76          return display_list
    77
    78      security.declareProtected(View, 'getCriteriaItems')
    79 -    def getCriteriaItems(self):
    80          result = []
    81          value = self.Value()
    82          language = self.Language()
    83
    84          if value is not '':
    85              result.append((self.Field(), value))
    86
    87          if language is not '':
    88              result.append((self.Field(),
    89                             {'query': value, 'language': language}))
    90
    91          return tuple(result)
    92
    93
    94  registerCriterion(ATTranslationCriterion, ['TranslationIndex'])
    95