| 1 | ################################################################################
|
|---|
| 2 | # _objchildren.py
|
|---|
| 3 | #
|
|---|
| 4 | # $Id: _objchildren.py,v 1.7 2004/11/24 21:02:52 zmsdev Exp $
|
|---|
| 5 | # $Name:$
|
|---|
| 6 | # $Author: zmsdev $
|
|---|
| 7 | # $Revision: 1.7 $
|
|---|
| 8 | #
|
|---|
| 9 | # This program is free software; you can redistribute it and/or
|
|---|
| 10 | # modify it under the terms of the GNU General Public License
|
|---|
| 11 | # as published by the Free Software Foundation; either version 2
|
|---|
| 12 | # of the License, or (at your option) any later version.
|
|---|
| 13 | #
|
|---|
| 14 | # This program is distributed in the hope that it will be useful,
|
|---|
| 15 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|---|
| 17 | # GNU General Public License for more details.
|
|---|
| 18 | #
|
|---|
| 19 | # You should have received a copy of the GNU General Public License
|
|---|
| 20 | # along with this program; if not, write to the Free Software
|
|---|
| 21 | # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|---|
| 22 | ################################################################################
|
|---|
| 23 |
|
|---|
| 24 | # Imports.
|
|---|
| 25 | import copy
|
|---|
| 26 | import time
|
|---|
| 27 | import urllib
|
|---|
| 28 | # Product Imports.
|
|---|
| 29 | import _blobfields
|
|---|
| 30 | import _fileutil
|
|---|
| 31 | import _globals
|
|---|
| 32 |
|
|---|
| 33 |
|
|---|
| 34 | ################################################################################
|
|---|
| 35 | ################################################################################
|
|---|
| 36 | ###
|
|---|
| 37 | ### Object Children
|
|---|
| 38 | ###
|
|---|
| 39 | ################################################################################
|
|---|
| 40 | ################################################################################
|
|---|
| 41 | class ObjChildren:
|
|---|
| 42 |
|
|---|
| 43 | # Management Permissions.
|
|---|
| 44 | # -----------------------
|
|---|
| 45 | __authorPermissions__ = (
|
|---|
| 46 | 'manage_initObjChild',
|
|---|
| 47 | )
|
|---|
| 48 | __ac_permissions__=(
|
|---|
| 49 | ('ZMS Author', __authorPermissions__),
|
|---|
| 50 | )
|
|---|
| 51 |
|
|---|
| 52 | """
|
|---|
| 53 | ############################################################################
|
|---|
| 54 | ###
|
|---|
| 55 | ### Constructor
|
|---|
| 56 | ###
|
|---|
| 57 | ############################################################################
|
|---|
| 58 | """
|
|---|
| 59 | # --------------------------------------------------------------------------
|
|---|
| 60 | # ObjChildren.initObjChild
|
|---|
| 61 | # --------------------------------------------------------------------------
|
|---|
| 62 | def initObjChild(self, id, _sort_id, type, REQUEST):
|
|---|
| 63 |
|
|---|
| 64 | ##### ID ####
|
|---|
| 65 | metaObjAttr = self.getObjChildrenAttr(id)
|
|---|
| 66 | repetitive = metaObjAttr.get('repetitive',0)==1
|
|---|
| 67 | if repetitive:
|
|---|
| 68 | id += str(self.getSequence().nextVal())
|
|---|
| 69 |
|
|---|
| 70 | ##### Create ####
|
|---|
| 71 | oItem = getattr(self,id,None)
|
|---|
| 72 | if oItem is None or id not in self.objectIds():
|
|---|
| 73 | if self.dGlobalAttrs.has_key(type):
|
|---|
| 74 | obj = self.dGlobalAttrs[type]['obj_class'](id,_sort_id+1)
|
|---|
| 75 | else:
|
|---|
| 76 | obj = self.dGlobalAttrs['ZMSCustom']['obj_class'](id,_sort_id+1,type)
|
|---|
| 77 | self._setObject(obj.id, obj)
|
|---|
| 78 | oItem = getattr(self,id)
|
|---|
| 79 |
|
|---|
| 80 | ##### Object State ####
|
|---|
| 81 | oItem.setObjStateNew(REQUEST)
|
|---|
| 82 | ##### Init Properties ####
|
|---|
| 83 | oItem.setObjStateModified(REQUEST)
|
|---|
| 84 | for lang in self.getLangIds():
|
|---|
| 85 | oItem.setObjProperty('active',1,lang)
|
|---|
| 86 | ##### VersionManager ####
|
|---|
| 87 | oItem.onChangeObj(REQUEST)
|
|---|
| 88 |
|
|---|
| 89 | ##### Normalize Sort-IDs ####
|
|---|
| 90 | self.normalizeSortIds(_globals.id_prefix(id))
|
|---|
| 91 |
|
|---|
| 92 | return oItem
|
|---|
| 93 |
|
|---|
| 94 |
|
|---|
| 95 | # --------------------------------------------------------------------------
|
|---|
| 96 | # ObjChildren._initObjChildren
|
|---|
| 97 | # --------------------------------------------------------------------------
|
|---|
| 98 | def _initObjChildren(self, obj_attr, REQUEST):
|
|---|
| 99 | id = obj_attr['id']
|
|---|
| 100 | ids = []
|
|---|
| 101 | for ob in self.getChildNodes(REQUEST):
|
|---|
| 102 | if ob.id[:len(id)]==id:
|
|---|
| 103 | ids.append(ob.id)
|
|---|
| 104 | mandatory = obj_attr.get('mandatory',0)==1
|
|---|
| 105 | if mandatory:
|
|---|
| 106 | if len(ids) == 0:
|
|---|
| 107 | default = obj_attr.get('custom')
|
|---|
| 108 | if default:
|
|---|
| 109 | _fileutil.import_zexp(self,default,obj_attr['id'],obj_attr['id'])
|
|---|
| 110 | else:
|
|---|
| 111 | if obj_attr['type'] == '*' and type( obj_attr['keys']) is list and len( obj_attr['keys']) > 0:
|
|---|
| 112 | obj_attr['type'] = obj_attr['keys'][0]
|
|---|
| 113 | self.initObjChild(obj_attr['id'],0,obj_attr['type'],REQUEST)
|
|---|
| 114 | repetitive = obj_attr.get('repetitive',0)==1
|
|---|
| 115 | if repetitive:
|
|---|
| 116 | if id in ids:
|
|---|
| 117 | new_id = self.getNewId(id)
|
|---|
| 118 | _globals.writeLog( self, "[_initObjChildren]: Rename %s to %s"%(id,new_id))
|
|---|
| 119 | if new_id not in self.objectIds():
|
|---|
| 120 | self.manage_renameObject(id=id,new_id=new_id)
|
|---|
| 121 | else:
|
|---|
| 122 | if not id in ids and len(ids)>0:
|
|---|
| 123 | old_id = ids[0]
|
|---|
| 124 | _globals.writeLog( self, "[_initObjChildren]: Rename %s to %s"%(old_id,id))
|
|---|
| 125 | if id not in self.objectIds():
|
|---|
| 126 | self.manage_renameObject(id=old_id,new_id=id)
|
|---|
| 127 |
|
|---|
| 128 |
|
|---|
| 129 | # --------------------------------------------------------------------------
|
|---|
| 130 | # ObjChildren.initObjChildren
|
|---|
| 131 | # --------------------------------------------------------------------------
|
|---|
| 132 | def initObjChildren(self, REQUEST):
|
|---|
| 133 | _globals.writeLog( self, "[initObjChildren]")
|
|---|
| 134 | self.getObjProperty( 'initObjChildren' ,REQUEST)
|
|---|
| 135 | metaObj = self.getMetaobj(self.meta_id)
|
|---|
| 136 | metaObjIds = self.getMetaobjIds(sort=0)+['*']
|
|---|
| 137 | for metaObjAttrId in self.getMetaobjAttrIds( self.meta_id):
|
|---|
| 138 | metaObjAttr = self.getMetaobjAttr( self.meta_id, metaObjAttrId)
|
|---|
| 139 | if metaObjAttr['type'] in metaObjIds:
|
|---|
| 140 | self._initObjChildren( metaObjAttr, REQUEST)
|
|---|
| 141 |
|
|---|
| 142 |
|
|---|
| 143 | # --------------------------------------------------------------------------
|
|---|
| 144 | # ObjChildren.getObjChildrenAttr:
|
|---|
| 145 | # --------------------------------------------------------------------------
|
|---|
| 146 | def getObjChildrenAttr(self, key, meta_type=None):
|
|---|
| 147 | meta_type = _globals.nvl(meta_type,self.meta_id)
|
|---|
| 148 | ##### Meta-Objects ####
|
|---|
| 149 | if meta_type in self.getMetaobjIds(sort=0) and key in self.getMetaobjAttrIds(meta_type):
|
|---|
| 150 | obj_attr = self.getMetaobjAttr(meta_type,key)
|
|---|
| 151 | ##### Default ####
|
|---|
| 152 | else:
|
|---|
| 153 | obj_attr = {'id':key,'repetitive':1,'mandatory':0}
|
|---|
| 154 | return obj_attr
|
|---|
| 155 |
|
|---|
| 156 |
|
|---|
| 157 | # --------------------------------------------------------------------------
|
|---|
| 158 | # ObjChildren.getObjChildren
|
|---|
| 159 | # --------------------------------------------------------------------------
|
|---|
| 160 | def getObjChildren(self, id, REQUEST, meta_types=None):
|
|---|
| 161 | """
|
|---|
| 162 | Returns a NodeList that contains all children of this node in
|
|---|
| 163 | correct order. If none, this is a empty NodeList.
|
|---|
| 164 | """
|
|---|
| 165 | objAttr = self.getObjChildrenAttr(id)
|
|---|
| 166 | reid = None
|
|---|
| 167 | if id:
|
|---|
| 168 | if objAttr.get('repetitive'):
|
|---|
| 169 | reid = id+'$'+'|'+id+'\\d+'
|
|---|
| 170 | else:
|
|---|
| 171 | reid = id
|
|---|
| 172 | return self.getChildNodes(REQUEST,meta_types,reid)
|
|---|
| 173 |
|
|---|
| 174 |
|
|---|
| 175 | # --------------------------------------------------------------------------
|
|---|
| 176 | # ObjChildren.getObjChildren
|
|---|
| 177 | # --------------------------------------------------------------------------
|
|---|
| 178 | def filteredObjChildren(self, id, REQUEST, meta_types=None):
|
|---|
| 179 | """
|
|---|
| 180 | Returns a NodeList that contains all visible children of this node in
|
|---|
| 181 | correct order. If none, this is a empty NodeList.
|
|---|
| 182 | """
|
|---|
| 183 | return filter(lambda ob: ob.isVisible(REQUEST),self.getObjChildren(id,REQUEST,meta_types))
|
|---|
| 184 |
|
|---|
| 185 |
|
|---|
| 186 | ############################################################################
|
|---|
| 187 | # ObjChildren.manage_initObjChild:
|
|---|
| 188 | #
|
|---|
| 189 | # Create object-child.
|
|---|
| 190 | ############################################################################
|
|---|
| 191 | def manage_initObjChild(self, id, type, lang, REQUEST, RESPONSE=None):
|
|---|
| 192 | """ ObjChildren.manage_initObjChild """
|
|---|
| 193 |
|
|---|
| 194 | # Create.
|
|---|
| 195 | obj = self.initObjChild(id,self.getNewSortId(),type,REQUEST)
|
|---|
| 196 |
|
|---|
| 197 | # Return with message.
|
|---|
| 198 | if RESPONSE is not None:
|
|---|
| 199 | message = self.getZMILangStr('MSG_INSERTED')%obj.display_type(REQUEST)
|
|---|
| 200 | message = urllib.quote(message)
|
|---|
| 201 | target = REQUEST.get('manage_target','%s/manage_main'%obj.id)
|
|---|
| 202 | RESPONSE.redirect('%s?lang=%s&manage_tabs_message=%s'%(target,lang,message))
|
|---|
| 203 |
|
|---|
| 204 | ################################################################################
|
|---|