Back to index

plone3  3.1.7
portaltype.py
Go to the documentation of this file.
00001 ##############################################################################
00002 #
00003 # ATContentTypes http://plone.org/products/atcontenttypes/
00004 # Archetypes reimplementation of the CMF core types
00005 #
00006 # Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
00007 # Copyright (c) 2003-2006 AT Content Types development team
00008 #
00009 # This software is subject to the provisions of the Zope Public License,
00010 # Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
00011 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
00012 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00013 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
00014 # FOR A PARTICULAR PURPOSE
00015 #
00016 ##############################################################################
00017 """ Topic:
00018 
00019 
00020 """
00021 
00022 __author__  = 'Godefroid Chapelle'
00023 __docformat__ = 'restructuredtext'
00024 __old_name__ = 'Products.ATContentTypes.types.criteria.ATPortalTypeCriterion'
00025 
00026 from Products.CMFCore.permissions import View
00027 from Products.CMFCore.utils import getToolByName
00028 from AccessControl import ClassSecurityInfo
00029 
00030 from Products.Archetypes.atapi import DisplayList
00031 
00032 from Products.ATContentTypes.criteria import registerCriterion
00033 from Products.ATContentTypes.criteria import FIELD_INDICES
00034 from Products.ATContentTypes.interfaces import IATTopicSearchCriterion
00035 from Products.ATContentTypes.criteria.selection import ATSelectionCriterion
00036 
00037 from Products.ATContentTypes import ATCTMessageFactory as _
00038 
00039 ATPortalTypeCriterionSchema = ATSelectionCriterion.schema.copy()
00040 
00041 val_widget = ATPortalTypeCriterionSchema['value'].widget
00042 val_widget.description=_(u'help_portal_type_criteria_value',
00043                          default=u'One of the available content types.')
00044 ATPortalTypeCriterionSchema['value'].widget = val_widget
00045 
00046     
00047 class ATPortalTypeCriterion(ATSelectionCriterion):
00048     """A portal_types criterion"""
00049 
00050     __implements__ = ATSelectionCriterion.__implements__ + (IATTopicSearchCriterion, )
00051     security       = ClassSecurityInfo()
00052     schema         = ATPortalTypeCriterionSchema
00053     meta_type      = 'ATPortalTypeCriterion'
00054     archetype_name = 'Portal Types Criterion'
00055     shortDesc      = 'Select content types'
00056 
00057     security.declareProtected(View, 'getCurrentValues')
00058     def getCurrentValues(self):
00059          """Return enabled portal types"""
00060          plone_tool = getToolByName(self, 'plone_utils')
00061          portal_types = plone_tool.getUserFriendlyTypes()
00062          getSortTuple = lambda x: ((x.Title() or x).lower(),
00063            unicode(x.Title() or x), x.Title() or x)
00064 
00065          if self.Field() == 'Type':
00066             types_tool = getToolByName(self, 'portal_types')
00067             get_type = types_tool.getTypeInfo
00068             # first item in tuple is sortkey, second is untranslated Title
00069             # and third is Title as a translatable Message object
00070             portal_types = [getSortTuple(get_type(t)) for t in portal_types]
00071          else:
00072             portal_types = [(t.lower(), t, t) for t in portal_types]
00073 
00074          portal_types.sort()
00075          portal_types = [(p[1], p[2]) for p in portal_types]
00076          return DisplayList(portal_types)
00077 
00078     security.declareProtected(View, 'getCriteriaItems')
00079     def getCriteriaItems(self):
00080         result = []
00081 
00082         if self.Value() is not '':
00083             result.append((self.Field(), self.Value()))
00084 
00085         return tuple(result)
00086 
00087 registerCriterion(ATPortalTypeCriterion, FIELD_INDICES)