Annotation of ZSQLExtend/ZSQLMetaData.py, revision 1.1

1.1     ! dwinter     1: #objekte zur erzeugung und verwaltung von metadaten
        !             2: 
        !             3: from OFS.Folder import Folder
        !             4: from Globals import Persistent
        !             5: from Acquisition import Implicit
        !             6: from Products.PageTemplates.PageTemplateFile import PageTemplateFile
        !             7: from Products.PageTemplates.PageTemplate import PageTemplate
        !             8: from OFS.SimpleItem import SimpleItem
        !             9: 
        !            10: import string
        !            11: 
        !            12: 
        !            13: class ZSQLMetadataMapping(SimpleItem):
        !            14:     """Einfaches Mapping Object"""
        !            15: 
        !            16:     meta_type="ZSQLMetadataMapping"
        !            17: 
        !            18:     def readFieldsFromParent(self):
        !            19:         """read all elements from root"""
        !            20:         return self.ac_parent.fields
        !            21:     
        !            22:     def __init__(self,id,title,arglist):
        !            23:         """init"""
        !            24:         self.id=id
        !            25:         self.title=title
        !            26: 
        !            27:         for fieldName in arglist.keys():
        !            28:             setattr(self,"md_"+fieldName,arglist[fieldName])
        !            29: 
        !            30:     manage_options = SimpleItem.manage_options+(
        !            31:         {'label':'Main Config','action':'change_ZSQLMappingForm'},
        !            32:         )
        !            33: 
        !            34:     def getValue(self,fieldName):
        !            35:         """get md value"""
        !            36:         return getattr(self,"md_"+fieldName)
        !            37: 
        !            38:     def generateMappingHash(self):
        !            39:         """erzeugen des Hash"""
        !            40:         hash={}
        !            41:         for field in self.fieldList:
        !            42:             hash[field]=getattr(self,"md_"+field)
        !            43:         return hash
        !            44: 
        !            45:    
        !            46:     
        !            47:     def change_ZSQLMappingForm(self):
        !            48:         """change"""
        !            49:         pt=PageTemplateFile('Products/ZSQLExtend/ChangeZSQLMetadataMapping.zpt').__of__(self)
        !            50:         return pt()
        !            51:     
        !            52:     def change_ZSQLMapping(self,titleOfObject,RESPONSE=None):
        !            53:         """change"""
        !            54: 
        !            55:         self.title=titleOfObject
        !            56:         arglist=self.REQUEST.form
        !            57:         for fieldName in arglist.keys():
        !            58:             setattr(self,"md_"+fieldName,arglist[fieldName])
        !            59: 
        !            60:         if RESPONSE is not None:
        !            61:             RESPONSE.redirect('manage_main')
        !            62: 
        !            63:     
        !            64: 
        !            65: def manage_addZSQLMetadataMappingForm(self):
        !            66:     """interface for adding the OSAS_root"""
        !            67:     pt=PageTemplateFile('Products/ZSQLExtend/AddZSQLMetadataMapping.zpt').__of__(self)
        !            68:     return pt()
        !            69: 
        !            70: def manage_addZSQLMetadataMapping(self,idOfObject,titleOfObject,RESPONSE=None):
        !            71:     """add the OSAS_root"""
        !            72:     
        !            73:     argList={}
        !            74:     for arg in self.REQUEST.form.keys():
        !            75:         if not (arg in ['idOfObject','titleOfObject']):
        !            76:             argList[arg]=self.REQUEST.form[arg]
        !            77:         
        !            78:     newObj=ZSQLMetadataMapping(idOfObject,titleOfObject,argList)
        !            79:     self._setObject(idOfObject,newObj)
        !            80:     if RESPONSE is not None:
        !            81:         RESPONSE.redirect('manage_main')
        !            82: 
        !            83:    
        !            84: class ZSQLMetadataMappingRoot(Persistent, Implicit, Folder):
        !            85:     """Root ordner für Metadaten set"""
        !            86: 
        !            87:     meta_type='ZSQLMetadataMappingRoot'
        !            88: 
        !            89:     def __init__(self,id,title,fields):
        !            90:         self.id=id
        !            91:         self.title=title
        !            92:         
        !            93:         self.fieldList=fields.split(",")[0:]
        !            94: 
        !            95:     
        !            96:     manage_options = Folder.manage_options+(
        !            97:         {'label':'Main Config','action':'change_ZSQLMappingRootForm'},
        !            98:         )
        !            99: 
        !           100: 
        !           101:     def generateMappingList(self):
        !           102:         """Erzeuge Mapping"""
        !           103:         mapping={}
        !           104:         for dict in self.__dict__:
        !           105:             #print dict
        !           106:             obj=getattr(self,dict)
        !           107:             if hasattr(obj,'meta_type'):
        !           108:                 if obj.meta_type=="ZSQLMetadataMapping":
        !           109:                     mapping[obj.getId()]=obj.generateMappingHash()
        !           110:         return mapping
        !           111:     
        !           112:     def generateMappingForType(self,type,clean="yes"):
        !           113:         """erzeuge spezifisches Mapping"""
        !           114:         hash=self.generateMappingList()
        !           115:         if hash.has_key(type):
        !           116:             if clean=="yes":
        !           117:                 temp={}
        !           118:                 for x in hash[type].keys():
        !           119:                     if not hash[type][x]=="":
        !           120:                         temp[x]=hash[type][x]
        !           121:                 return temp
        !           122:             else:
        !           123:                 return hash[type]
        !           124:         
        !           125:         else:
        !           126:             return {}
        !           127: 
        !           128:     def getFieldList(self):
        !           129:         """erzeuge string aus fields"""
        !           130:         return string.join(self.fieldList,",")
        !           131: 
        !           132:     def getFields(self):
        !           133:         """ausgabe der Felder"""
        !           134:         return self.fieldList
        !           135: 
        !           136:     def getTypeTitle(self,id):
        !           137:         """Title von ID"""
        !           138:         try:
        !           139:             obj=getattr(self,id)
        !           140:             return obj.title
        !           141:         except:
        !           142:             return id
        !           143:         
        !           144:     def getStoredTypes(self):
        !           145:         """Gebe gespeicherte typen zurück"""
        !           146:         
        !           147:         types=[]
        !           148:         for dict in self.__dict__:
        !           149:             
        !           150:             obj=getattr(self,dict)
        !           151:             if hasattr(obj,'meta_type'):
        !           152:                 if obj.meta_type=="ZSQLMetadataMapping":
        !           153:                     #print obj
        !           154:                     if obj.title=="":
        !           155:                         title=obj.id
        !           156:                     else:
        !           157:                         title=obj.title
        !           158:                     types.append((obj.id,title))
        !           159:         return types
        !           160:     
        !           161:     def change_ZSQLMappingRootForm(self):
        !           162:         """change"""
        !           163:         pt=PageTemplateFile('Products/ZSQLExtend/ChangeZSQLMetadataMappingRoot.zpt').__of__(self)
        !           164:         return pt()
        !           165: 
        !           166: 
        !           167:     def change_ZSQLMetadataMapping(self,title,fields,RESPONSE=None):
        !           168:         """change entries"""
        !           169:         self.title=title
        !           170:         self.fieldList=fields.split(",")[0:]
        !           171: 
        !           172:         if RESPONSE is not None:
        !           173:             RESPONSE.redirect('manage_main')
        !           174: 
        !           175:     
        !           176: 
        !           177: def manage_addZSQLMetadataMappingRootForm(self):
        !           178:     """interface for adding the OSAS_root"""
        !           179:     pt=PageTemplateFile('Products/ZSQLExtend/AddZSQLMetadataMappingRoot.zpt').__of__(self)
        !           180:     return pt()
        !           181: 
        !           182: def manage_addZSQLMetadataMappingRoot(self,id,title,fields,RESPONSE=None):
        !           183:     """add the OSAS_root"""
        !           184:     newObj=ZSQLMetadataMappingRoot(id,title,fields)
        !           185:     self._setObject(id,newObj)
        !           186:     if RESPONSE is not None:
        !           187:         RESPONSE.redirect('manage_main')
        !           188: 
        !           189:     

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>