Back to index

plone3  3.1.7
base.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__  = 'Christian Heimes <tiran@cheimes.de>'
00023 __docformat__ = 'restructuredtext'
00024 
00025 from Products.Archetypes.atapi import BaseContentMixin
00026 
00027 from Products.CMFCore.permissions import View
00028 from AccessControl import ClassSecurityInfo
00029 from Globals import InitializeClass
00030 
00031 from Products.Archetypes.ClassGen import generateClass
00032 from Products.ATContentTypes.interfaces import IATTopicCriterion
00033 from Products.ATContentTypes.criteria.schemata import ATBaseCriterionSchema
00034 
00035 from Products.CMFCore.PortalContent import PortalContent
00036 from Products.Archetypes.interfaces.base import IBaseContent
00037 
00038 class NonRefCatalogContent(BaseContentMixin):
00039     """Base class for content that is neither referenceable nor in the catalog
00040     """
00041 
00042     isReferenceable = None
00043 
00044     __implements__ = (PortalContent.__implements__, IATTopicCriterion,
00045                       IBaseContent)
00046 
00047     # reference register / unregister methods
00048     def _register(self, *args, **kwargs): pass
00049     def _unregister(self, *args, **kwargs): pass
00050     def _updateCatalog(self, *args, **kwargs): pass
00051     def _referenceApply(self, *args, **kwargs): pass
00052     def _uncatalogUID(self, *args, **kwargs): pass
00053     def _uncatalogRefs(self, *args, **kwargs): pass
00054 
00055     # catalog methods
00056     def indexObject(self, *args, **kwargs): pass
00057     def unindexObject(self, *args, **kwargs): pass
00058     def reindexObject(self, *args, **kwargs): pass
00059 
00060 class ATBaseCriterion(NonRefCatalogContent):
00061     """A basic criterion"""
00062 
00063     security = ClassSecurityInfo()
00064 
00065     __implements__ = (IATTopicCriterion, NonRefCatalogContent.__implements__)
00066 
00067     schema = ATBaseCriterionSchema
00068     meta_type = 'ATBaseCriterion'
00069     archetype_name = 'Base Criterion'
00070 
00071     def __init__(self, id=None, field=None, oid=None):
00072         if oid is not None:
00073             if field is None:
00074                 field = id
00075             id = oid
00076         assert id
00077         NonRefCatalogContent.__init__(self, id)
00078         self.getField('id').set(self, id)
00079         self.getField('field').set(self, field)
00080 
00081     security.declareProtected(View, 'getId')
00082     def getId(self):
00083         """Get the object id"""
00084         return str(self.id)
00085 
00086     def setId(self, value, *kw):
00087         """Setting a new ID isn't allowed
00088         """
00089         assert value == self.getId(), 'You are not allowed to change the id'
00090 
00091     security.declareProtected(View, 'Type')
00092     def Type(self):
00093         return self.archetype_name
00094 
00095     security.declareProtected(View, 'Description')
00096     def Description(self):
00097         lines = [ line.strip() for line in self.__doc__.splitlines() ]
00098         return ' '.join( [ line for line in lines if line ] )
00099 
00100     security.declareProtected(View, 'getCriteriaItems')
00101     def getCriteriaItems(self):
00102         """Return a sequence of items to be used to build the catalog query.
00103         """
00104         return ()
00105 
00106 # because I don't register the class I've to generator it on my own. Otherwise
00107 # I'm not able to unit test it in the right way.
00108 generateClass(ATBaseCriterion)
00109 InitializeClass(ATBaseCriterion)