-
Notifications
You must be signed in to change notification settings - Fork 0
/
zmsobject.py
1456 lines (1284 loc) · 60.1 KB
/
zmsobject.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
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
################################################################################
# zmsobject.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 AccessControl import ClassSecurityInfo
from App.special_dtml import HTMLFile
from Products.PageTemplates.PageTemplateFile import PageTemplateFile
from types import StringTypes
import Globals
import ZPublisher.HTTPRequest
import urllib
import string
import time
# Product Imports.
import zmscontainerobject
import ZMSItem
import ZMSGlobals
import ZMSWorkflowItem
import _accessmanager
import _blobfields
import _cachemanager
import _confmanager
import _copysupport
import _deprecatedapi
import _exportable
import _globals
import _metacmdmanager
import _multilangmanager
import _objattrs
import _objchildren
import _objinputs
import _objtypes
import _pathhandler
import _versionmanager
import _xmllib
import _textformatmanager
import _zcatalogmanager
import _zmsattributecontainer
import _zreferableitem
__all__= ['ZMSObject']
################################################################################
################################################################################
###
### Abstract Class ZMSObject
###
################################################################################
################################################################################
class ZMSObject(ZMSItem.ZMSItem,
_accessmanager.AccessableObject, # Access manager.
_versionmanager.VersionItem, # Version Item.
ZMSWorkflowItem.ZMSWorkflowItem,
_copysupport.CopySupport, # Copy Support (Paste Objects).
_cachemanager.ReqBuff, # Request Buffer (Cache).
_deprecatedapi.DeprecatedAPI, # Deprecated API.
_metacmdmanager.MetacmdObject, # Meta-Commands.
_multilangmanager.MultiLanguageObject, # Multi-Language.
_exportable.Exportable, # XML Export.
_objattrs.ObjAttrs, # Object-Attributes.
_objchildren.ObjChildren, # Object-Children.
_objinputs.ObjInputs, # Object-Inputs.
_objtypes.ObjTypes, # Object-Types.
_pathhandler.PathHandler, # Path-Handler.
_textformatmanager.TextFormatObject, # Text-Formats.
_zcatalogmanager.ZCatalogItem, # ZCatalog Item.
ZMSGlobals.ZMSGlobals, # ZMS Global Functions and Definitions.
_zreferableitem.ZReferableItem # ZReferable Item.
):
# Documentation string.
__doc__ = """ZMS product module."""
# Version string.
__version__ = '0.1'
# Create a SecurityInfo for this class. We will use this
# in the rest of our class definition to make security
# assertions.
security = ClassSecurityInfo()
# Properties.
# -----------
QUOT = chr(34)
MISC_ZMS = '/misc_/zms/'
FORM_LABEL_MANDATORY = '<sup style="color:red">*</sup>'
spacer_gif = '/misc_/zms/spacer.gif'
# ZPT Templates.
# --------------
zmi_breadcrumbs = PageTemplateFile('zpt/common/zmi_breadcrumbs', globals())
zmi_manage_tabs_message = PageTemplateFile('zpt/common/zmi_manage_tabs_message', globals())
zmi_body_footer = PageTemplateFile('zpt/common/zmi_body_footer', globals())
zmi_body_header = PageTemplateFile('zpt/common/zmi_body_header', globals())
zmi_html_head = PageTemplateFile('zpt/common/zmi_html_head', globals())
zmi_pagination = PageTemplateFile('zpt/common/zmi_pagination', globals())
zmi_tabs = PageTemplateFile('zpt/common/zmi_tabs', globals())
zmi_tabs_sub = PageTemplateFile('zpt/common/zmi_tabs_sub', globals())
zmi_ace_editor = PageTemplateFile('zpt/common/zmi_ace_editor',globals())
# Templates.
# ----------
f_display_icon = _confmanager.ConfDict.template('object/f_display_icon') # ZMI Display-Icon
f_recordset_grid = _confmanager.ConfDict.template('object/f_recordset_grid') # ZMI RecordSet::Grid
f_recordset_init = HTMLFile('dtml/object/f_recordset_init', globals()) # ZMI RecordSet::Init
f_recordset_nav = HTMLFile('dtml/object/f_recordset_nav', globals()) # ZMI RecordSet::Navigation
f_headline = HTMLFile('dtml/object/f_headline', globals()) # ZMI Headline
f_breadcrumbs = HTMLFile('dtml/object/f_breadcrumbs', globals()) # ZMI Breadcrumbs
f_css_defaults = HTMLFile('dtml/object/f_css_defaults', globals()) # CSS: Default StyleSheet (WAI)
f_submitInputFields = HTMLFile('dtml/object/f_submitinputfields', globals())
f_submitBtn = HTMLFile('dtml/object/f_submitbtn', globals())
zmi_form_section_begin = HTMLFile('dtml/object/zmi_form_section_begin', globals())
zmi_form_section_end = HTMLFile('dtml/object/zmi_form_section_end', globals())
f_collectionBtn = HTMLFile('dtml/object/f_collectionbtn', globals())
f_languages = HTMLFile('dtml/object/f_languages', globals())
f_frame = HTMLFile('dtml/object/f_frame', globals())
f_frame_top = HTMLFile('dtml/object/f_frame_top', globals())
f_frame_bottom = HTMLFile('dtml/object/f_frame_bottom', globals())
f_xstandard_browseImages = HTMLFile('dtml/object/f_xstandard_browseimages', globals())
f_xstandard_browseFiles = HTMLFile('dtml/object/f_xstandard_browsefiles', globals())
preview_html = _confmanager.ConfDict.template('object/preview')
preview_top_html = _confmanager.ConfDict.template('object/preview_top')
f_api_html = _confmanager.ConfDict.template('object/f_api')
f_api_top_html = _confmanager.ConfDict.template('object/f_api_top')
obj_input_js = HTMLFile('dtml/ZMSObject/input_js', globals())
obj_input_fields = _confmanager.ConfDict.template('ZMSObject/input_fields')
obj_input_elements = _confmanager.ConfDict.template('ZMSObject/input_elements')
# Deprecated
f_css_printhtml = ''
active_input_fields = ''
version_input_fields = ''
############################################################################
# ZMSObject.__init__:
#
# Constructor (initialise a new instance of ZMSObject).
############################################################################
def __init__(self, id='', sort_id=0):
""" ZMSObject.__init__ """
self.id = id
self.sort_id = _globals.format_sort_id(sort_id)
self.ref_by = []
# --------------------------------------------------------------------------
# ZMSObject.title:
# --------------------------------------------------------------------------
def title(self, REQUEST={}):
try:
return self.getObjProperty('title', REQUEST)
except:
return 'ZMS'
# --------------------------------------------------------------------------
# ZMSObject.__proxy__:
# --------------------------------------------------------------------------
def __proxy__(self):
return self
# --------------------------------------------------------------------------
# ZMSObject.get_conf_blob:
# --------------------------------------------------------------------------
security.declarePublic('get_conf_blob')
def get_conf_blob(self, path, REQUEST, RESPONSE):
""" ZMS.get_conf_blob """
v = self.getConfProperties()
try:
for id in path.split('/'):
if type(v) is dict:
v = v[id]
elif type(v) is list:
if id.find( ':int') > 0:
v = v[ int( id[:id.find( ':int')])]
elif id in v:
v = v[ v.index(id)+1]
else:
l = filter(lambda x: x.get('id',None)==id, v)
if len( l) > 0:
v = l[ 0]
RESPONSE.setHeader( 'Cache-Control', 'public, max-age=3600')
RESPONSE.setHeader( 'Content-Type', v.getContentType())
RESPONSE.setHeader( 'Content-Disposition', 'inline;filename="%s"'%v.getFilename())
v = v.getData()
except:
masterId = self.getConfProperty('Portal.Master','')
if len(masterId) > 0:
masterHome = getattr(self.getHome(),masterId)
masterDocElmnt = masterHome.content
v = masterDocElmnt.get_conf_blob(path, REQUEST, RESPONSE)
else:
_globals.writeError(self,"[get_conf_blob]: path=%s"%str(path))
return v
# --------------------------------------------------------------------------
# ZMSObject.isMetaType:
# --------------------------------------------------------------------------
def isMetaType(self, meta_type, REQUEST={}):
if meta_type is None:
return True
if type(meta_type) is not list:
meta_type = [meta_type]
b = self.meta_type in meta_type or self.meta_id in meta_type
if not b and self.PAGES in meta_type:
b = b or self.isPage()
elif not b and self.PAGEELEMENTS in meta_type:
b = b or self.isPageElement()
return b
# --------------------------------------------------------------------------
# ZMSObject.isPageContainer:
# --------------------------------------------------------------------------
def isPageContainer(self):
metaobj_manager = getattr(self,'metaobj_manager',None)
if metaobj_manager is not None:
return metaobj_manager.__is_page_container__( self.meta_id)
return False
# --------------------------------------------------------------------------
# ZMSObject.isPage:
# --------------------------------------------------------------------------
def isPage(self):
return self.getType() in [ 'ZMSDocument', 'ZMSReference'] \
and not self.meta_id in [ 'ZMSNote', 'ZMSTeaserContainer']
# --------------------------------------------------------------------------
# ZMSObject.isPageElement:
# --------------------------------------------------------------------------
def isPageElement(self):
return self.getType() in [ 'ZMSObject', 'ZMSRecordSet'] \
and not self.meta_id in [ 'ZMSNote', 'ZMSTeaserContainer']
# --------------------------------------------------------------------------
# ZMSObject.getTitle
# --------------------------------------------------------------------------
def getTitle( self, REQUEST):
s = self.getObjProperty('title',REQUEST)
if len(s) == 0:
if self.isPage():
metaObjAttrs = self.getMetaobj( self.meta_id).get( 'attrs', [])
offs = 1
c = 0
for metaObjAttr in metaObjAttrs:
if metaObjAttr[ 'type'] in [ 'constant', 'method', 'py', 'string', 'select']:
if c == offs:
v = self.getObjProperty( metaObjAttr[ 'id'], REQUEST)
if type(v) in StringTypes:
s = v
break
c = c + 1
if len(s) == 0:
s = self.display_type(REQUEST)
if self.isPage():
sec_no = self.getSecNo()
if len(sec_no) > 0:
s = sec_no + ' ' + s
return s
# --------------------------------------------------------------------------
# ZMSObject.getTitlealt
# --------------------------------------------------------------------------
def getTitlealt( self, REQUEST):
s = self.getObjProperty('titlealt',REQUEST)
if len(s) == 0:
s = self.display_type(REQUEST)
if len(s) == 0:
if self.isPage():
metaObjAttrs = self.getMetaobj( self.meta_id).get( 'attrs', [])
offs = 0
c = 0
for metaObjAttr in metaObjAttrs:
if metaObjAttr[ 'type'] in [ 'constant', 'method', 'py', 'string', 'select']:
if c == offs:
v = self.getObjProperty( metaObjAttr[ 'id'], REQUEST)
if type(v) in StringTypes:
s = v
break
c = c + 1
if self.isPage():
sec_no = self.getSecNo()
if len(sec_no) > 0:
s = sec_no + ' ' + s
return s
# --------------------------------------------------------------------------
# ZMSObject.getType
#
# Returns type of object. Valid types are:
# <li>ZMSDocument: Page</li>
# <li>ZMSObject: Page-Element</li>
# <li>ZMSTeaserElement: Teaser-Element</li>
# <li>ZMSRecordSet</li>
# <li>ZMSResource</li>
# <li>ZMSReference</li>
# <li>ZMSLibrary</li>
# <li>ZMSPackage</li>
# <li>ZMSModule</li>
# --------------------------------------------------------------------------
def getType(self):
metaObj = self.getMetaobj(self.meta_id)
return metaObj.get('type','ZMSDocument')
# --------------------------------------------------------------------------
# ZMSObject.isResource
# --------------------------------------------------------------------------
def isResource(self, REQUEST):
return self.getObjProperty('attr_dc_type',REQUEST) == 'Resource' or \
self.id in REQUEST.get( 'ZMS_IDS_RESOURCE', [])
# --------------------------------------------------------------------------
# ZMSObject.isTranslated
#
# Returns True if current object is translated to given language.
# --------------------------------------------------------------------------
def isTranslated(self, lang, REQUEST):
REQUEST = _globals.nvl(REQUEST,self.REQUEST)
rtnVal = False
req = {'lang':lang,'preview':REQUEST.get('preview','')}
value = self.getObjProperty('change_uid',req)
rtnVal = value is not None and len(value) > 0
return rtnVal
# --------------------------------------------------------------------------
# ZMSObject.isModifiedInParentLanguage
#
# Returns True if current object is modified in parent language.
# --------------------------------------------------------------------------
def isModifiedInParentLanguage(self, lang, REQUEST):
rtnVal = False
parent = self.getParentLanguage(lang)
if parent is not None:
req = {'lang':lang, 'preview':REQUEST.get('preview','') }
change_dt_lang = self.getObjProperty('change_dt',req)
req = {'lang':parent, 'preview':REQUEST.get('preview','') }
change_dt_parent = self.getObjProperty('change_dt',req)
try:
if change_dt_lang is not None and change_dt_parent is not None:
rtnVal = _globals.compareDate(change_dt_lang, change_dt_parent) > 0
except:
_globals.writeError(self,"[isModifiedInParentLanguage]: Unexpected exception: change_dt_lang=%s, change_dt_parent=%s!"%(str(change_dt_lang),str(change_dt_parent)))
return rtnVal
# --------------------------------------------------------------------------
# ZMSObject.isVisible:
#
# Returns 1 if current object is visible.
# --------------------------------------------------------------------------
def isVisible(self, REQUEST):
REQUEST = _globals.nvl(REQUEST,self.REQUEST)
lang = REQUEST.get('lang',self.getPrimaryLanguage())
visible = True
visible = visible and self.isTranslated(lang,REQUEST) # Object is translated.
visible = visible and self.isCommitted(REQUEST) # Object has been committed.
visible = visible and self.isActive(REQUEST) # Object is active.
return visible
# --------------------------------------------------------------------------
# ZMSObject.get_size
#
# @param REQUEST
# --------------------------------------------------------------------------
def get_size(self, REQUEST={}):
size = 0
keys = self.getObjAttrs().keys()
if self.getType()=='ZMSRecordSet':
keys = [self.getMetaobjAttrIds(self.meta_id)[0]]
for key in keys:
objAttr = self.getObjAttr(key)
value = self.getObjAttrValue( objAttr, REQUEST)
size = size + _globals.get_size(value)
return size
# --------------------------------------------------------------------------
# ZMSObject.getDCCoverage
#
# Returns "Dublin Core: Coverage".
#
# @param REQUEST
# --------------------------------------------------------------------------
def getDCCoverage(self, REQUEST={}):
key_coverage = 'attr_dc_coverage'
obj_vers = self.getObjVersion(REQUEST)
coverage = getattr( obj_vers, key_coverage, '') # Take a performant shortcut to get object-property.
coverages = [ '', 'obligation', None]
if coverage in coverages:
coverage = 'global.' + self.getPrimaryLanguage()
return coverage
# --------------------------------------------------------------------------
# ZMSObject.getDCType
#
# Returns "Dublin Core: Type".
#
# @param REQUEST
# --------------------------------------------------------------------------
def getDCType(self, REQUEST):
return self.getObjProperty('attr_dc_type',REQUEST)
# --------------------------------------------------------------------------
# ZMSObject.getDCDescription
#
# Returns "Dublin Core: Description".
#
# @param REQUEST
# --------------------------------------------------------------------------
def getDCDescription(self, REQUEST):
return self.getObjProperty('attr_dc_description',REQUEST)
# --------------------------------------------------------------------------
# ZMSObject.getSelf:
# --------------------------------------------------------------------------
def getSelf(self, meta_type=None):
ob = self
if meta_type is not None and not ob.isMetaType( meta_type):
parent = ob.getParentNode()
if parent is not None:
ob = parent.getSelf(meta_type)
return ob
# --------------------------------------------------------------------------
# ZMSObject.icon:
# --------------------------------------------------------------------------
def icon(self):
try:
icon = self.display_icon( self.REQUEST, zpt=False)
if icon.find( '://') > 0:
icon = icon[ icon.find( '://')+3:]
icon = icon[ icon.find( '/'):]
BASEPATH1 = self.REQUEST.get('BASEPATH1','?')
if icon.startswith( BASEPATH1):
icon = icon[ len( BASEPATH1):]
if icon.startswith( '/'):
icon = icon[1:]
return icon
except:
_globals.writeError( self, '[icon]: An unexpected error occured!')
# --------------------------------------------------------------------------
# ZMSObject.display_icon:
#
# @param REQUEST
# --------------------------------------------------------------------------
def display_icon(self, REQUEST, meta_type=None, key='icon', zpt=None):
icon_title = self.display_type(REQUEST,meta_type)
if zpt is None:
zpt = False
pattern = '%s'
if zpt:
pattern = '<img src="%s" title="'+icon_title+'"/>'
obj_type = meta_type
if obj_type is None:
if not self.isActive(REQUEST):
key = 'icon_disabled'
obj_type = self.meta_id
if obj_type in self.getMetaobjIds( sort=0):
if zpt:
metaObjAttr = self.getMetaobjAttr( obj_type, 'icon_clazz')
if metaObjAttr is not None:
icon_clazz = None
if metaObjAttr['type'] == 'py':
icon_clazz = metaObjAttr['py'](zmscontext=self)
elif metaObjAttr['type'] == 'constant':
icon_clazz = metaObjAttr.get('custom',None)
if icon_clazz:
return '<i class="%s" title="%s"></i>'%(icon_clazz,icon_title)
if key in self.getMetaobjAttrIds( obj_type):
metaObjAttr = self.getMetaobjAttr( obj_type, key)
if metaObjAttr is not None and metaObjAttr['type'] == 'method':
value = _globals.dt_html(self,metaObjAttr.get('custom',''),REQUEST)
elif metaObjAttr is not None and metaObjAttr['type'] == 'py':
value = metaObjAttr['py'](zmscontext=self)
else:
value = metaObjAttr.get( 'custom', None)
if value is not None and type(value) is not str:
return pattern%value.absolute_url()
metaObj = self.getMetaobj( obj_type)
if metaObj:
if metaObj[ 'type'] == 'ZMSResource':
return pattern%'%sico_class.gif'%self.MISC_ZMS
elif metaObj[ 'type'] == 'ZMSLibrary':
return pattern%'%sico_library.gif'%self.MISC_ZMS
elif metaObj[ 'type'] == 'ZMSPackage':
return pattern%'%sico_package.gif'%self.MISC_ZMS
elif metaObj[ 'type'] == 'ZMSRecordSet':
return pattern%'%sico_sqldb.gif'%self.MISC_ZMS
elif metaObj[ 'type'] == 'ZMSReference':
return pattern%'%sico_linkcontainer.gif'%self.MISC_ZMS
return pattern%'%sico_document.gif'%self.MISC_ZMS
return pattern%'%s/p_/broken'
# --------------------------------------------------------------------------
# ZMSObject.display_type:
#
# @param REQUEST
# --------------------------------------------------------------------------
def display_type(self, REQUEST={}, meta_type=None):
obj_type = _globals.nvl( meta_type, self.meta_id)
metaObj = self.getMetaobj( obj_type)
if type( metaObj) is dict and metaObj.has_key( 'name'):
obj_type = metaObj[ 'name']
lang_key = 'TYPE_%s'%obj_type.upper()
lang_str = self.getZMILangStr( lang_key)
if lang_key == lang_str:
return obj_type
else:
return lang_str
# --------------------------------------------------------------------------
# ZMSObject.breadcrumbs_obj_path:
# --------------------------------------------------------------------------
def breadcrumbs_obj_path(self, portalMaster=True):
REQUEST = self.REQUEST
# Handle This.
rtn = []
obj = self
for lvl in range(self.getLevel()+1):
if obj is not None:
obj_item = [obj]
obj_item.extend(rtn)
rtn = obj_item
obj = obj.getParentNode()
# Handle Portal Master.
if portalMaster and self.getConfProperty('Portal.Master',''):
try:
thisHome = self.getHome()
masterHome = getattr(thisHome,self.getConfProperty('Portal.Master',''),None)
if masterHome is not None:
masterDocElmnt = masterHome.content
obj_item = masterDocElmnt.breadcrumbs_obj_path()
obj_item.extend(rtn)
rtn = obj_item
except:
_globals.writeError( self, '[breadcrumbs_obj_path]: An unexpected error occured while handling portal master!')
return rtn
# --------------------------------------------------------------------------
# ZMSObject.relative_obj_path:
# --------------------------------------------------------------------------
def relative_obj_path(self):
return self.absolute_url()[len(self.getDocumentElement().absolute_url())+1:]
############################################################################
# ZMSObject.manage_changeProperties:
#
# Change properties.
############################################################################
def manage_changeProperties(self, lang, REQUEST, RESPONSE=None):
""" ZMSObject.manage_changeProperties """
message = ''
messagekey = 'manage_tabs_message'
t0 = time.time()
redirect_self = False
redirect_self = redirect_self or REQUEST.get('btn','') == ''
redirect_self = redirect_self or self.isPage()
for attr in self.getMetaobj(self.meta_id)['attrs']:
attr_type = attr['type']
redirect_self = redirect_self or attr_type in self.getMetaobjIds()+['*']
redirect_self = redirect_self and (self.isPageContainer() or not REQUEST.get('btn','') in [ self.getZMILangStr('BTN_CANCEL'), self.getZMILangStr('BTN_BACK')])
if REQUEST.get('btn','') not in [ self.getZMILangStr('BTN_CANCEL'), self.getZMILangStr('BTN_BACK')]:
try:
##### Object State #####
self.setObjStateModified(REQUEST)
##### Resources #####
if 'resources' in self.getMetaobjAttrIds( self.meta_id):
resources = self.getObjProperty( 'resources', REQUEST)
l = map( lambda x: 0, range( len( resources)))
for key in self.getObjAttrs().keys():
obj_attr = self.getObjAttr( key)
el_name = self.getObjAttrName( obj_attr, lang)
if REQUEST.has_key( el_name) and REQUEST.has_key( 'resource_%s'%el_name):
el_value = REQUEST.get( el_name)
if el_value is not None:
for i in range( len( resources)):
v = resources[ i]
if el_value.find( '/'+v.getFilename()) > 0:
l[ i] = l[ i] + 1
c = 0
for i in range( len( resources)):
v = resources[ c]
if l[ i] == 0:
del resources[ c]
else:
src_old = '%s/@%i/%s'%(self.id,i,v.getFilename())
src_new = '%s/@%i/%s'%(self.id,c,v.getFilename())
for key in self.getObjAttrs().keys():
obj_attr = self.getObjAttr( key)
el_name = self.getObjAttrName( obj_attr, lang)
if REQUEST.has_key( el_name) and REQUEST.has_key( 'resource_%s'%el_name):
el_value = REQUEST.get( el_name)
if el_value is not None:
el_value = el_value.replace( src_old, src_new)
REQUEST.set( el_name, el_value)
c = c + 1
for key in self.getObjAttrs().keys():
obj_attr = self.getObjAttr( key)
el_name = self.getObjAttrName( obj_attr, lang)
if REQUEST.has_key( el_name) and REQUEST.has_key( 'resource_%s'%el_name):
v = REQUEST.get( 'resource_%s'%el_name)
if isinstance(v,ZPublisher.HTTPRequest.FileUpload):
if len(getattr(v,'filename',''))>0:
v = _blobfields.createBlobField(self,_globals.DT_FILE,v)
resources.append( v)
el_value = REQUEST.get( el_name)
if el_value is not None:
src_new = '%s/@%i/%s'%(self.absolute_url(),len(resources)-1,v.getFilename())
if v.getContentType().find( 'image/') == 0:
el_value = el_value + '<img src="%s" alt="" border="0" align="absmiddle"/>'%src_new
else:
el_value = el_value + '<a href="%s" target="_blank">%s</a>'%(src_new,v.getFilename())
REQUEST.set( el_name, el_value)
redirect_self = True
self.setObjProperty( 'resources', resources, lang)
##### Properties #####
keys = self.getObjAttrs().keys()
for key in keys:
if key != 'resources':
self.setReqProperty(key,REQUEST)
##### Resource-Objects #####
metaObjIds = self.getMetaobjIds(sort=0)
keys = self.getMetaobjAttrIds(self.meta_id)
for key in keys:
objAttr = self.getMetaobjAttr(self.meta_id,key)
if objAttr['type'] in metaObjIds and \
self.getMetaobj(objAttr['type'])['type'] == 'ZMSResource':
for ob in self.getObjChildren(key,REQUEST):
REQUEST.set('objAttrNamePrefix',ob.id+'_')
ob.manage_changeProperties( lang, REQUEST)
REQUEST.set('objAttrNamePrefix','')
##### VersionManager ####
self.onChangeObj(REQUEST)
##### Message ####
message = self.getZMILangStr('MSG_CHANGED')
except:
message = _globals.writeError(self,"[manage_changeProperties]")
messagekey = 'manage_tabs_error_message'
message += ' (in '+str(int((time.time()-t0)*100.0)/100.0)+' secs.)'
# Return with message.
target_ob = self.getParentNode()
if redirect_self or target_ob is None:
target_ob = self
target = REQUEST.get( 'manage_target', '%s/manage_main'%target_ob.absolute_url())
target = self.url_append_params( target, { 'lang': lang, 'preview': 'preview', messagekey: message})
target = '%s#_%s'%( target, self.id)
if RESPONSE is not None:
return RESPONSE.redirect( target)
############################################################################
###
### Common Functions
###
############################################################################
# --------------------------------------------------------------------------
# ZMSObject.findObjId:
#
# Find object by ids given in object path.
# --------------------------------------------------------------------------
def findObjId(self, relative_obj_path, REQUEST):
_globals.writeLog( self, '[findObjId]: relative_obj_path=%s'%relative_obj_path)
docElmnt = self.getDocumentElement()
ob = docElmnt
if len(relative_obj_path) > 0:
ids = relative_obj_path.split( '/')
for id in ids:
ob = getattr(ob,id,None)
if ob is None:
if self.getConfProperty('ZMS.InternalLinks.autocorrection',0)==1:
ob_id = self.getHome().id+'@'+relative_obj_path.split('/')[-1]
_globals.writeBlock(self,'[findObjId]: ob_id='+ob_id)
ob = self.synchronizeRefs( ob_id)
break
return ob
# --------------------------------------------------------------------------
# ZMSObject.getDeclId:
#
# Returns declarative id.
# --------------------------------------------------------------------------
def getDeclId(self, REQUEST={}):
declId = ''
try:
if self.getConfProperty( 'ZMS.pathhandler', 0) != 0:
obj_attrs_keys = self.getObjAttrs().keys()
for key in [ 'attr_dc_identifier_doi', 'attr_dc_identifier_url_node']:
if key in obj_attrs_keys:
declId = self.getObjProperty( key, REQUEST)
if len( declId) > 0:
break
if len(declId) == 0:
declId = self.getTitlealt( REQUEST)
mapping = self.dict_list(self.getConfProperty('ZMS.pathhandler.id_quote.mapping',' _-_/_'))
declId = _globals.id_quote( declId, mapping)
except:
_globals.writeError(self,'[getDeclId]: can\'t get declarative id')
if len( declId) == 0:
declId = self.id
return declId
# --------------------------------------------------------------------------
# ZMSObject.aq_absolute_url:
#
# Object is called in a different context and we want to use acquisition.
# --------------------------------------------------------------------------
def aq_absolute_url(self, relative=0):
abs_url = self.absolute_url( relative)
i = abs_url.find('/content')
if i > 0:
home_id = abs_url[:i]
home_id = home_id[home_id.rfind('/')+1:]
home_abs_url = self.getHome().absolute_url()
if home_id in home_abs_url.split('/'):
abs_url = home_abs_url + abs_url[i:]
return abs_url
# --------------------------------------------------------------------------
# ZMSObject.getDeclUrl:
#
# Returns declarative url.
# --------------------------------------------------------------------------
def getDeclUrl(self, REQUEST={}):
if self.getConfProperty('ZMS.pathhandler',0) == 0 or REQUEST.get('preview','')=='preview':
url = self.aq_absolute_url()
else:
ob = self.getDocumentElement()
url = ob.aq_absolute_url()
for id in self.aq_absolute_url()[len(url):].split('/'):
if len(id) > 0:
ob = getattr(ob,id,None)
if ob is None: break
url += '/' + ob.getDeclId(REQUEST)
return url
# --------------------------------------------------------------------------
# ZMSObject.getPageExt:
#
# Get page-extension.
# --------------------------------------------------------------------------
def getPageExt(self, REQUEST):
pageexts = ['.html']
if 'attr_pageext' in self.getObjAttrs().keys():
obj_attr = self.getObjAttr('attr_pageext')
if obj_attr.has_key('keys') and len(obj_attr.get('keys')) > 0:
pageexts = obj_attr.get('keys')
pageext = self.getObjProperty('attr_pageext',REQUEST)
if pageext == '' or pageext is None:
pageext = pageexts[0]
return pageext
# --------------------------------------------------------------------------
# ZMSObject.getHref2Html:
# ZMSObject.getHref2IndexHtml:
# ZMSObject.getHref2PrintHtml:
# ZMSObject.getHref2SitemapHtml:
#
# "Sans-Document"-Navigation: reference to first page that contains visible
# page-elements.
# --------------------------------------------------------------------------
def getHref2Html(self, fct, pageext, REQUEST):
if not self.isPage():
parent = self.getParentNode()
pageext = parent.getPageExt(REQUEST)
href = parent.getHref2Html( fct, pageext, REQUEST)
href += '#' + self.id
else:
href = self.getDeclUrl(REQUEST)+'/'
# Assemble href.
if REQUEST.get('ZMS_INDEX_HTML',0)==1 or fct != 'index' or len(self.getLangIds())>1:
href += '%s_%s%s'%(fct,REQUEST['lang'],pageext)
if REQUEST.get('preview','')=='preview': href=self.url_append_params(href,{'preview':'preview'})
if (REQUEST.get('ZMS_PATHCROPPING',False) or self.getConfProperty('ZMS.pathcropping',0)==1) and REQUEST.get('export_format','') == '':
base = REQUEST.get('BASE0','')
if href.find( base) == 0:
href = href[len(base):]
return href
#++
def getHref2SitemapHtml(self, REQUEST):
if not REQUEST.has_key('lang'): REQUEST.set('lang',self.getLanguage(REQUEST))
href = 'sitemap_%s%s'%(REQUEST['lang'],self.getPageExt(REQUEST))
if REQUEST.get('preview','')=='preview': href = self.url_append_params(href,{'preview':'preview'})
return href
#++
def getHref2PrintHtml(self, REQUEST):
if not REQUEST.has_key('lang'):
REQUEST.set('lang',self.getLanguage(REQUEST))
href = 'index_print_%s%s'%(REQUEST['lang'],self.getPageExt(REQUEST))
qs = REQUEST.get('QUERY_STRING','')
if len(qs)>0:
href += '?' + qs
if REQUEST.get('preview','')=='preview':
href = self.url_append_params(href,{'preview':'preview'})
return href
#++
def getHref2IndexHtml(self, REQUEST, deep=1):
if not REQUEST.has_key('lang'):
try: REQUEST.set('lang',self.getLanguage(REQUEST))
except: REQUEST['lang'] = self.getPrimaryLanguage()
#-- [ReqBuff]: Fetch buffered value from Http-Request.
try:
reqBuffId = 'getHref2IndexHtml_%i'%deep
value = self.fetchReqBuff(reqBuffId,REQUEST)
return value
except:
#-- Get value.
ob = self
fct = REQUEST.get('ZMS_SKIN','index')
if fct == 'index' and 'index_html' in self.objectIds():
value = self.absolute_url()
if REQUEST.get('lang','') != '':
value = self.url_append_params(value,{'lang':REQUEST['lang']})
if REQUEST.get('preview','') != '':
value = self.url_append_params(value,{'preview':REQUEST['preview']})
else:
if deep:
ob = _globals.getPageWithElements( self, REQUEST)
value = ob.getHref2Html( fct, ob.getPageExt(REQUEST), REQUEST)
#-- [ReqBuff]: Returns value and stores it in buffer of Http-Request.
return self.storeReqBuff(reqBuffId,value,REQUEST)
############################################################################
###
### Object-actions of management interface
###
############################################################################
# --------------------------------------------------------------------------
# ZMSObject.getMetaobjZMI:
#
# Returns ZMI from method 'manage_main' for meta-object specified by given Id.
# --------------------------------------------------------------------------
def getMetaobjZMI(self, id, REQUEST):
metaObj = self.getMetaobj(id)
for metaObjAttr in metaObj['attrs']:
if metaObjAttr['id']=='manage_main':
value = metaObjAttr['custom']
fmName = REQUEST.get('fmName','form0')
REQUEST.set('fmName',fmName)
html = []
if REQUEST.get('ZMS_INSERT',None) is not None:
fmAction = '%s/manage_addZMSCustom'%REQUEST['URL1'][len(REQUEST['BASE0']):]
html.append('<form name="%s" action="%s" method="post" enctype="multipart/form-data">\n'%(fmName,fmAction))
html.append('<input type="hidden" name="meta_id" value="%s">\n'%id)
html.append('<input type="hidden" name="id" value="%s">\n'%REQUEST.get('id','e'))
html.append('<input type="hidden" name="_sort_id:int" value="%i">\n'%REQUEST.get('_sort_id'))
html.append('<input type="hidden" name="ZMS_INSERT" value="%s">\n'%REQUEST.get('ZMS_INSERT'))
else:
fmAction = 'manage_changeProperties'
html.append('<form name="%s" action="%s" method="post" enctype="multipart/form-data">\n'%(fmName,fmAction))
REQUEST.set('ZMS_ACTION',fmAction)
try:
value = _globals.dt_html(self,value,REQUEST)
except:
value = _globals.writeError(self,'[getMetaobjZMI]')
html.append(self.f_submitInputFields(self,REQUEST))
html.append(value)
html.append('</form>\n')
return ''.join(html)
return None
############################################################################
###
### DOM-Methods
###
############################################################################
# --------------------------------------------------------------------------
# ZMSObject.getLevel:
#
# The hierarchical level of this node.
# --------------------------------------------------------------------------
def getLevel(self):
docElmnt = self.getDocumentElement()
docPath = docElmnt.getPhysicalPath()
path = self.getPhysicalPath()
return len(path)-len(docPath)
# --------------------------------------------------------------------------
# ZMSObject.isAnchestor:
#
# True if self is anchestor of given object.
# --------------------------------------------------------------------------
def isAnchestor(self, ob):
if ob is not None:
path = '/'.join(self.getPhysicalPath())
obPath = '/'.join(ob.getPhysicalPath())
return obPath.startswith(path)
return False
# --------------------------------------------------------------------------
# ZMSObject.getParentByDepth:
#
# The parent of this node by depth.
# --------------------------------------------------------------------------
def getParentByDepth(self, deep):
rtn = self
for i in range(deep):
rtn = rtn.getParentNode()
return rtn
# --------------------------------------------------------------------------
# ZMSObject.getParentByLevel:
#
# The parent of this node by level.
# --------------------------------------------------------------------------
def getParentByLevel(self, level):
rtn = self
while rtn.getLevel() > level:
rtn = rtn.getParentNode()
return rtn
# --------------------------------------------------------------------------
# ZMSObject.getParentNode:
# --------------------------------------------------------------------------
security.declarePublic('getParentNode')
def getParentNode(self):
"""
The parent of this node.
All nodes except root may have a parent.
"""
rtn = getattr(self, 'aq_parent', None)
# Handle ZMSProxyObjects.
if hasattr( rtn, 'is_blob') or hasattr( rtn, 'base'):
rtn = getattr( self, self.absolute_url().split( '/')[-2], None)
return rtn
# --------------------------------------------------------------------------
# ZMSObject.getTreeNodes:
# --------------------------------------------------------------------------
def getTreeNodes(self, REQUEST={}, meta_types=None):
"""
Returns a NodeList that contains all children of this subtree in correct order.