1
# Copyright (C) 1998,1999,2000,2001,2002 by the Free Software Foundation, Inc.
1
# Copyright (C) 1998-2005 by the Free Software Foundation, Inc.
3
3
# This program is free software; you can redistribute it and/or
4
4
# modify it under the terms of the GNU General Public License
5
5
# as published by the Free Software Foundation; either version 2
6
6
# of the License, or (at your option) any later version.
8
8
# This program is distributed in the hope that it will be useful,
9
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
11
# GNU General Public License for more details.
13
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18
18
"""Library for program-based construction of an HTML documents.
99
99
DictMerge(self.cell_info[row], kws)
101
101
self.cell_info[row][col] = kws
103
103
def AddRowInfo(self, row, **kws):
104
104
kws = CaseInsensitiveKeyedDict(kws)
105
105
if not self.row_info.has_key(row):
110
110
# What's the index for the row we just put in?
111
111
def GetCurrentRowIndex(self):
112
112
return len(self.cells)-1
114
114
# What's the index for the col we just put in?
115
115
def GetCurrentCellIndex(self):
116
116
return len(self.cells[-1])-1
202
202
output = output + '\n' + ' '*indent + '</table>\n'
208
208
def __init__(self, href, text, target=None):
211
211
self.target = target
213
213
def Format(self, indent=0):
215
215
if self.target != None:
236
236
def __init__(self, *items, **kw):
237
237
self.items = list(items)
240
240
def Format(self, indent=0):
242
242
for k, v in self.attrs.items():
334
334
output.append('%s</HTML>' % tab)
335
335
return NL.join(output)
337
def addError(self, errmsg, tag=None, *args):
337
def addError(self, errmsg, tag=None):
339
339
tag = _('Error: ')
340
340
self.AddItem(Header(3, Bold(FontAttr(
341
341
_(tag), color=mm_cfg.WEB_ERROR_COLOR, size='+2')).Format() +
342
Italic(errmsg % args).Format()))
342
Italic(errmsg).Format()))
345
345
class HeadlessDocument(Document):
346
346
"""Document without head section, for templates that provide their own."""
347
347
suppress_head = 1
350
350
class StdContainer(Container):
351
351
def Format(self, indent=0):
353
353
output = '<%s>' % self.tag
354
354
output = output + Container.Format(self, indent)
355
355
output = '%s</%s>' % (output, self.tag)
359
359
class QuotedContainer(Container):
578
578
(spaces, HTMLFormatObject(item, indent + 2))
579
579
output = output + '%s</ol>\n' % spaces
582
582
class DefinitionList(Container):
583
583
def Format(self, indent=0):
584
584
spaces = ' ' * indent
634
634
class SelectOptions:
635
def __init__(self, varname, values, legend,
635
def __init__(self, varname, values, legend,
636
636
selected=0, size=1, multiple=None):
637
637
self.varname = varname
638
638
self.values = values
639
639
self.legend = legend
641
641
self.multiple = multiple
642
# we convert any type to tuple, commas are needed
642
# we convert any type to tuple, commas are needed
644
644
if type(selected) == types.IntType:
645
645
self.selected = (selected,)
649
649
self.selected = (selected[0],)
651
651
self.selected = (0,)
653
653
def Format(self, indent=0):
654
654
spaces = " " * indent
655
655
items = min( len(self.values), len(self.legend) )
657
657
# jcrey: If there is no argument, we return nothing to avoid errors
661
661
text = "\n" + spaces + "<Select name=\"%s\"" % self.varname
662
662
if self.size > 1:
663
663
text = text + " size=%d" % self.size
664
664
if self.multiple:
665
665
text = text + " multiple"
666
666
text = text + ">\n"
668
668
for i in range(items):
669
669
if i in self.selected:
670
670
checked = " Selected"
674
674
opt = " <option value=\"%s\"%s> %s </option>" % (
675
675
self.values[i], checked, self.legend[i])
676
676
text = text + spaces + opt + "\n"
678
678
return text + spaces + '</Select>'