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