Back to index

plone3  3.1.7
path.py
Go to the documentation of this file.
00001 #  ATContentTypes http://plone.org/products/atcontenttypes/
00002 #  Archetypes reimplementation of the CMF core types
00003 #  Copyright (c) 2003-2006 AT Content Types development team
00004 #
00005 #  This program is free software; you can redistribute it and/or modify
00006 #  it under the terms of the GNU General Public License as published by
00007 #  the Free Software Foundation; either version 2 of the License, or
00008 #  (at your option) any later version.
00009 #
00010 #  This program is distributed in the hope that it will be useful,
00011 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 #  GNU General Public License for more details.
00014 #
00015 #  You should have received a copy of the GNU General Public License
00016 #  along with this program; if not, write to the Free Software
00017 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 #
00019 """ Topic:
00020 
00021 """
00022 
00023 __author__  = 'Alec Mitchell'
00024 __docformat__ = 'restructuredtext'
00025 __old_name__ = 'Products.ATContentTypes.types.criteria.ATPathCriterion'
00026 
00027 from Products.CMFCore.permissions import View
00028 from AccessControl import ClassSecurityInfo
00029 
00030 from Products.Archetypes.atapi import Schema
00031 from Products.Archetypes.atapi import BooleanField
00032 from Products.Archetypes.atapi import BooleanWidget
00033 from Products.Archetypes.atapi import ReferenceField
00034 from Products.Archetypes.Referenceable import Referenceable
00035 
00036 from Products.ATContentTypes.criteria import registerCriterion
00037 from Products.ATContentTypes.criteria import PATH_INDICES
00038 from Products.ATContentTypes.interfaces import IATTopicSearchCriterion
00039 from Products.ATContentTypes.permission import ChangeTopics
00040 from Products.ATContentTypes.criteria.base import ATBaseCriterion
00041 from Products.ATContentTypes.criteria.schemata import ATBaseCriterionSchema
00042 from Products.ATReferenceBrowserWidget.ATReferenceBrowserWidget import ReferenceBrowserWidget
00043 
00044 from Products.ATContentTypes import ATCTMessageFactory as _
00045 
00046 ATPathCriterionSchema = ATBaseCriterionSchema + Schema((
00047     ReferenceField('value',
00048                 required=1,
00049                 mode="rw",
00050                 write_permission=ChangeTopics,
00051                 accessor="Value",
00052                 mutator="setValue",
00053                 allowed_types_method="getNavTypes",
00054                 multiValued=True,
00055                 relationship="paths",
00056                 widget=ReferenceBrowserWidget(
00057                     allow_search=1,
00058                     label=_(u'label_path_criteria_value', default=u'Folders'),
00059                     description=_(u'help_path_criteria_value',
00060                                   default=u'Folders to search in.'),
00061                     base_query={'is_folderish':True},
00062                     restrict_browse=True,
00063                     startup_directory='../')
00064                 ),
00065     BooleanField('recurse',
00066                 mode="rw",
00067                 write_permission=ChangeTopics,
00068                 accessor="Recurse",
00069                 default=False,
00070                 widget=BooleanWidget(
00071                     label=_(u'label_path_criteria_recurse', default=u'Search Sub-Folders'),
00072                     description='',
00073                     ),
00074                 ),
00075     ))
00076 
00077 class ATPathCriterion(ATBaseCriterion):
00078     """A path criterion"""
00079 
00080     __implements__ = ATBaseCriterion.__implements__ + (IATTopicSearchCriterion, )
00081     security       = ClassSecurityInfo()
00082     schema         = ATPathCriterionSchema
00083     meta_type      = 'ATPathCriterion'
00084     archetype_name = 'Path Criterion'
00085     shortDesc      = 'Location in site'
00086 
00087     def getNavTypes(self):
00088         ptool = self.plone_utils
00089         nav_types = ptool.typesToList()
00090         return nav_types
00091 
00092     # Override reference mutator, so that it always reindexes
00093     def setValue(self, value):
00094         self.getField('value').set(self, value)
00095         self.reindexObject()
00096 
00097     security.declareProtected(View, 'getCriteriaItems')
00098     def getCriteriaItems(self):
00099         result = []
00100         depth = (not self.Recurse() and 1) or -1
00101         paths = ['/'.join(o.getPhysicalPath()) for o in self.Value()]
00102 
00103         if paths is not '':
00104             result.append((self.Field(), {'query': paths, 'depth': depth}))
00105 
00106         return tuple( result )
00107 
00108     # We need references, so we need to be partly cataloged
00109     _catalogUID = Referenceable._catalogUID
00110     _catalogRefs = Referenceable._catalogRefs
00111     _unregister = Referenceable._unregister
00112     _updateCatalog = Referenceable._updateCatalog
00113     _referenceApply = Referenceable._referenceApply
00114     _uncatalogUID = Referenceable._uncatalogUID
00115     _uncatalogRefs = Referenceable._uncatalogRefs
00116 
00117     def reindexObject(self, *args, **kwargs):
00118         self._catalogUID(self)
00119         self._catalogRefs(self)
00120 
00121     def unindexObject(self, *args, **kwargs):
00122         self._uncatalogUID(self)
00123         self._uncatalogRefs(self)
00124 
00125     def indexObject(self, *args, **kwargs):
00126         self._catalogUID(self)
00127         self._catalogRefs(self)
00128 
00129 registerCriterion(ATPathCriterion, PATH_INDICES)