~ubuntu-branches/ubuntu/natty/moin/natty-updates

« back to all changes in this revision

Viewing changes to MoinMoin/widget/html.py

  • Committer: Bazaar Package Importer
  • Author(s): Jonas Smedegaard
  • Date: 2008-06-22 21:17:13 UTC
  • mfrom: (0.9.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20080622211713-fpo2zrq3s5dfecxg
Tags: 1.7.0-3
Simplify /etc/moin/wikilist format: "USER URL" (drop unneeded middle
CONFIG_DIR that was wrongly advertised as DATA_DIR).  Make
moin-mass-migrate handle both formats and warn about deprecation of
the old one.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
"""
3
3
    MoinMoin - HTML Widgets
4
4
 
5
 
    @copyright: 2003 by J�rgen Hermann <jh@web.de>
 
5
    @copyright: 2003 Juergen Hermann <jh@web.de>
6
6
    @license: GNU GPL, see COPYING for details.
7
7
"""
8
8
 
9
9
from MoinMoin import wikiutil
10
 
from MoinMoin.widget.base import Widget
11
10
 
12
11
# sort attributes or not? (set to 1 by unit tests)
13
12
_SORT_ATTRS = 0
26
25
    def __unicode__(self):
27
26
        return wikiutil.escape(self.text)
28
27
 
29
 
        
 
28
 
30
29
class Raw:
31
30
    """ Raw HTML code.
32
31
    """
36
35
    def __unicode__(self):
37
36
        return self.markup
38
37
 
39
 
        
 
38
 
40
39
class Element:
41
40
    """ Abstract base class for HTML elements.
42
41
    """
60
59
    }
61
60
 
62
61
    def __init__(self, **kw):
63
 
        for key in kw.keys():
 
62
        for key in kw:
64
63
            key = key.lower()
65
 
            if not self._ATTRS.has_key(key):
 
64
            if key not in self._ATTRS:
66
65
                raise AttributeError(
67
66
                    "Invalid HTML attribute %r for tag <%s>" % (
68
67
                        key, self.tagname()))
76
75
    def _openingtag(self):
77
76
        result = [self.tagname()]
78
77
        attrs = self.attrs.items()
79
 
        if _SORT_ATTRS: attrs.sort()
 
78
        if _SORT_ATTRS:
 
79
            attrs.sort()
80
80
        for key, val in attrs:
81
81
            key = key.lower()
82
 
            if self._BOOL_ATTRS.has_key(key):
83
 
                if val: result.append(key)
 
82
            if key in self._BOOL_ATTRS:
 
83
                if val:
 
84
                    result.append(key)
84
85
            else:
85
86
                result.append(u'%s="%s"' % (key, wikiutil.escape(val, 1)))
86
87
        return ' '.join(result)
87
88
 
88
89
    def __unicode__(self):
89
 
        raise NotImplementedError 
90
 
 
91
 
        
 
90
        raise NotImplementedError
 
91
 
 
92
 
92
93
class EmptyElement(Element):
93
94
    """ HTML elements with an empty content model.
94
95
    """
272
273
class DIV(CompositeElement):
273
274
    "generic language/style container"
274
275
    _ATTRS = {
 
276
        'id': None,
275
277
        'class': None,
276
278
    }
277
279
 
396
398
        'checked': None,
397
399
        'class': None,
398
400
        'disabled': None,
 
401
        'id': None,
399
402
        'ismap': None,
400
403
        'maxlength': None,
401
404
        'name': None,
428
431
    "form field label text"
429
432
    _ATTRS = {
430
433
        'class': None,
 
434
        'for_': None,
431
435
    }
432
436
 
 
437
    def _openingtag(self):
 
438
        result = [self.tagname()]
 
439
        attrs = self.attrs.items()
 
440
        if _SORT_ATTRS:
 
441
            attrs.sort()
 
442
        for key, val in attrs:
 
443
            key = key.lower()
 
444
            if key == 'for_':
 
445
                key = 'for'
 
446
            if key in self._BOOL_ATTRS:
 
447
                if val:
 
448
                    result.append(key)
 
449
            else:
 
450
                result.append(u'%s="%s"' % (key, wikiutil.escape(val, 1)))
 
451
        return ' '.join(result)
 
452
 
 
453
 
433
454
class LI(CompositeElement):
434
455
    "list item"
435
456
    _ATTRS = {
596
617
        'align': None,
597
618
        'class': None,
598
619
        'valign': None,
 
620
        'colspan': None,
 
621
        'rowspan': None,
599
622
    }
600
623
 
601
624
class TEXTAREA(CompositeElement):
664
687
### Widgets
665
688
#############################################################################
666
689
 
667
 
class FormWidget(Widget):
668
 
    """ Widget to display data as an HTML form.
669
 
 
670
 
        TODO: write code to combine the labels, data and HTML DOM to a complete form.
671
 
 
672
 
        INCOMPLETE!!!
673
 
    """
674
 
 
675
 
    def __init__(self, request, **kw):
676
 
        Widget.__init__(self, request)
677
 
        # FIXME     vvvv
678
 
        self.form = form(**kw)
679
 
 
680
 
    def render(self):
681
 
        self.request.write(str(self.form))
 
690
#from MoinMoin.widget.base import Widget
 
691
#class FormWidget(Widget):
 
692
#    """ Widget to display data as an HTML form.
 
693
#
 
694
#        TODO: write code to combine the labels, data and HTML DOM to a complete form.
 
695
#
 
696
#        INCOMPLETE!!!
 
697
#    """
 
698
#
 
699
#    def __init__(self, request, **kw):
 
700
#        Widget.__init__(self, request)
 
701
#        self.form = form(**kw)
 
702
#
 
703
#    def render(self):
 
704
#        self.request.write(str(self.form))
682
705