[Zapp-cvs-commit] ZApp ZApp_DublinCoreMixin.py,NONE,1.1 ZApp_CMFBase.py,1.20,1.21 ZApp_MiscData.py,1
Brought to you by:
sspickle
|
From: <ssp...@us...> - 2004-01-02 22:07:04
|
Update of /cvsroot/zapp/ZApp
In directory sc8-pr-cvs1:/tmp/cvs-serv380
Modified Files:
ZApp_CMFBase.py ZApp_MiscData.py
Added Files:
ZApp_DublinCoreMixin.py
Log Message:
adding metadata code to ZApp_CMF stuff
--- NEW FILE: ZApp_DublinCoreMixin.py ---
#
# ZApp_DublinCore is just a 'shim' that allows ZApp to shadow dublin core metadata... without
# adding significant overhead...
#
from Products.CMFDefault.DublinCore import DefaultDublinCoreImpl
from ComputedAttribute import ComputedAttribute
class ZApp_MetaMethodInvoker:
"""
This is an object that is ised to override a block of methods with
a behavior that consists of referencing a computed attribute
(_v_meta) of an instance before calling the original
method of the superclass.
This instance smells like a class method (and it is stored in
the class as if it really were a class method). It is assigned
as a computed attribute that only gets used if the orginally targeted
method of the instance is called.
"""
def __init__(self, method):
self.method = method
def setInstance(self, inst):
self.inst = inst
return self
def __call__(self, *args, **kw):
""" perform the method of the superclass """
self.inst._v_meta
return apply(self.method, (self.inst,) + args, kw)
class ZApp_DublinCoreMixin( DefaultDublinCoreImpl ):
__per_transaction_cache_attrs__ = ('_v_meta',)
_custom_skin_scripts = ('WHEN OBJECT CHANGED STORE metadata_modified USING self.zapp_cmf_metadataChanged and self.zapp_cmf_metadataChanged()',)
class_default_for_zapp_cmf_metadataChanged = None
class_default_for_metadata_modified = 0
def _v_meta(self):
"""metadata changed trigger... """
self._v_Keeper # make sure we reset at transaction boundaries..
self.metadata_modified = 1
return 1
_v_meta = ComputedAttribute( _v_meta )
#
# This is a bit tricky. We want to insert ourselves into the dublin core..
# Here's a way to do it without re-writing all the methods.... or even
# knowing what they are.
#
methodType = type(ZApp_DublinCoreMixin._v_meta)
for methodName in dir(DefaultDublinCoreImpl):
theMethod = getattr(DefaultDublinCoreImpl,methodName)
if methodName[:3] == 'set' and type(theMethod) == methodType:
setattr(ZApp_DublinCoreMixin, methodName, ComputedAttribute(ZApp_MetaMethodInvoker( theMethod ).setInstance))
Index: ZApp_CMFBase.py
===================================================================
RCS file: /cvsroot/zapp/ZApp/ZApp_CMFBase.py,v
retrieving revision 1.20
retrieving revision 1.21
diff -C2 -d -r1.20 -r1.21
*** ZApp_CMFBase.py 16 Dec 2003 17:19:44 -0000 1.20
--- ZApp_CMFBase.py 2 Jan 2004 22:07:01 -0000 1.21
***************
*** 30,34 ****
#
- from Products.CMFDefault.DublinCore import DefaultDublinCoreImpl
from Products.CMFDefault.SkinnedFolder import SkinnedFolder
from AccessControl import ClassSecurityInfo, getSecurityManager
--- 30,33 ----
***************
*** 39,42 ****
--- 38,42 ----
from OFS.CopySupport import CopySource
from Acquisition import ImplicitAcquisitionWrapper,aq_base
+ from ZApp_DublinCoreMixin import ZApp_DublinCoreMixin
from DateTime import DateTime
***************
*** 44,48 ****
import tempfile
! class ZApp_CMFBase(FreeRangeDS, SkinnedFolder, ZApp_Base, DefaultDublinCoreImpl, ZApp_MiscDataUser, ZApp_RelatedObject):
meta_type = 'ZApp CMF Content'
--- 44,48 ----
import tempfile
! class ZApp_CMFBase(FreeRangeDS, SkinnedFolder, ZApp_Base, ZApp_DublinCoreMixin, ZApp_MiscDataUser, ZApp_RelatedObject):
meta_type = 'ZApp CMF Content'
***************
*** 50,53 ****
--- 50,65 ----
isPrincipiaFolderish = 1
+ __implements__ = (
+ ZApp_DublinCoreMixin.__implements__,
+ SkinnedFolder.__implements__,
+ )
+
+ manage_options = (
+ { 'label' : 'Dublin Core'
+ , 'action' : 'manage_metadata'
+ }
+ ,) \
+ + SkinnedFolder.manage_options
+
class_default_for_copyable = 0 # make these guys default to 'not copyable'
***************
*** 88,92 ****
return result
! def setMiscData(self, dataDict=None, **kw):
"""
Set miscellaneous data for this object..
--- 100,104 ----
return result
! def setMiscData(self, dataDict=None, dataType='', **kw):
"""
Set miscellaneous data for this object..
***************
*** 95,99 ****
currDict.update(kw)
currDict.update(dataDict)
! self.safeMiscData.setXMLAttrs( currDict )
return "OK!"
--- 107,112 ----
currDict.update(kw)
currDict.update(dataDict)
! miscData = self.getMiscData( dataType=dataType, createIfNone=1)
! miscData.setXMLAttrs( currDict )
return "OK!"
Index: ZApp_MiscData.py
===================================================================
RCS file: /cvsroot/zapp/ZApp/ZApp_MiscData.py,v
retrieving revision 1.23
retrieving revision 1.24
diff -C2 -d -r1.23 -r1.24
*** ZApp_MiscData.py 31 Dec 2003 18:04:21 -0000 1.23
--- ZApp_MiscData.py 2 Jan 2004 22:07:01 -0000 1.24
***************
*** 218,223 ****
then calling with 'checked=1' will avoid a search.
"""
-
-
mdm = None
Manager = Manager or self.miscDataManager
--- 218,221 ----
***************
*** 286,293 ****
}
! def setMiscDataFor(self, dataDict, miscNameAttr='miscAttributeNames', dataType=''):
"""
check for the existence of an attribute of this object with the name given by miscNameAttr
! (e.g., check for the 'miscAttributeNames' attribute of self by default). If this attribute exists,
use it to access a MiscData object that corresponds to this set of attributes.
--- 284,293 ----
}
! DEFAULT_MISCNAMEATTR='miscAttributeNames'
!
! def setMiscDataFor(self, dataDict, miscNameAttr=DEFAULT_MISCNAMEATTR , dataType=''):
"""
check for the existence of an attribute of this object with the name given by miscNameAttr
! (e.g., check for the DEFAULT_MISCNAMEATTR attribute of self by default). If this attribute exists,
use it to access a MiscData object that corresponds to this set of attributes.
***************
*** 335,342 ****
}
! def getMiscDataFor(self, miscNameAttr='miscAttributeNames', dataType=''):
"""
check for the existence of an attribute of this object with the name given by miscNameAttr
! (e.g., check for the 'miscAttributeNames' attribute of self by default). If this attribute exists,
use it to access a MiscData object that corresponds to this set of attributes.
--- 335,342 ----
}
! def getMiscDataFor(self, miscNameAttr=DEFAULT_MISCNAMEATTR, dataType=''):
"""
check for the existence of an attribute of this object with the name given by miscNameAttr
! (e.g., check for the DEFAULT_MISCNAMEATTR attribute of self by default). If this attribute exists,
use it to access a MiscData object that corresponds to this set of attributes.
***************
*** 378,400 ****
return result
! def getObjectInfo(self):
"""
return known attributes/values for object..
"""
result = {'objectID':self.getId()}
- for p in self._properties:
- if p['id']:
- val = getattr(self, p['id'])
- if p['type'] == 'date':
- val = (hasattr(val,'ISO') and val.ISO()) or `val`
- elif p['type'] != 'string':
- if val:
- val = `val`
- elif val is None:
- val = ''
-
- result[p['id']] = val
! result.update( self.getMiscDataFor( 'miscAttributeNames' ))
return result
--- 378,403 ----
return result
! def getObjectInfo(self, miscNameAttr=DEFAULT_MISCNAMEATTR):
"""
return known attributes/values for object..
"""
+
result = {'objectID':self.getId()}
! if miscNameAttr==DEFAULT_MISCNAMEATTR:
! for p in self._properties:
! if p['id']:
! val = getattr(self, p['id'])
! if p['type'] == 'date':
! val = (hasattr(val,'ISO') and val.ISO()) or `val`
! elif p['type'] != 'string':
! if val:
! val = `val`
! elif val is None:
! val = ''
!
! result[p['id']] = val
!
! result.update( self.getMiscDataFor( miscNameAttr ))
return result
|