예제 #1
0
def setup(template, use_version=None):
    """Register the flatland directives with a template.

    :param template: a `Template` instance
    """
    if use_version is None:
        use_version = 6 if hasattr(template, 'add_directives') else 5

    if use_version == 6:
        from flatland.out.genshi_06 import setup
        setup(template)
    else:
        install_element_mixin()
        template.filters.append(flatland_filter)
예제 #2
0
파일: __init__.py 프로젝트: jek/flatland
def setup(template, use_version=None):
    """Register the flatland directives with a template.

    :param template: a `Template` instance
    """
    if use_version is None:
        use_version = 6 if hasattr(template, "add_directives") else 5

    if use_version == 6:
        from flatland.out.genshi_06 import setup

        setup(template)
    else:
        install_element_mixin()
        template.filters.append(flatland_filter)
예제 #3
0
파일: _util.py 프로젝트: dag/flatland
def _render_genshi_06(markup, language, schema, **kw):
    from genshi.template import MarkupTemplate
    from flatland.out.genshi_06 import setup

    template = MarkupTemplate(markup)
    setup(template)

    if schema is not None:
        kw['form'] = schema()
    else:
        kw['form'] = None
    output = template.generate(**kw).render(language)

    # strip div wrapper off
    got = output[output.index('\n') + 1:output.rindex('\n')]
    got = got.strip()

    return got
예제 #4
0
def _render_genshi_06(markup, language, schema, **kw):
    from genshi.template import MarkupTemplate
    from flatland.out.genshi_06 import setup

    template = MarkupTemplate(markup)
    setup(template)

    if schema is not None:
        kw['form'] = schema()
    else:
        kw['form'] = None
    output = template.generate(**kw).render(language)

    # strip div wrapper off
    got = output[output.index('\n') + 1:output.rindex('\n')]
    got = got.strip()

    return got
from flatland import Form, String
from flatland.validation import Present, LengthBetween, ValuesEqual
from flatland.out.genshi_06 import setup

class PasswordCompareElement(Form):
    password = String.using(
        label='New Password',
        validators=[
            Present(),
            LengthBetween(5, 25)
        ]
    )
    confirm = String.using(
        label='Repeat Password',
        validators=[
            Present(),
            ValuesEqual(
                '../confirm',
                '../password'
            )]
    )



template = MarkupTemplate(markup)
setup(template)

kw = dict(form=PasswordCompareElement())
output = template.generate(**kw).render('xhtml')
print output