~ubuntu-branches/ubuntu/hardy/mailman/hardy-updates

« back to all changes in this revision

Viewing changes to Mailman/htmlformat.py

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2006-07-03 16:59:25 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20060703165925-175ubna955u796c0
Tags: 0:2.1.8-1ubuntu1
* Merge to Debian; remaining Ubuntu changes:
  - debian/mailman.init: Create /var/{run,lock}/mailman.
  - debian/control: exim4 -> postfix.
* debian/control: Dependency fix: apache -> apache2.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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.
2
2
#
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.
7
 
 
7
#
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.
12
 
 
12
#
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.
16
16
 
17
17
 
18
18
"""Library for program-based construction of an HTML documents.
84
84
    # Add a new blank cell at the end
85
85
    def NewCell(self):
86
86
        self.cells[-1].append('')
87
 
        
 
87
 
88
88
    def AddRow(self, row):
89
89
        self.cells.append(row)
90
90
 
99
99
            DictMerge(self.cell_info[row], kws)
100
100
        else:
101
101
            self.cell_info[row][col] = kws
102
 
        
 
102
 
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
113
 
    
 
113
 
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
154
154
            if key == 'border' and val == None:
155
155
                output = output + ' BORDER'
156
156
                continue
157
 
            else:       
 
157
            else:
158
158
                output = output + ' %s="%s"' % (key.upper(), val)
159
159
 
160
160
        return output
202
202
        output = output + '\n' + ' '*indent + '</table>\n'
203
203
 
204
204
        return output
205
 
        
 
205
 
206
206
 
207
207
class Link:
208
208
    def __init__(self, href, text, target=None):
209
209
        self.href = href
210
210
        self.text = text
211
211
        self.target = target
212
 
    
 
212
 
213
213
    def Format(self, indent=0):
214
214
        texpr = ""
215
215
        if self.target != None:
223
223
    def __init__(self, size, *items):
224
224
        self.items = list(items)
225
225
        self.size = size
226
 
    
 
226
 
227
227
    def Format(self, indent=0):
228
228
        output = '<font size="%s">' % self.size
229
229
        for item in self.items:
236
236
    def __init__(self, *items, **kw):
237
237
        self.items = list(items)
238
238
        self.attrs = kw
239
 
    
 
239
 
240
240
    def Format(self, indent=0):
241
241
        seq = []
242
242
        for k, v in self.attrs.items():
334
334
            output.append('%s</HTML>' % tab)
335
335
        return NL.join(output)
336
336
 
337
 
    def addError(self, errmsg, tag=None, *args):
 
337
    def addError(self, errmsg, tag=None):
338
338
        if tag is 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()))
343
343
 
344
344
 
345
345
class HeadlessDocument(Document):
346
346
    """Document without head section, for templates that provide their own."""
347
347
    suppress_head = 1
348
 
    
 
348
 
349
349
 
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)
356
 
        return output       
 
356
        return output
357
357
 
358
358
 
359
359
class QuotedContainer(Container):
375
375
 
376
376
class Underline(StdContainer):
377
377
    tag = 'u'
378
 
        
 
378
 
379
379
class Bold(StdContainer):
380
 
    tag = 'strong'  
 
380
    tag = 'strong'
381
381
 
382
382
class Italic(StdContainer):
383
383
    tag = 'em'
494
494
        self.size = size
495
495
    def Format(self, indent=0):
496
496
        output = '<spacer type="vertical" height="%d">' % self.size
497
 
        return output 
 
497
        return output
498
498
 
499
499
class WidgetArray:
500
500
    Widget = None
578
578
                     (spaces, HTMLFormatObject(item, indent + 2))
579
579
        output = output + '%s</ol>\n' % spaces
580
580
        return output
581
 
        
 
581
 
582
582
class DefinitionList(Container):
583
583
    def Format(self, indent=0):
584
584
        spaces = ' ' * indent
632
632
 
633
633
 
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
640
640
      self.size     = size
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
643
643
      if not multiple:
644
644
         if type(selected) == types.IntType:
645
645
             self.selected = (selected,)
649
649
             self.selected = (selected[0],)
650
650
         else:
651
651
             self.selected = (0,)
652
 
 
 
652
 
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
658
658
      if items == 0:
659
659
          return ""
660
 
 
 
660
 
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"
667
 
 
 
667
 
668
668
      for i in range(items):
669
669
          if i in self.selected:
670
670
              checked = " Selected"
671
671
          else:
672
672
              checked = ""
673
 
 
 
673
 
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"
677
 
 
 
677
 
678
678
      return text + spaces + '</Select>'