source: ZMS/trunk/_textformatmanager.py @ 1830

Revision 1830, 4.1 KB checked in by zmsdev, 2 months ago (diff)

Ticket#35 (desy): textformatmanager / Sites 2009 patch 1

Line 
1################################################################################
2# _textformatmanager.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# Product Imports.
20import _globals
21import _objattrs
22
23
24class TextFormatObject:
25
26  # ----------------------------------------------------------------------------
27  #  TextFormatObject.getSecNo
28  #
29  #  Returns section-number.
30  # ----------------------------------------------------------------------------
31  def getSecNo( self):
32    sec_no = ''
33    #-- [ReqBuff]: Fetch buffered value from Http-Request.
34    parentNode = self.getParentNode()
35    if parentNode is None or \
36       getattr(parentNode,'meta_type',None) not in self.dGlobalAttrs.keys():
37      return sec_no
38    reqBuffId = 'getSecNo'
39    try:
40      levelnfc = parentNode.fetchReqBuff( '%s_levelnfc'%reqBuffId, self.REQUEST, forced=True)
41      if levelnfc > 0:
42        sec_no = parentNode.fetchReqBuff( '%s_%s'%(reqBuffId,self.id), self.REQUEST, forced=True)
43    except:
44      levelnfc = parentNode.attr('levelnfc')
45      parentNode.storeReqBuff( '%s_levelnfc'%reqBuffId, levelnfc, self.REQUEST)
46      if len(levelnfc) > 0:
47        parent_no = parentNode.getSecNo()
48        sectionizer = _globals.MySectionizer(levelnfc)
49        siblings = parentNode.filteredChildNodes( self.REQUEST)
50        for sibling in siblings:
51          curr_no = ''
52          level = 0
53          if sibling.isPageElement():
54            format = sibling.attr('format')
55            if format.find('headline') == 0:
56              level = int(format[len(_globals.id_prefix(format)):])-1
57          elif sibling.isPage():
58            level = 1
59          if level > 0:
60            sectionizer.processLevel(level)
61            curr_no = parent_no + str(sectionizer)
62            if self == sibling:
63              sec_no = curr_no
64          #-- [ReqBuff]: Store value in buffer of Http-Request.
65          parentNode.storeReqBuff( '%s_%s'%(reqBuffId,sibling.id), curr_no, self.REQUEST)
66    #-- [ReqBuff]: Return value.
67    return sec_no
68
69
70  # ----------------------------------------------------------------------------
71  #  TextFormatObject.getText
72  #
73  #  Returns text with section-number.
74  # ----------------------------------------------------------------------------
75  def getText( self, REQUEST, key='text'):
76    s = self.getObjProperty(key,REQUEST)
77    if self.isPageElement():
78      sec_no = self.getSecNo()
79      if len(sec_no) > 0:
80        s = sec_no + ' ' + s
81    s = _globals.form_quote(s,REQUEST)
82    return s
83
84
85  # ----------------------------------------------------------------------------
86  #  TextFormatObject.renderText:
87  # ----------------------------------------------------------------------------
88  def renderText( self, format, key, text, REQUEST, id=None, clazz=None):
89    # Process format.
90    if format is not None:
91      textformat = self.getTextFormat( format, REQUEST)
92      if textformat is not None and len( text) > 0:
93        text = textformat.renderText( text, REQUEST, id, clazz)
94    # Custom hook.
95    try:
96      name = 'renderCustomText'
97      if hasattr(self,name):
98        text = getattr(self,name)(context=self,key=key,text=text,REQUEST=REQUEST)
99    except:
100      _globals.writeError( self, '[renderText]: can\'t %s'%name)
101    # Return.
102    return text
103
104################################################################################
Note: See TracBrowser for help on using the repository browser.