tags.py
author Sylvain Thénault <sylvain.thenault@logilab.fr>
Wed, 16 Jun 2010 09:21:49 +0200
changeset 5754 51179e0bb250
parent 5424 8ecbcbff9777
child 6048 4695b1ee58a0
permissions -rw-r--r--
[test] support for test on postgres database using the same mecanism as sqlite: one template database generated when necessary + actual test database created from the template * * * [test] reset postgres database between test of the same fixture
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5421
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
     1
# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
     2
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
     3
#
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
     4
# This file is part of CubicWeb.
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
     5
#
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
     6
# CubicWeb is free software: you can redistribute it and/or modify it under the
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
     7
# terms of the GNU Lesser General Public License as published by the Free
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
     8
# Software Foundation, either version 2.1 of the License, or (at your option)
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
     9
# any later version.
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
    10
#
5424
8ecbcbff9777 replace logilab-common by CubicWeb in disclaimer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5421
diff changeset
    11
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT
5421
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
    12
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
    13
# FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
    14
# details.
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
    15
#
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
    16
# You should have received a copy of the GNU Lesser General Public License along
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
    17
# with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
980
59552ba2015f more tags, map klass -> class avoiding needs to use **dict
sylvain.thenault@logilab.fr
parents: 909
diff changeset
    18
"""helper classes to generate simple (X)HTML tags
59552ba2015f more tags, map klass -> class avoiding needs to use **dict
sylvain.thenault@logilab.fr
parents: 909
diff changeset
    19
59552ba2015f more tags, map klass -> class avoiding needs to use **dict
sylvain.thenault@logilab.fr
parents: 909
diff changeset
    20
"""
59552ba2015f more tags, map klass -> class avoiding needs to use **dict
sylvain.thenault@logilab.fr
parents: 909
diff changeset
    21
__docformat__ = "restructuredtext en"
59552ba2015f more tags, map klass -> class avoiding needs to use **dict
sylvain.thenault@logilab.fr
parents: 909
diff changeset
    22
4023
eae23c40627a drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3847
diff changeset
    23
from cubicweb.uilib import simple_sgml_tag, sgml_attributes
980
59552ba2015f more tags, map klass -> class avoiding needs to use **dict
sylvain.thenault@logilab.fr
parents: 909
diff changeset
    24
845
6103d0f55a0b simple tags
sylvain.thenault@logilab.fr
parents:
diff changeset
    25
class tag(object):
1623
sylvain.thenault@logilab.fr
parents: 1065
diff changeset
    26
    def __init__(self, name, escapecontent=True):
845
6103d0f55a0b simple tags
sylvain.thenault@logilab.fr
parents:
diff changeset
    27
        self.name = name
1623
sylvain.thenault@logilab.fr
parents: 1065
diff changeset
    28
        self.escapecontent = escapecontent
sylvain.thenault@logilab.fr
parents: 1065
diff changeset
    29
845
6103d0f55a0b simple tags
sylvain.thenault@logilab.fr
parents:
diff changeset
    30
    def __call__(self, __content=None, **attrs):
1623
sylvain.thenault@logilab.fr
parents: 1065
diff changeset
    31
        attrs.setdefault('escapecontent', self.escapecontent)
845
6103d0f55a0b simple tags
sylvain.thenault@logilab.fr
parents:
diff changeset
    32
        return simple_sgml_tag(self.name, __content, **attrs)
6103d0f55a0b simple tags
sylvain.thenault@logilab.fr
parents:
diff changeset
    33
3803
414bb8439002 [web ui] decorate form buttons with icons (at last)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2517
diff changeset
    34
button = tag('button')
845
6103d0f55a0b simple tags
sylvain.thenault@logilab.fr
parents:
diff changeset
    35
input = tag('input')
6103d0f55a0b simple tags
sylvain.thenault@logilab.fr
parents:
diff changeset
    36
textarea = tag('textarea')
6103d0f55a0b simple tags
sylvain.thenault@logilab.fr
parents:
diff changeset
    37
a = tag('a')
6103d0f55a0b simple tags
sylvain.thenault@logilab.fr
parents:
diff changeset
    38
span = tag('span')
1623
sylvain.thenault@logilab.fr
parents: 1065
diff changeset
    39
div = tag('div', False)
845
6103d0f55a0b simple tags
sylvain.thenault@logilab.fr
parents:
diff changeset
    40
img = tag('img')
846
e449f1da7d09 new label tag
sylvain.thenault@logilab.fr
parents: 845
diff changeset
    41
label = tag('label')
895
e78ae38506db select tag now accepts a multiple argument
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 861
diff changeset
    42
option = tag('option')
980
59552ba2015f more tags, map klass -> class avoiding needs to use **dict
sylvain.thenault@logilab.fr
parents: 909
diff changeset
    43
h1 = tag('h1')
59552ba2015f more tags, map klass -> class avoiding needs to use **dict
sylvain.thenault@logilab.fr
parents: 909
diff changeset
    44
h2 = tag('h2')
59552ba2015f more tags, map klass -> class avoiding needs to use **dict
sylvain.thenault@logilab.fr
parents: 909
diff changeset
    45
h3 = tag('h3')
59552ba2015f more tags, map klass -> class avoiding needs to use **dict
sylvain.thenault@logilab.fr
parents: 909
diff changeset
    46
h4 = tag('h4')
59552ba2015f more tags, map klass -> class avoiding needs to use **dict
sylvain.thenault@logilab.fr
parents: 909
diff changeset
    47
h5 = tag('h5')
3847
7cf2b338a8e7 [common] add tr, th and td tags
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 3803
diff changeset
    48
tr = tag('tr')
7cf2b338a8e7 [common] add tr, th and td tags
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 3803
diff changeset
    49
th = tag('th')
7cf2b338a8e7 [common] add tr, th and td tags
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 3803
diff changeset
    50
td = tag('td')
861
7985b5db2284 provide a mini HTML select tag constructor
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 846
diff changeset
    51
1054
434e098f6c76 allow arbitrary arguments
sylvain.thenault@logilab.fr
parents: 980
diff changeset
    52
def select(name, id=None, multiple=False, options=[], **attrs):
895
e78ae38506db select tag now accepts a multiple argument
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 861
diff changeset
    53
    if multiple:
909
4685a8c21d73 select needs to accept an id
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 895
diff changeset
    54
        attrs['multiple'] = 'multiple'
4685a8c21d73 select needs to accept an id
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 895
diff changeset
    55
    if id:
4685a8c21d73 select needs to accept an id
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 895
diff changeset
    56
        attrs['id'] = id
1647
9936aca2453d sort attribute for testing purpose
sylvain.thenault@logilab.fr
parents: 1623
diff changeset
    57
    attrs['name'] = name
2517
d664652b7f9c select attributes should be escaped
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
    58
    html = [u'<select %s>' % sgml_attributes(attrs)]
861
7985b5db2284 provide a mini HTML select tag constructor
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 846
diff changeset
    59
    html += options
7985b5db2284 provide a mini HTML select tag constructor
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 846
diff changeset
    60
    html.append(u'</select>')
7985b5db2284 provide a mini HTML select tag constructor
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 846
diff changeset
    61
    return u'\n'.join(html)
7985b5db2284 provide a mini HTML select tag constructor
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 846
diff changeset
    62