| 1 | ################################################################################
|
|---|
| 2 | # zms.py
|
|---|
| 3 | #
|
|---|
| 4 | # This program is free software; you can redistribute it and/or
|
|---|
| 5 | # modify it under the terms of the GNU General Public License
|
|---|
| 6 | # as published by the Free Software Foundation; either version 2
|
|---|
| 7 | # of the License, or (at your option) any later version.
|
|---|
| 8 | #
|
|---|
| 9 | # This program is distributed in the hope that it will be useful,
|
|---|
| 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|---|
| 12 | # GNU General Public License for more details.
|
|---|
| 13 | #
|
|---|
| 14 | # You should have received a copy of the GNU General Public License
|
|---|
| 15 | # along with this program; if not, write to the Free Software
|
|---|
| 16 | # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|---|
| 17 | ################################################################################
|
|---|
| 18 |
|
|---|
| 19 | # Imports.
|
|---|
| 20 | from App.Common import package_home
|
|---|
| 21 | from App.special_dtml import HTMLFile
|
|---|
| 22 | from OFS.Image import Image
|
|---|
| 23 | from sys import *
|
|---|
| 24 | import copy
|
|---|
| 25 | import os
|
|---|
| 26 | import shutil
|
|---|
| 27 | import sys
|
|---|
| 28 | import time
|
|---|
| 29 | import transaction
|
|---|
| 30 | import urllib
|
|---|
| 31 | import zExceptions
|
|---|
| 32 | # Product imports.
|
|---|
| 33 | import _accessmanager
|
|---|
| 34 | import _builder
|
|---|
| 35 | import _confmanager
|
|---|
| 36 | import _enummanager
|
|---|
| 37 | import _fileutil
|
|---|
| 38 | import _ftpmanager
|
|---|
| 39 | import _globals
|
|---|
| 40 | import _importable
|
|---|
| 41 | import _objattrs
|
|---|
| 42 | import _xmllib
|
|---|
| 43 | import _zcatalogmanager
|
|---|
| 44 | import _zmsattributecontainer
|
|---|
| 45 | import ZMSMetamodelProvider, ZMSFormatProvider, ZMSWorkflowProvider, ZMSWorkflowProviderAcquired
|
|---|
| 46 | from _versionmanager import getObjStates
|
|---|
| 47 | from zmscustom import ZMSCustom
|
|---|
| 48 | from zmslinkcontainer import ZMSLinkContainer
|
|---|
| 49 | from zmslinkelement import ZMSLinkElement
|
|---|
| 50 | from zmslog import ZMSLog
|
|---|
| 51 | from zmssqldb import ZMSSqlDb
|
|---|
| 52 | from zmstrashcan import ZMSTrashcan
|
|---|
| 53 |
|
|---|
| 54 | __all__= ['ZMS']
|
|---|
| 55 |
|
|---|
| 56 |
|
|---|
| 57 | ################################################################################
|
|---|
| 58 | ################################################################################
|
|---|
| 59 | ###
|
|---|
| 60 | ### Common Function(s)
|
|---|
| 61 | ###
|
|---|
| 62 | ################################################################################
|
|---|
| 63 | ################################################################################
|
|---|
| 64 |
|
|---|
| 65 | # ------------------------------------------------------------------------------
|
|---|
| 66 | # ZMS.recurse_cleanArtefacts:
|
|---|
| 67 | #
|
|---|
| 68 | # Clean artefacts.
|
|---|
| 69 | # ------------------------------------------------------------------------------
|
|---|
| 70 | def recurse_cleanArtefacts( self, level=0):
|
|---|
| 71 | from OFS.CopySupport import absattr
|
|---|
| 72 | # Recursion.
|
|---|
| 73 | last_id = None
|
|---|
| 74 | for ob in self.objectValues():
|
|---|
| 75 | if absattr(self.id) == absattr(ob.id):
|
|---|
| 76 | print (" "*level)+"recurse_cleanArtefacts", ob.absolute_url(), ob.meta_type
|
|---|
| 77 | raise zExceptions.InternalError('InfiniteRecursionError')
|
|---|
| 78 | else:
|
|---|
| 79 | try:
|
|---|
| 80 | recurse_cleanArtefacts( ob, level+1)
|
|---|
| 81 | except "InfiniteRecursionError":
|
|---|
| 82 | print (" "*level)+"recurse_cleanArtefacts: clean artefact ", ob.absolute_url(), ob.meta_type
|
|---|
| 83 | self._delObject(absattr(ob.id), suppress_events=True)
|
|---|
| 84 |
|
|---|
| 85 |
|
|---|
| 86 | # ------------------------------------------------------------------------------
|
|---|
| 87 | # ZMS.recurse_updateVersionBuild:
|
|---|
| 88 | #
|
|---|
| 89 | # Update version build.
|
|---|
| 90 | # ------------------------------------------------------------------------------
|
|---|
| 91 | def recurse_updateVersionBuild(docElmnt, self, REQUEST):
|
|---|
| 92 | message = ''
|
|---|
| 93 |
|
|---|
| 94 | ##### Build 131a: ZMS Teaser-Elements: Penetrance ####
|
|---|
| 95 | if getattr( docElmnt, 'build', '000') < '131':
|
|---|
| 96 | try:
|
|---|
| 97 | if self.getType() == 'ZMSTeaserElement':
|
|---|
| 98 | d = { '0': 'this', '1': 'sub_nav', '2': 'sub_all'}
|
|---|
| 99 | for ob_ver in self.getObjVersions():
|
|---|
| 100 | key = 'attr_penetrance'
|
|---|
| 101 | if hasattr( ob_ver, key):
|
|---|
| 102 | try:
|
|---|
| 103 | v = getattr( ob_ver, key)
|
|---|
| 104 | setattr( ob_ver, key, d.get( str( v), v))
|
|---|
| 105 | except:
|
|---|
| 106 | pass
|
|---|
| 107 | except:
|
|---|
| 108 | pass
|
|---|
| 109 |
|
|---|
| 110 | ##### Build 132a: Rename logo to zmi_logo ####
|
|---|
| 111 | if getattr( docElmnt, 'build', '000') < '132':
|
|---|
| 112 | try:
|
|---|
| 113 | self.zmi_logo = self.logo
|
|---|
| 114 | delattr( self, 'logo')
|
|---|
| 115 | except:
|
|---|
| 116 | pass
|
|---|
| 117 |
|
|---|
| 118 | ##### Build 133a: Create workflow-managers ####
|
|---|
| 119 | if getattr( docElmnt, 'build', '000') < '133':
|
|---|
| 120 | if self.meta_type == 'ZMS':
|
|---|
| 121 | autocommit = self.getConfProperty('ZMS.autocommit',1)
|
|---|
| 122 | nodes = self.getConfProperty('ZMS.workflow.nodes',['{$}'])
|
|---|
| 123 | acquired = self.getConfProperty('ZMS.workflow.acquire',0)
|
|---|
| 124 | activities = self.getConfProperty('ZMS.workflow.activities',[])
|
|---|
| 125 | transitions = self.getConfProperty('ZMS.workflow.transitions',[])
|
|---|
| 126 | if acquired or len(activities+transitions)>0:
|
|---|
| 127 | if acquired:
|
|---|
| 128 | manager = ZMSWorkflowProviderAcquired.ZMSWorkflowProviderAcquired(autocommit,nodes)
|
|---|
| 129 | else:
|
|---|
| 130 | manager = ZMSWorkflowProvider.ZMSWorkflowProvider(autocommit,nodes,activities,transitions)
|
|---|
| 131 | if manager.id in self.objectIds():
|
|---|
| 132 | self.manage_delObjects(manager.id)
|
|---|
| 133 | self._setObject( manager.id, manager)
|
|---|
| 134 | self.delConfProperty('ZMS.autocommit')
|
|---|
| 135 | self.delConfProperty('ZMS.workflow.nodes')
|
|---|
| 136 | self.delConfProperty('ZMS.workflow.acquire')
|
|---|
| 137 | self.delConfProperty('ZMS.workflow.activities')
|
|---|
| 138 | self.delConfProperty('ZMS.workflow.transitions')
|
|---|
| 139 |
|
|---|
| 140 | ##### Build 134c: Store object-state for modified sub-objects in version-container ####
|
|---|
| 141 | if getattr( docElmnt, 'build', '000') < '134':
|
|---|
| 142 | if not self.getAutocommit() and self.isVersionContainer():
|
|---|
| 143 | self.syncObjModifiedChildren( REQUEST)
|
|---|
| 144 |
|
|---|
| 145 | # Recursion.
|
|---|
| 146 | for ob in self.objectValues( self.dGlobalAttrs.keys()):
|
|---|
| 147 | recurse_updateVersionBuild(docElmnt, ob, REQUEST)
|
|---|
| 148 |
|
|---|
| 149 | ##### Build 130a: ZMS Standard-Objects ####
|
|---|
| 150 | if getattr( docElmnt, 'build', '000') < '130':
|
|---|
| 151 | if self.meta_type == 'ZMS':
|
|---|
| 152 | users = self.getConfProperty('ZMS.security.users',{})
|
|---|
| 153 | for user in users.keys():
|
|---|
| 154 | nodes = users[user].get('nodes',{})
|
|---|
| 155 | try:
|
|---|
| 156 | for node_ref in nodes.keys():
|
|---|
| 157 | node_ob = self.getLinkObj(node_ref)
|
|---|
| 158 | node_dict = nodes[node_ref]
|
|---|
| 159 | if node_ob:
|
|---|
| 160 | self.setLocalUser( user, node_ref, node_dict['roles'], node_dict['langs'])
|
|---|
| 161 | except:
|
|---|
| 162 | pass
|
|---|
| 163 |
|
|---|
| 164 | # Return with message.
|
|---|
| 165 | return message
|
|---|
| 166 |
|
|---|
| 167 |
|
|---|
| 168 | # ------------------------------------------------------------------------------
|
|---|
| 169 | # ZMS.recurse_updateVersionPatch:
|
|---|
| 170 | #
|
|---|
| 171 | # Update version patch.
|
|---|
| 172 | # ------------------------------------------------------------------------------
|
|---|
| 173 | def recurse_updateVersionPatch(docElmnt, self, REQUEST):
|
|---|
| 174 | message = ''
|
|---|
| 175 | _confmanager.updateConf(self,REQUEST)
|
|---|
| 176 | self.getSequence()
|
|---|
| 177 | self.synchronizeObjAttrs()
|
|---|
| 178 | self.initRoleDefs()
|
|---|
| 179 | return message
|
|---|
| 180 |
|
|---|
| 181 |
|
|---|
| 182 | # ------------------------------------------------------------------------------
|
|---|
| 183 | # initTheme:
|
|---|
| 184 | # ------------------------------------------------------------------------------
|
|---|
| 185 | def initTheme(self, theme, new_id, REQUEST):
|
|---|
| 186 |
|
|---|
| 187 | filename = _fileutil.extractFilename(theme)
|
|---|
| 188 | id = filename[:filename.rfind('.')]
|
|---|
| 189 |
|
|---|
| 190 | ### Store copy of ZEXP in INSTANCE_HOME/import-folder.
|
|---|
| 191 | filepath = INSTANCE_HOME + '/import/' + filename
|
|---|
| 192 | if theme.startswith('http://'):
|
|---|
| 193 | initutil = _globals.initutil()
|
|---|
| 194 | initutil.setConfProperty('HTTP.proxy',REQUEST.get('http_proxy',''))
|
|---|
| 195 | zexp = _globals.http_import( initutil, theme)
|
|---|
| 196 | _fileutil.exportObj( zexp, filepath)
|
|---|
| 197 | else:
|
|---|
| 198 | packagepath = package_home(globals()) + '/import/' + filename
|
|---|
| 199 | try:
|
|---|
| 200 | os.stat(_fileutil.getOSPath(filepath))
|
|---|
| 201 | except OSError:
|
|---|
| 202 | shutil.copy( packagepath, filepath)
|
|---|
| 203 |
|
|---|
| 204 | ### Import theme from ZEXP.
|
|---|
| 205 | _fileutil.importZexp( self, filename)
|
|---|
| 206 |
|
|---|
| 207 | ### Assign folder-id.
|
|---|
| 208 | if id != new_id:
|
|---|
| 209 | self.manage_renameObject( id=id, new_id=new_id)
|
|---|
| 210 |
|
|---|
| 211 | ### Return new ZMS home instance.
|
|---|
| 212 | return getattr( self, new_id)
|
|---|
| 213 |
|
|---|
| 214 |
|
|---|
| 215 | # ------------------------------------------------------------------------------
|
|---|
| 216 | # initZMS:
|
|---|
| 217 | # ------------------------------------------------------------------------------
|
|---|
| 218 | def initZMS(self, id, titlealt, title, lang, manage_lang, REQUEST):
|
|---|
| 219 |
|
|---|
| 220 | ### Constructor.
|
|---|
| 221 | obj = ZMS()
|
|---|
| 222 | obj.id = id
|
|---|
| 223 | self._setObject(obj.id, obj)
|
|---|
| 224 | obj = getattr(self,obj.id)
|
|---|
| 225 |
|
|---|
| 226 | ### Trashcan.
|
|---|
| 227 | trashcan = ZMSTrashcan()
|
|---|
| 228 | obj._setObject(trashcan.id, trashcan)
|
|---|
| 229 |
|
|---|
| 230 | ### Manager.
|
|---|
| 231 | manager = ZMSMetamodelProvider.ZMSMetamodelProvider()
|
|---|
| 232 | obj._setObject( manager.id, manager)
|
|---|
| 233 | manager = ZMSFormatProvider.ZMSFormatProvider()
|
|---|
| 234 | obj._setObject( manager.id, manager)
|
|---|
| 235 |
|
|---|
| 236 | ### Init languages.
|
|---|
| 237 | obj.setLanguage(lang,REQUEST['lang_label'],'',manage_lang)
|
|---|
| 238 |
|
|---|
| 239 | ### Log.
|
|---|
| 240 | if REQUEST.get('zmslog'):
|
|---|
| 241 | zmslog = ZMSLog( copy_to_stdout=True, logged_entries=[ 'ERROR', 'INFO'])
|
|---|
| 242 | obj._setObject(zmslog.id, zmslog)
|
|---|
| 243 |
|
|---|
| 244 | ### Init Configuration.
|
|---|
| 245 | obj.setConfProperty('HTTP.proxy',REQUEST.get('http_proxy',''))
|
|---|
| 246 | obj.setConfProperty('ZMS.autocommit',1)
|
|---|
| 247 | obj.setConfProperty('ZMS.Version.autopack',2)
|
|---|
| 248 |
|
|---|
| 249 | ### Init zcatalog.
|
|---|
| 250 | obj.recreateCatalog(lang)
|
|---|
| 251 |
|
|---|
| 252 | ### Init ZMS object-model.
|
|---|
| 253 | conf = 'zms'
|
|---|
| 254 | if REQUEST.get('initialization',0) == 3:
|
|---|
| 255 | conf = 'zms2go'
|
|---|
| 256 | _confmanager.initConf(obj, conf, REQUEST)
|
|---|
| 257 |
|
|---|
| 258 | ### Init default-configuration.
|
|---|
| 259 | _confmanager.initConf(obj, 'default', REQUEST)
|
|---|
| 260 |
|
|---|
| 261 | ### Init Role-Definitions and Permission Settings.
|
|---|
| 262 | obj.initRoleDefs()
|
|---|
| 263 |
|
|---|
| 264 | ### Init Properties: active, titlealt, title.
|
|---|
| 265 | obj.setObjStateNew(REQUEST)
|
|---|
| 266 | obj.updateVersion(lang,REQUEST)
|
|---|
| 267 | obj.setObjProperty('active',1,lang)
|
|---|
| 268 | obj.setObjProperty('titlealt',titlealt,lang)
|
|---|
| 269 | obj.setObjProperty('title',title,lang)
|
|---|
| 270 | obj.onChangeObj(REQUEST,forced=1)
|
|---|
| 271 |
|
|---|
| 272 | ### Return new ZMS instance.
|
|---|
| 273 | return obj
|
|---|
| 274 |
|
|---|
| 275 |
|
|---|
| 276 | # ------------------------------------------------------------------------------
|
|---|
| 277 | # initContent:
|
|---|
| 278 | # ------------------------------------------------------------------------------
|
|---|
| 279 | def initContent(self, filename, REQUEST):
|
|---|
| 280 | file = open(_fileutil.getOSPath(package_home(globals())+'/import/'+filename),'rb')
|
|---|
| 281 | _importable.importFile( self, file, REQUEST, _importable.importContent)
|
|---|
| 282 | file.close()
|
|---|
| 283 |
|
|---|
| 284 |
|
|---|
| 285 | ################################################################################
|
|---|
| 286 | ################################################################################
|
|---|
| 287 | ###
|
|---|
| 288 | ### Constructor
|
|---|
| 289 | ###
|
|---|
| 290 | ################################################################################
|
|---|
| 291 | ################################################################################
|
|---|
| 292 | manage_addZMSForm = HTMLFile('manage_addzmsform', globals())
|
|---|
| 293 | def manage_addZMS(self, lang, manage_lang, REQUEST, RESPONSE):
|
|---|
| 294 | """ manage_addZMS """
|
|---|
| 295 | message = ''
|
|---|
| 296 | t0 = time.time()
|
|---|
| 297 |
|
|---|
| 298 | if REQUEST['btn'] == 'Add':
|
|---|
| 299 |
|
|---|
| 300 | ##### Add Theme ####
|
|---|
| 301 | homeElmnt = initTheme(self,REQUEST['theme'],REQUEST['folder_id'],REQUEST)
|
|---|
| 302 | if REQUEST.get('mobile',0)==1:
|
|---|
| 303 | tempId = 'myZMSmobile'
|
|---|
| 304 | tempMobile = initTheme(homeElmnt,'myZMSmobile.zexp',tempId,REQUEST)
|
|---|
| 305 | cb_copy_data = tempMobile.manage_cutObjects(tempMobile.objectIds())
|
|---|
| 306 | homeElmnt.manage_pasteObjects(cb_copy_data=cb_copy_data)
|
|---|
| 307 | homeElmnt.manage_delObjects(ids=[tempId])
|
|---|
| 308 |
|
|---|
| 309 | ##### Add ZMS ####
|
|---|
| 310 | titlealt = 'ZMS home'
|
|---|
| 311 | title = 'ZMS - ZOPE-based contentmanagement system for science, technology and medicine'
|
|---|
| 312 | obj = initZMS(homeElmnt,'content',titlealt,title,lang,manage_lang,REQUEST)
|
|---|
| 313 |
|
|---|
| 314 | ##### Default content ####
|
|---|
| 315 | if REQUEST.get('initialization',0)==1:
|
|---|
| 316 | initContent(obj,'content.default.zip',REQUEST)
|
|---|
| 317 | elif REQUEST.get('initialization',0)==3:
|
|---|
| 318 | initContent(obj,'zms2go.default.zip',REQUEST)
|
|---|
| 319 |
|
|---|
| 320 | ##### E-Learning components ####
|
|---|
| 321 | if REQUEST.get('initialization',0)==2:
|
|---|
| 322 | # Create Home.
|
|---|
| 323 | lcmsHomeElmnt = initTheme(homeElmnt,'lcms.zexp','lcms',REQUEST)
|
|---|
| 324 | # Create LCMS.
|
|---|
| 325 | titlealt = 'LCMS'
|
|---|
| 326 | title = 'Learning Content Management System'
|
|---|
| 327 | lcms = initZMS(lcmsHomeElmnt,'content',titlealt,title,lang,manage_lang,REQUEST)
|
|---|
| 328 | lcms.setLanguage('eng', 'English', 'ger', 'eng')
|
|---|
| 329 | # Init configuration.
|
|---|
| 330 | _confmanager.initConf(lcms, 'lcms', REQUEST)
|
|---|
| 331 | _confmanager.initConf(obj, 'lms', REQUEST)
|
|---|
| 332 | # Register Portal/Client.
|
|---|
| 333 | lcms.setConfProperty('Portal.Master',homeElmnt.id)
|
|---|
| 334 | obj.setConfProperty('Portal.Clients',[lcmsHomeElmnt.id])
|
|---|
| 335 | # Init content.
|
|---|
| 336 | initContent(lcms,'lcms.default.xml',REQUEST)
|
|---|
| 337 | initContent(obj,'lms.default.zip',REQUEST)
|
|---|
| 338 |
|
|---|
| 339 | ##### Configuration ####
|
|---|
| 340 |
|
|---|
| 341 | #-- Example Database
|
|---|
| 342 | if REQUEST.get('specobj_galleria',0) == 1:
|
|---|
| 343 | # Init configuration.
|
|---|
| 344 | _confmanager.initConf(obj, 'com.zms.jquery.galleria', REQUEST)
|
|---|
| 345 | # Init content.
|
|---|
| 346 | initContent(obj,'com.zms.jquery.galleria.content.zip',REQUEST)
|
|---|
| 347 |
|
|---|
| 348 | #-- Example Database
|
|---|
| 349 | if REQUEST.get('specobj_exampledb',0) == 1:
|
|---|
| 350 | # Init configuration.
|
|---|
| 351 | _confmanager.initConf(obj, 'exampledb', REQUEST)
|
|---|
| 352 | # Init content.
|
|---|
| 353 | initContent(obj,'exampledb.content.xml',REQUEST)
|
|---|
| 354 |
|
|---|
| 355 | #-- Bulletin Board
|
|---|
| 356 | if REQUEST.get('specobj_discussions',0) == 1:
|
|---|
| 357 | # Init configuration.
|
|---|
| 358 | _confmanager.initConf(obj, 'discussions', REQUEST)
|
|---|
| 359 | # Init content.
|
|---|
| 360 | initContent(obj,'discussions.content.xml',REQUEST)
|
|---|
| 361 |
|
|---|
| 362 | #-- Newsletter
|
|---|
| 363 | if REQUEST.get('specobj_newsletter',0) == 1:
|
|---|
| 364 | # Init configuration.
|
|---|
| 365 | _confmanager.initConf(obj, 'newsletter', REQUEST)
|
|---|
| 366 |
|
|---|
| 367 | #-- Calendar
|
|---|
| 368 | if REQUEST.get('specobj_calendar',0) == 1:
|
|---|
| 369 | # Init configuration.
|
|---|
| 370 | _confmanager.initConf(obj, 'calendar', REQUEST)
|
|---|
| 371 |
|
|---|
| 372 | ##### Access ####
|
|---|
| 373 | obj.synchronizePublicAccess()
|
|---|
| 374 |
|
|---|
| 375 | # Return with message.
|
|---|
| 376 | message = obj.getLangStr('MSG_INSERTED',manage_lang)%obj.meta_type
|
|---|
| 377 | message += ' (in '+str(int((time.time()-t0)*100.0)/100.0)+' secs.)'
|
|---|
| 378 | RESPONSE.redirect('%s/%s/manage?manage_tabs_message=%s'%(homeElmnt.absolute_url(),obj.id,urllib.quote(message)))
|
|---|
| 379 |
|
|---|
| 380 | else:
|
|---|
| 381 | RESPONSE.redirect('%s/manage_main'%self.absolute_url())
|
|---|
| 382 |
|
|---|
| 383 |
|
|---|
| 384 | def containerFilter(container):
|
|---|
| 385 | return container.meta_type == 'Folder'
|
|---|
| 386 |
|
|---|
| 387 |
|
|---|
| 388 | ################################################################################
|
|---|
| 389 | ################################################################################
|
|---|
| 390 | ###
|
|---|
| 391 | ### Class
|
|---|
| 392 | ###
|
|---|
| 393 | ################################################################################
|
|---|
| 394 | ################################################################################
|
|---|
| 395 | class ZMS(
|
|---|
| 396 | ZMSCustom,
|
|---|
| 397 | _accessmanager.AccessManager,
|
|---|
| 398 | _builder.Builder,
|
|---|
| 399 | _confmanager.ConfManager,
|
|---|
| 400 | _ftpmanager.FtpManager,
|
|---|
| 401 | _objattrs.ObjAttrsManager,
|
|---|
| 402 | _zcatalogmanager.ZCatalogManager,
|
|---|
| 403 | ):
|
|---|
| 404 |
|
|---|
| 405 | # Version-Info.
|
|---|
| 406 | # -------------
|
|---|
| 407 | zms_build = '134' # Internal use only, designates object model!
|
|---|
| 408 | zms_patch = 'c' # Internal use only!
|
|---|
| 409 |
|
|---|
| 410 | # Properties.
|
|---|
| 411 | # -----------
|
|---|
| 412 | meta_type = meta_id = "ZMS"
|
|---|
| 413 |
|
|---|
| 414 | # Management Options.
|
|---|
| 415 | # -------------------
|
|---|
| 416 | def manage_options(self):
|
|---|
| 417 | pc = self.isPageContainer()
|
|---|
| 418 | root = self.getLevel() == 0
|
|---|
| 419 | opts = []
|
|---|
| 420 | opts.append({'label': 'TAB_EDIT', 'action': 'manage_main'})
|
|---|
| 421 | if pc:
|
|---|
| 422 | opts.append({'label': 'TAB_PROPERTIES', 'action': 'manage_properties'})
|
|---|
| 423 | opts.append({'label': 'TAB_ACCESS', 'action': 'manage_users'})
|
|---|
| 424 | opts.append({'label': 'TAB_IMPORTEXPORT', 'action': 'manage_importexport'})
|
|---|
| 425 | opts.append({'label': 'TAB_TASKS', 'action': 'manage_tasks'})
|
|---|
| 426 | opts.append({'label': 'TAB_REFERENCES', 'action': 'manage_RefForm'})
|
|---|
| 427 | opts.append({'label': 'TAB_HISTORY', 'action': 'manage_UndoVersionForm'})
|
|---|
| 428 | opts.append({'label': 'TAB_CONFIGURATION','action': 'manage_customize'})
|
|---|
| 429 | opts.append({'label': 'TAB_SEARCH', 'action': 'manage_search'})
|
|---|
| 430 | opts.append({'label': 'TAB_PREVIEW', 'action': 'preview_html'})
|
|---|
| 431 | return tuple(opts)
|
|---|
| 432 |
|
|---|
| 433 | # Management Permissions.
|
|---|
| 434 | # -----------------------
|
|---|
| 435 | __administratorPermissions__ = (
|
|---|
| 436 | 'manage_importexportFtp',
|
|---|
| 437 | 'manage_customize', 'manage_customizeSystem',
|
|---|
| 438 | 'manage_changeLanguages', 'manage_customizeLanguagesForm',
|
|---|
| 439 | 'manage_changeMetacmds', 'manage_customizeMetacmdForm',
|
|---|
| 440 | 'manage_customizeDesign', 'manage_customizeDesignForm',
|
|---|
| 441 | )
|
|---|
| 442 | __authorPermissions__ = (
|
|---|
| 443 | 'manage','manage_main','manage_main_iframe','manage_workspace',
|
|---|
| 444 | 'manage_addZMSModule',
|
|---|
| 445 | 'manage_deleteObjs','manage_undoObjs',
|
|---|
| 446 | 'manage_moveObjUp','manage_moveObjDown','manage_moveObjToPos',
|
|---|
| 447 | 'manage_cutObjects','manage_copyObjects','manage_pasteObjs',
|
|---|
| 448 | 'manage_ajaxDragDrop','manage_ajaxZMIActions',
|
|---|
| 449 | 'manage_properties','manage_changeProperties','manage_changeTempBlobjProperty',
|
|---|
| 450 | 'manage_search','manage_search_attrs','manage_tasks',
|
|---|
| 451 | 'manage_wfTransition', 'manage_wfTransitionFinalize',
|
|---|
| 452 | 'manage_userForm', 'manage_user',
|
|---|
| 453 | 'manage_importexport', 'manage_import', 'manage_export',
|
|---|
| 454 | )
|
|---|
| 455 | __userAdministratorPermissions__ = (
|
|---|
| 456 | 'manage_users', 'manage_userProperties', 'manage_roleProperties',
|
|---|
| 457 | )
|
|---|
| 458 | __ac_permissions__=(
|
|---|
| 459 | ('ZMS Administrator', __administratorPermissions__),
|
|---|
| 460 | ('ZMS Author', __authorPermissions__),
|
|---|
| 461 | ('ZMS UserAdministrator', __userAdministratorPermissions__),
|
|---|
| 462 | )
|
|---|
| 463 |
|
|---|
| 464 | # Globals.
|
|---|
| 465 | # --------
|
|---|
| 466 | dGlobalAttrs = {
|
|---|
| 467 | 'ZMS':{
|
|---|
| 468 | 'obj_class':None},
|
|---|
| 469 | 'ZMSCustom':{
|
|---|
| 470 | 'obj_class':ZMSCustom},
|
|---|
| 471 | 'ZMSLinkContainer':{
|
|---|
| 472 | 'obj_class':ZMSLinkContainer,
|
|---|
| 473 | 'constructor':'manage_addZMSLinkContainer'},
|
|---|
| 474 | 'ZMSLinkElement':{
|
|---|
| 475 | 'obj_class':ZMSLinkElement,
|
|---|
| 476 | 'constructor':'manage_addzmslinkelementform'},
|
|---|
| 477 | 'ZMSSqlDb':{
|
|---|
| 478 | 'obj_class':ZMSSqlDb,
|
|---|
| 479 | 'constructor':'manage_addzmssqldbform'},
|
|---|
| 480 | }
|
|---|
| 481 |
|
|---|
| 482 | # Interface.
|
|---|
| 483 | # ----------
|
|---|
| 484 | index_html = HTMLFile('dtml/ZMS/index', globals()) # index_html
|
|---|
| 485 | not_found_html = HTMLFile('dtml/ZMS/not_found', globals()) # index_html
|
|---|
| 486 | f_index_html = HTMLFile('dtml/ZMS/index', globals()) # index_html
|
|---|
| 487 | f_inactive_html = HTMLFile('dtml/ZMS/f_inactive', globals()) # inactive_html
|
|---|
| 488 | f_headDoctype = HTMLFile('dtml/ZMS/f_headdoctype', globals()) # Template: DOCTYPE
|
|---|
| 489 | f_bodyContent_Sitemap = HTMLFile('dtml/ZMS/f_bodycontent_sitemap', globals()) # Template: Sitemap
|
|---|
| 490 | f_bodyContent_Search = HTMLFile('dtml/ZMS/f_bodycontent_search', globals()) # Template: Search
|
|---|
| 491 | f_bodyContent_NotFound = HTMLFile('dtml/ZMS/f_bodycontent_notfound', globals()) # Template: Not Found
|
|---|
| 492 | f_headTitle = HTMLFile('dtml/ZMS/f_headtitle', globals()) # Head.Title
|
|---|
| 493 | f_headMeta_DC = HTMLFile('dtml/ZMS/f_headmeta_dc', globals()) # Head.Meta.DC
|
|---|
| 494 | f_headMeta_Locale = HTMLFile('dtml/ZMS/f_headmeta_locale', globals()) # Head.Locale (Content-Type & Charset)
|
|---|
| 495 | f_sitemap = HTMLFile('dtml/ZMS/f_sitemap', globals()) # f_sitemap
|
|---|
| 496 | f_standard_html_request = HTMLFile('dtml/ZMS/f_standard_html_request', globals()) # f_standard_html_request
|
|---|
| 497 | f_standard_html_header = HTMLFile('dtml/ZMS/f_standard_html_header', globals()) # f_standard_html_header
|
|---|
| 498 | f_standard_html_footer = HTMLFile('dtml/ZMS/f_standard_html_footer', globals()) # f_standard_html_footer
|
|---|
| 499 | headScript = HTMLFile('dtml/ZMS/headscript', globals()) # Head.Script
|
|---|
| 500 | headMeta = HTMLFile('dtml/ZMS/headmeta', globals()) # Head.Meta
|
|---|
| 501 | headCStyleSheet = HTMLFile('dtml/ZMS/headcstylesheet', globals()) # Template_L1: CSS-Reference
|
|---|
| 502 | headCSS = HTMLFile('dtml/ZMS/headcstylesheet', globals()) # Template_L1: CSS-Referenz
|
|---|
| 503 | search_nav_html = HTMLFile('dtml/ZMS/search_nav', globals()) # search_nav_html
|
|---|
| 504 | manage_editorForm = HTMLFile('dtml/ZMS/manage_editorform', globals()) # Editor (Frameset)
|
|---|
| 505 |
|
|---|
| 506 | # Enumerations.
|
|---|
| 507 | # -------------
|
|---|
| 508 | browse_enum = HTMLFile('dtml/ZMS/browse_enum', globals())
|
|---|
| 509 | enumManager = _enummanager.EnumManager()
|
|---|
| 510 |
|
|---|
| 511 |
|
|---|
| 512 | """
|
|---|
| 513 | ############################################################################
|
|---|
| 514 | ###
|
|---|
| 515 | ### Constructor
|
|---|
| 516 | ###
|
|---|
| 517 | ############################################################################
|
|---|
| 518 | """
|
|---|
| 519 |
|
|---|
| 520 | # --------------------------------------------------------------------------
|
|---|
| 521 | # ZMS.__init__:
|
|---|
| 522 | # --------------------------------------------------------------------------
|
|---|
| 523 | def __init__(self):
|
|---|
| 524 | """
|
|---|
| 525 | Constructor.
|
|---|
| 526 | """
|
|---|
| 527 | self.id = 'content'
|
|---|
| 528 | file = open(_fileutil.getOSPath(package_home(globals())+'/www/spacer.gif'),'rb')
|
|---|
| 529 | self.zmi_logo = Image(id='logo', title='', file=file.read())
|
|---|
| 530 | file.close()
|
|---|
| 531 |
|
|---|
| 532 |
|
|---|
| 533 | # --------------------------------------------------------------------------
|
|---|
| 534 | # ZMS.initZMS:
|
|---|
| 535 | # --------------------------------------------------------------------------
|
|---|
| 536 | def initZMS(self, container, id, titlealt, title, lang, manage_lang, REQUEST):
|
|---|
| 537 | return initZMS(container, id, titlealt, title, lang, manage_lang, REQUEST)
|
|---|
| 538 |
|
|---|
| 539 |
|
|---|
| 540 | # --------------------------------------------------------------------------
|
|---|
| 541 | # ZMS.zms_version:
|
|---|
| 542 | #
|
|---|
| 543 | # Get version.
|
|---|
| 544 | # --------------------------------------------------------------------------
|
|---|
| 545 | def zms_version(self):
|
|---|
| 546 | file = open(_fileutil.getOSPath(package_home(globals())+'/version.txt'),'r')
|
|---|
| 547 | rtn = file.read()
|
|---|
| 548 | file.close()
|
|---|
| 549 | return rtn
|
|---|
| 550 |
|
|---|
| 551 | # --------------------------------------------------------------------------
|
|---|
| 552 | # ZMS.getDocumentElement
|
|---|
| 553 | # --------------------------------------------------------------------------
|
|---|
| 554 | def getDocumentElement(self):
|
|---|
| 555 | """
|
|---|
| 556 | The root element of the site.
|
|---|
| 557 | """
|
|---|
| 558 | return self
|
|---|
| 559 |
|
|---|
| 560 | # --------------------------------------------------------------------------
|
|---|
| 561 | # ZMS.getAbsoluteHome
|
|---|
| 562 | # --------------------------------------------------------------------------
|
|---|
| 563 | def getAbsoluteHome(self):
|
|---|
| 564 | portalMaster = self.getPortalMaster()
|
|---|
| 565 | if portalMaster:
|
|---|
| 566 | return portalMaster.getAbsoluteHome()
|
|---|
| 567 | return self.getHome()
|
|---|
| 568 |
|
|---|
| 569 | # --------------------------------------------------------------------------
|
|---|
| 570 | # ZMS.getHome
|
|---|
| 571 | # --------------------------------------------------------------------------
|
|---|
| 572 | def getHome(self):
|
|---|
| 573 | """
|
|---|
| 574 | Returns the home-folder of the site.
|
|---|
| 575 | """
|
|---|
| 576 | docElmnt = self.getDocumentElement()
|
|---|
| 577 | ob = docElmnt
|
|---|
| 578 | try:
|
|---|
| 579 | depth = 0
|
|---|
| 580 | while ob.meta_type != 'Folder':
|
|---|
| 581 | if depth > sys.getrecursionlimit():
|
|---|
| 582 | raise zExceptions.InternalError('Maximum recursion depth exceeded')
|
|---|
| 583 | depth = depth + 1
|
|---|
| 584 | ob = ob.aq_parent
|
|---|
| 585 | except:
|
|---|
| 586 | try:
|
|---|
| 587 | ob = getattr( docElmnt, docElmnt.absolute_url().split( '/')[-2])
|
|---|
| 588 | except:
|
|---|
| 589 | ob = docElmnt.aq_parent
|
|---|
| 590 | return ob
|
|---|
| 591 |
|
|---|
| 592 | # --------------------------------------------------------------------------
|
|---|
| 593 | # ZMS.getTrashcan
|
|---|
| 594 | # --------------------------------------------------------------------------
|
|---|
| 595 | def getTrashcan(self):
|
|---|
| 596 | return self.objectValues(['ZMSTrashcan'])[0]
|
|---|
| 597 |
|
|---|
| 598 | # --------------------------------------------------------------------------
|
|---|
| 599 | # ZMS.getNewId
|
|---|
| 600 | # --------------------------------------------------------------------------
|
|---|
| 601 | def getNewId(self, id_prefix='e'):
|
|---|
| 602 | """
|
|---|
| 603 | Returns new (unique) Object-ID.
|
|---|
| 604 | """
|
|---|
| 605 | return '%s%i'%(id_prefix,self.getSequence().nextVal())
|
|---|
| 606 |
|
|---|
| 607 | # --------------------------------------------------------------------------
|
|---|
| 608 | # ZMS.getDCCoverage
|
|---|
| 609 | # --------------------------------------------------------------------------
|
|---|
| 610 | def getDCCoverage(self, REQUEST={}):
|
|---|
| 611 | """
|
|---|
| 612 | Returns Dublin-Core Meta-Attribute Coverage.
|
|---|
| 613 | """
|
|---|
| 614 | return 'global.'+self.getPrimaryLanguage()
|
|---|
| 615 |
|
|---|
| 616 | # --------------------------------------------------------------------------
|
|---|
| 617 | # ZMS.sendMail
|
|---|
| 618 | # --------------------------------------------------------------------------
|
|---|
| 619 | def sendMail(self, mto, msubject, mbody, REQUEST):
|
|---|
| 620 | """
|
|---|
| 621 | Sends Mail via MailHost.
|
|---|
| 622 | """
|
|---|
| 623 |
|
|---|
| 624 | ##### Get Sender ####
|
|---|
| 625 | auth_user = REQUEST['AUTHENTICATED_USER']
|
|---|
| 626 | mfrom = self.getUserAttr(auth_user,'email',self.getConfProperty('ZMSAdministrator.email',''))
|
|---|
| 627 |
|
|---|
| 628 | ##### Get MailHost ####
|
|---|
| 629 | mailhost = None
|
|---|
| 630 | homeElmnt = self.getHome()
|
|---|
| 631 | if len(homeElmnt.objectValues(['Mail Host'])) == 1:
|
|---|
| 632 | mailhost = homeElmnt.objectValues(['Mail Host'])[0]
|
|---|
| 633 | elif getattr(homeElmnt,'MailHost',None) is not None:
|
|---|
| 634 | mailhost = getattr(homeElmnt,'MailHost',None)
|
|---|
| 635 |
|
|---|
| 636 | ##### Get MessageText ####
|
|---|
| 637 | messageText = ''
|
|---|
| 638 | messageText += 'Content-Type: text/plain; charset=unicode-1-1-utf-8\n'
|
|---|
| 639 | if type(mto) is dict and mto.has_key( 'From'):
|
|---|
| 640 | messageText += 'From: %s\n'%mto['From']
|
|---|
| 641 | else:
|
|---|
| 642 | messageText += 'From: %s\n'%mfrom
|
|---|
| 643 | if type(mto) is dict:
|
|---|
| 644 | for key in ['To','Cc','Bcc']:
|
|---|
| 645 | if mto.has_key( key):
|
|---|
| 646 | messageText += '%s: %s\n'%(key,mto[key])
|
|---|
| 647 | else:
|
|---|
| 648 | messageText += 'To: %s\n'%mto
|
|---|
| 649 | messageText += 'Subject: %s\n\n'%msubject
|
|---|
| 650 | messageText += '%s\n'%mbody
|
|---|
| 651 |
|
|---|
| 652 | ##### Send mail ####
|
|---|
| 653 | try:
|
|---|
| 654 | _globals.writeBlock( self, "[sendMail]: %s"%messageText)
|
|---|
| 655 | mailhost.send(messageText)
|
|---|
| 656 | return 0
|
|---|
| 657 | except:
|
|---|
| 658 | return -1
|
|---|
| 659 |
|
|---|
| 660 |
|
|---|
| 661 | ############################################################################
|
|---|
| 662 | #
|
|---|
| 663 | # ZMS - Portals
|
|---|
| 664 | #
|
|---|
| 665 | ############################################################################
|
|---|
| 666 |
|
|---|
| 667 | # --------------------------------------------------------------------------
|
|---|
| 668 | # ZMS.getPortalMaster
|
|---|
| 669 | # --------------------------------------------------------------------------
|
|---|
| 670 | def getPortalMaster(self):
|
|---|
| 671 | """
|
|---|
| 672 | Returns portal-master, none if it does not exist.
|
|---|
| 673 | """
|
|---|
| 674 | v = self.getConfProperty('Portal.Master','')
|
|---|
| 675 | if len(v) > 0:
|
|---|
| 676 | try:
|
|---|
| 677 | return getattr( self, v).content
|
|---|
| 678 | except:
|
|---|
| 679 | _globals.writeError(self, '[getPortalMaster]: %s not found!'%str(v))
|
|---|
| 680 | return None
|
|---|
| 681 |
|
|---|
| 682 | # --------------------------------------------------------------------------
|
|---|
| 683 | # ZMS.getPortalClients
|
|---|
| 684 | # --------------------------------------------------------------------------
|
|---|
| 685 | def getPortalClients(self):
|
|---|
| 686 | """
|
|---|
| 687 | Returns portal-clients, empty list if none exist.
|
|---|
| 688 | """
|
|---|
| 689 | docElmnts = []
|
|---|
| 690 | v = self.getConfProperty('Portal.Clients',[])
|
|---|
| 691 | if len(v) > 0:
|
|---|
| 692 | thisHome = self.getHome()
|
|---|
| 693 | for id in v:
|
|---|
| 694 | try:
|
|---|
| 695 | docElmnts.append(getattr(thisHome,id).content)
|
|---|
| 696 | except:
|
|---|
| 697 | _globals.writeError(self, '[getPortalClients]: %s not found!'%str(id))
|
|---|
| 698 | return docElmnts
|
|---|
| 699 |
|
|---|
| 700 |
|
|---|
| 701 | ############################################################################
|
|---|
| 702 | #
|
|---|
| 703 | # ZMS - Versions
|
|---|
| 704 | #
|
|---|
| 705 | ############################################################################
|
|---|
| 706 |
|
|---|
| 707 | # --------------------------------------------------------------------------
|
|---|
| 708 | # ZMS.updateVersion:
|
|---|
| 709 | #
|
|---|
| 710 | # Update version.
|
|---|
| 711 | # --------------------------------------------------------------------------
|
|---|
| 712 | def updateVersion(self, lang, REQUEST, maintenance=True):
|
|---|
| 713 | message = ''
|
|---|
| 714 | build = getattr( self, 'build', '000')
|
|---|
| 715 | patch = getattr( self, 'patch', '000')
|
|---|
| 716 | if build != self.zms_build:
|
|---|
| 717 | REQUEST.set('recurse_updateVersionBuild',True)
|
|---|
| 718 | _globals.writeBlock(self,'[ZMS.updateVersion]: Synchronize object-model from build #%s%s to #%s%s...'%(build,patch,self.zms_build,self.zms_patch))
|
|---|
| 719 | message += recurse_updateVersionBuild( self, self, REQUEST)
|
|---|
| 720 | _globals.writeBlock(self,'[ZMS.updateVersion]: Synchronize object-model from build #%s%s to #%s%s - Finished!'%(build,patch,self.zms_build,self.zms_patch))
|
|---|
| 721 | setattr( self, 'build', self.zms_build)
|
|---|
| 722 | transaction.commit()
|
|---|
| 723 | message += 'Synchronized object-model from build #%s%s to #%s%s!<br/>'%(build,patch,self.zms_build,self.zms_patch)
|
|---|
| 724 | if build != self.zms_build or patch != self.zms_patch:
|
|---|
| 725 | REQUEST.set('recurse_updateVersionPatch',True)
|
|---|
| 726 | _globals.writeBlock(self,'[ZMS.updateVersion]: Synchronize object-model from patch #%s%s to #%s%s...'%(build,patch,self.zms_build,self.zms_patch))
|
|---|
| 727 | message += recurse_updateVersionPatch( self, self, REQUEST)
|
|---|
| 728 | _globals.writeBlock(self,'[ZMS.updateVersion]: Synchronize object-model from patch #%s%s to #%s%s - Finished!'%(build,patch,self.zms_build,self.zms_patch))
|
|---|
| 729 | setattr( self, 'patch', self.zms_patch)
|
|---|
| 730 | transaction.commit()
|
|---|
| 731 | message += 'Synchronized object-model from patch #%s%s to #%s%s!<br/>'%(build,patch,self.zms_build,self.zms_patch)
|
|---|
| 732 | if maintenance:
|
|---|
| 733 | try:
|
|---|
| 734 | self.getTrashcan().run_garbage_collection()
|
|---|
| 735 | except:
|
|---|
| 736 | _globals.writeError( self, '[updateVersion]: can\'t run garbage collection')
|
|---|
| 737 |
|
|---|
| 738 | # Process clients.
|
|---|
| 739 | if message:
|
|---|
| 740 | for portalClient in self.getPortalClients():
|
|---|
| 741 | message += portalClient.updateVersion( lang, REQUEST, False)
|
|---|
| 742 |
|
|---|
| 743 | return message
|
|---|
| 744 |
|
|---|
| 745 |
|
|---|
| 746 | ############################################################################
|
|---|
| 747 | ###
|
|---|
| 748 | ### DOM-Methods
|
|---|
| 749 | ###
|
|---|
| 750 | ############################################################################
|
|---|
| 751 |
|
|---|
| 752 | # --------------------------------------------------------------------------
|
|---|
| 753 | # ZMS.getParentNode
|
|---|
| 754 | # --------------------------------------------------------------------------
|
|---|
| 755 | getParentNode__roles__ = None
|
|---|
| 756 | def getParentNode(self):
|
|---|
| 757 | """
|
|---|
| 758 | The parent of this node.
|
|---|
| 759 | All nodes except root may have a parent.
|
|---|
| 760 | """
|
|---|
| 761 | return None
|
|---|
| 762 |
|
|---|
| 763 |
|
|---|
| 764 | ############################################################################
|
|---|
| 765 | ###
|
|---|
| 766 | ### XML-Builder
|
|---|
| 767 | ###
|
|---|
| 768 | ############################################################################
|
|---|
| 769 |
|
|---|
| 770 | # --------------------------------------------------------------------------
|
|---|
| 771 | # ZMS.xmlOnStartElement
|
|---|
| 772 | # --------------------------------------------------------------------------
|
|---|
| 773 | def xmlOnStartElement(self, sTagName, dTagAttrs, oParentNode, oRoot):
|
|---|
| 774 | """
|
|---|
| 775 | Handler for XML-Builder (_builder.py)
|
|---|
| 776 | """
|
|---|
| 777 | _globals.writeLog( self, "[xmlOnStartElement]: sTagName=%s"%sTagName)
|
|---|
| 778 |
|
|---|
| 779 | # remove all ZMS-objects.
|
|---|
| 780 | self.manage_delObjects(self.objectIds(self.dGlobalAttrs.keys()))
|
|---|
| 781 | # remove all languages.
|
|---|
| 782 | for s_lang in self.getLangIds():
|
|---|
| 783 | self.delLanguage(s_lang)
|
|---|
| 784 |
|
|---|
| 785 | self.dTagStack = _globals.MyStack()
|
|---|
| 786 | self.dValueStack = _globals.MyStack()
|
|---|
| 787 |
|
|---|
| 788 | # WORKAROUND! The member variable "aq_parent" does not contain the right
|
|---|
| 789 | # parent object at this stage of the creation process (it will later on!).
|
|---|
| 790 | # Therefore, we introduce a special attribute containing the parent
|
|---|
| 791 | # object, which will be used by xmlGetParent() (see below).
|
|---|
| 792 | self.oParent = None
|
|---|
| 793 |
|
|---|
| 794 | ################################################################################ |
|---|