-
Notifications
You must be signed in to change notification settings - Fork 0
/
_textformatmanager.py
104 lines (95 loc) · 4.1 KB
/
_textformatmanager.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
################################################################################
# _textformatmanager.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.
################################################################################
# Product Imports.
import _globals
import _objattrs
class TextFormatObject:
# ----------------------------------------------------------------------------
# TextFormatObject.getSecNo
#
# Returns section-number.
# ----------------------------------------------------------------------------
def getSecNo( self):
sec_no = ''
#-- [ReqBuff]: Fetch buffered value from Http-Request.
parentNode = self.getParentNode()
if parentNode is None or \
getattr(parentNode,'meta_type',None) not in self.dGlobalAttrs.keys():
return sec_no
reqBuffId = 'getSecNo'
try:
levelnfc = parentNode.fetchReqBuff( '%s_levelnfc'%reqBuffId, self.REQUEST, forced=True)
if levelnfc > 0:
sec_no = parentNode.fetchReqBuff( '%s_%s'%(reqBuffId,self.id), self.REQUEST, forced=True)
except:
levelnfc = parentNode.attr('levelnfc')
parentNode.storeReqBuff( '%s_levelnfc'%reqBuffId, levelnfc, self.REQUEST)
if len(levelnfc) > 0:
parent_no = parentNode.getSecNo()
sectionizer = _globals.MySectionizer(levelnfc)
siblings = parentNode.filteredChildNodes( self.REQUEST)
for sibling in siblings:
curr_no = ''
level = 0
if sibling.isPageElement():
format = sibling.attr('format')
if format.find('headline') == 0:
level = int(format[len(_globals.id_prefix(format)):])-1
elif sibling.isPage():
level = 1
if level > 0:
sectionizer.processLevel(level)
curr_no = parent_no + str(sectionizer)
if self == sibling:
sec_no = curr_no
#-- [ReqBuff]: Store value in buffer of Http-Request.
parentNode.storeReqBuff( '%s_%s'%(reqBuffId,sibling.id), curr_no, self.REQUEST)
#-- [ReqBuff]: Return value.
return sec_no
# ----------------------------------------------------------------------------
# TextFormatObject.getText
#
# Returns text with section-number.
# ----------------------------------------------------------------------------
def getText( self, REQUEST, key='text'):
s = self.getObjProperty(key,REQUEST)
if self.isPageElement():
sec_no = self.getSecNo()
if len(sec_no) > 0:
s = sec_no + ' ' + s
s = _globals.form_quote(s,REQUEST)
return s
# ----------------------------------------------------------------------------
# TextFormatObject.renderText:
# ----------------------------------------------------------------------------
def renderText( self, format, key, text, REQUEST, id=None, clazz=None):
# Process format.
if format is not None:
textformat = self.getTextFormat( format, REQUEST)
if textformat is not None and len( text) > 0:
text = textformat.renderText( text, REQUEST, id, clazz)
# Custom hook.
try:
name = 'renderCustomText'
if hasattr(self,name):
text = getattr(self,name)(context=self,key=key,text=text,REQUEST=REQUEST)
except:
_globals.writeError( self, '[renderText]: can\'t %s'%name)
# Return.
return text
################################################################################