[Zapp-cvs-commit] ZApp ZApp_MiscData.py,1.9,1.10 ZApp_Specialist.py,1.25,1.26
Brought to you by:
sspickle
|
From: <ssp...@us...> - 2003-06-20 04:15:12
|
Update of /cvsroot/zapp/ZApp
In directory sc8-pr-cvs1:/tmp/cvs-serv18192
Modified Files:
ZApp_MiscData.py ZApp_Specialist.py
Log Message:
Yee ha! It sorta works. ;->
Index: ZApp_MiscData.py
===================================================================
RCS file: /cvsroot/zapp/ZApp/ZApp_MiscData.py,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -d -r1.9 -r1.10
*** ZApp_MiscData.py 18 Jun 2003 19:11:19 -0000 1.9
--- ZApp_MiscData.py 20 Jun 2003 04:15:08 -0000 1.10
***************
*** 7,10 ****
--- 7,11 ----
dumps, loads = xmlrpclib.dumps, xmlrpclib.loads
+ StringType = type('')
from Products.ZPatterns.DataSkins import _v_dm_
***************
*** 29,32 ****
--- 30,35 ----
)
+ missing = []
+
class ZApp_MiscData(ZApp_Base.ZApp_Base):
***************
*** 67,79 ****
return self.xml
def getXMLAttr(self, attr, default=None, escNL=0):
""" get an XML based attribute."""
value = self._v_xmlDict.get(attr, default)
if isinstance(value, xmlrpclib.DateTime):
! value = value.value
! if len(value)>4 and value[4] != '-':
! value = '-'.join([value[:4],value[4:6],value[6:]])
! value = DateTime(value)
return value
def XMLAttrs(self):
--- 70,92 ----
return self.xml
+ def decodeXMLDate(self, value):
+ """ decode the ISO XML date object"""
+ value = value.value
+ if len(value)>4 and value[4] != '-':
+ value = '-'.join([value[:4],value[4:6],value[6:]])
+ return DateTime(value)
+
def getXMLAttr(self, attr, default=None, escNL=0):
""" get an XML based attribute."""
value = self._v_xmlDict.get(attr, default)
if isinstance(value, xmlrpclib.DateTime):
! value = self.decodeXMLDate(value)
return value
+
+ def getXMLDict(self):
+ """ return the XML dictionary.. """
+ result = {}
+ result.update( self._v_xmlDict )
+ return result
def XMLAttrs(self):
***************
*** 118,123 ****
storeDict = {}
! missing = []
!
for key in attr_list:
val = getattr(obj, key, missing)
--- 131,135 ----
storeDict = {}
!
for key in attr_list:
val = getattr(obj, key, missing)
***************
*** 126,136 ****
self.setXMLAttrs( storeDict )
! class ZApp_MiscDataUser: # mixin for classes that need a MiscData 'bag'.
miscDataManagerKey = None
_v_MyMDMCache = {}
! _custom_skin_scripts = ("WITH self.getMiscDataSpecialist().ZApp_getItems( objectID=self.id, Manager=self.miscDataManager) COMPUTE miscData=(RESULT and RESULT[0])",
"WITH SELF COMPUTE miscDataManager = self.getMiscDataManager()",
"WITH SELF COMPUTE safeMiscData=self.miscData or self.setupMiscData()",
--- 138,155 ----
self.setXMLAttrs( storeDict )
+
+ ZApp_Base.extendProperties( ZApp_MiscData, props )
! class ZApp_MiscDataUser:
!
! """
! MiscdDataUsers are objects that need 'peripheral' storage
! of almost anything, 'on the fly'.
! """
miscDataManagerKey = None
_v_MyMDMCache = {}
! _custom_skin_scripts = ("WITH self.getMiscData() COMPUTE miscData=RESULT",
"WITH SELF COMPUTE miscDataManager = self.getMiscDataManager()",
"WITH SELF COMPUTE safeMiscData=self.miscData or self.setupMiscData()",
***************
*** 155,188 ****
return self.findApplication().getSpecialist('MiscData')
! def setupMiscData(self, Manager=None, dataType=''):
!
! missing = []
!
! if Manager is None:
! Manager = self.getMiscDataManager()
localmdmKey = Manager + ":" + dataType
mdm = self._v_MyMDMCache.get(localmdmKey, missing)
if mdm is missing:
! md = self.getMiscDataSpecialist() # get MiscData Manager..
!
! currentBag = None
! for aBag in md.ZApp_getItems( objectID = self.id, Manager = Manager):
if aBag.dataType == dataType:
! currentBag = aBag
break
! if not currentBag:
! #
! # there is no current manager..
! #
! currentBag = md.ZApp_createNewItem( objectID = self.id, Manager = Manager, dataType=dataType )
! self._v_MyMDMCache[localmdmKey] = currentBag
! else:
! currentBag = mdm
! return currentBag
def getDataPropertyManagers(self, withID=''):
--- 174,215 ----
return self.findApplication().getSpecialist('MiscData')
! def getMiscData(self, Manager=None, dataType=''):
! """
! Get MiscData object associated with this object/Manager/dataType combination..
! """
+ Manager = Manager or self.miscDataManager
localmdmKey = Manager + ":" + dataType
mdm = self._v_MyMDMCache.get(localmdmKey, missing)
if mdm is missing:
! mds = self.getMiscDataSpecialist()
! for aBag in mds.ZApp_getItems( objectID = self.id, Manager = Manager):
if aBag.dataType == dataType:
! mdm = aBag
break
! return mdm
! def setupMiscData(self, Manager=None, dataType='', checked=0):
! """
! If you *know* that there is no MiscData for this object..
! then calling with 'checked=1' will avoid a search.
! """
!
! mdm = None
! Manager = Manager or self.miscDataManager
!
! if not checked:
! mdm = self.getMiscData( Manager=Manager, dataType=dataType )
!
! if not mdm:
! localmdmKey = Manager + ":" + dataType
! md = self.getMiscDataSpecialist()
! mdm = md.ZApp_createNewItem( objectID = self.id, Manager = Manager, dataType=dataType )
! self._v_MyMDMCache[localmdmKey] = mdm
!
! return mdm
def getDataPropertyManagers(self, withID=''):
***************
*** 216,220 ****
--- 243,362 ----
mdobs = mds and mds.ZApp_getItems( objectID=self.id, Manager=Manager, dataType=dataType)
return mdobs and mdobs[0]
+
+ def applyTypeConverter(self, typeCode, value, args=None):
+ """
+ apply a type converter/formatter to a value..
+ """
+ result = value
+ if typeCode:
+ converter = self.decodeTypeConverters.get( typeCode, missing)
+ if converter:
+ value = [value]
+ if type(converter) == StringType:
+ converter = getattr(self, converter, missing)
+
+ if args:
+ value = value + args
+
+ result = apply(converter, tuple(value))
+
+ if type(result) != StringType:
+ result = `result`
+
+ return result
+
+ encodeTypeConverters = {
+ }
+
+ 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.
+
+ each attribute is either a simple name (e.,g., 'fatherName') or it could be
+ a name with a 'typecode' that specifies a type converter/formatter to display
+ the attribute with some special formatting (e.,g., 'attrName:typecode/arg1/arg2/arg3')
+ where arg1, arg2, arg3 etc are arguments for the conversion.
+ """
+
+ attrList = getattr(self, miscNameAttr, missing)
+
+ if attrList is missing:
+ return "No Attributes for '%s'." % miscNameAttr
+
+ xmlDict = {}
+ mdobj = self.getMiscDataObj(dataType=dataType)
+ if mdobj:
+ xmlDict = mdobj.getXMLDict()
+
+ for attr_and_type in attrList:
+ attr_type_list = attr_and_type.split(':')
+ attr = attr_type_list[0]
+ if dataDict.has_key(attr):
+ typecode = ''
+ if len(attr_type_list) > 2:
+ typecodeList = attr_type_list[2].split('/')
+ typecode = typecodeList[0]
+ if len(typecodeList) > 1:
+ args = map(lambda x,ca=checkArg: ca(x), typecodeList[1:])
+
+ value = dataDict.get(attr,missing)
+ if value is not missing:
+ if typecode:
+ value = self.applyTypeConverter(typecode, value, args)
+ xmlDict[attr] = value
+
+ if not mdobj:
+ mdobj = self.setupMiscData(dataType = dataType)
+
+ mdobj.setXMLAttrs( xmlDict )
+ return xmlDict
+
+ decodeTypeConverters = {
+ 'date':'sanitizeDateString',
+ }
+
+ 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.
+
+ each attribute is either a simple name (e.,g., 'fatherName') or it could be
+ a name with a 'typecode' that specifies a type converter/formatter to display
+ the attribute with some special formatting (e.,g., 'attrName:typecode/arg1/arg2/arg3')
+ where arg1, arg2, arg3 etc are arguments for the conversion.
+ """
+
+ attrList = getattr(self, miscNameAttr, missing)
+ if attrList is missing:
+ return {}
+
+ mdobj = self.getMiscDataObj(dataType=dataType)
+ if not mdobj:
+ return {}
+
+ result = {}
+ for attr_and_type in attrList:
+ attr_type_list = attr_and_type.split(':')
+ attr = attr_type_list[0]
+ typecode = ''
+ args = None
+ if len(attr_type_list) != 1:
+ typecodeList = attr_type_list[1].split('/')
+ typecode = typecodeList[0]
+ if len(typecodeList) != 1:
+ args = map(lambda x,ca=checkArg: ca(x), typecodeList[1:])
+
+ value = mdobj.getXMLAttr(attr)
+
+ if typecode:
+ value = self.applyTypeConverter(typecode, value, args)
+
+ result[attr] = value
+ return result
+
def getObjectInfo(self):
"""
***************
*** 229,240 ****
result[p['id']] = val
!
! result.update( self.getMiscDataFor( 'miscAttributes' ))
return result
- ZApp_Base.extendProperties( ZApp_MiscData, props )
-
- missing = []
class ZApp_MiscDataPropertySheetProvider( SheetProvider ):
--- 371,378 ----
result[p['id']] = val
! result.update( self.getMiscDataFor( 'miscAttributeNames' ))
return result
class ZApp_MiscDataPropertySheetProvider( SheetProvider ):
Index: ZApp_Specialist.py
===================================================================
RCS file: /cvsroot/zapp/ZApp/ZApp_Specialist.py,v
retrieving revision 1.25
retrieving revision 1.26
diff -C2 -d -r1.25 -r1.26
*** ZApp_Specialist.py 12 Jun 2003 14:00:55 -0000 1.25
--- ZApp_Specialist.py 20 Jun 2003 04:15:08 -0000 1.26
***************
*** 42,45 ****
--- 42,46 ----
elif commit_mode:
get_transaction().commit(1)
+
from Products.ZPatterns.Specialists import Specialist
***************
*** 151,154 ****
--- 152,161 ----
"""
check_commit(1)
+
+ def final_commit(self):
+ """
+ do a full-final-total commit.
+ """
+ get_transaction().commit()
def findApplication(self):
|