diff MoinMoin/util/forms.py @ 0:5568cf133caf moin20-repo-reboot

create moin/2.0 repo, drop all history (see notes below) Up to now, we used the moin/2.0-dev repository (which was cloned from another, older moin repo quite some time ago). Over the years, these repositories got rather fat (>200MB) and were a pain to clone over slow, high-latency or unreliable connections. After having finished most of the dirty work in moin2, having killed all the 3rd party code we had bundled with (is now installed by quickinstall / pip / setuptools), it is now a good time to get rid of the history (the history made up most of the repository's size). If you need to look at the history, look there: http://hg.moinmo.in/moin/2.0-dev The new moin/2.0 repository has the files as of this changesets: http://hg.moinmo.in/moin/2.0-dev/rev/075132a755dc The changeset hashes that link the repositories will be tagged (in both repositories) as "moin20-repo-reboot".
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sun, 20 Feb 2011 20:53:45 +0100
parents
children fe47d0977895
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MoinMoin/util/forms.py	Sun Feb 20 20:53:45 2011 +0100
@@ -0,0 +1,62 @@
+# -*- coding: ascii -*-
+"""
+    MoinMoin - form helpers for flatland / jinja2
+
+    @copyright: 2010 Thomas Waldmann, Jason Kirtland, Scott Wilson
+    @license: see flatland license
+"""
+
+from jinja2 import Markup
+
+from flatland.out.markup import Generator
+from flatland.schema.util import find_i18n_function
+
+from MoinMoin.i18n import _, L_, N_
+
+def label_filter(tagname, attributes, contents, context, bind):
+    """Provide a translated, generated fallback for field labels."""
+    if bind is not None and not contents:
+        contents = _(bind.label)
+    return contents
+label_filter.tags = set(['label'])
+
+
+def button_filter(tagname, attributes, contents, context, bind):
+    """Show translated text in clickable buttons and submits."""
+    if bind is None:
+        return contents
+    if tagname == 'input':
+        if ('value' not in attributes and
+            attributes.get('type') in ['submit', 'reset', ]):
+            attributes['value'] = _(bind.default_value)
+    elif tagname == 'button' and not contents:
+        contents = _(bind.default_value)
+    return contents
+button_filter.tags = set(['input', 'button'])
+
+
+def error_filter_factory(class_='moin-error'):
+    """Returns an HTML generation filter annotating field CSS class on error.
+
+    :param class: The css class to apply in case of validation error on a
+                  field.  Default: 'error'
+    """
+    def error_filter(tagname, attributes, contents, context, bind):
+        if bind is not None and bind.errors:
+            if 'class' in attributes:
+                attributes['class'] = ' '.join([attributes['class'], class_])
+            else:
+                attributes['class'] = class_
+        return contents
+    error_filter.tags = set(['input'])
+    return error_filter
+
+error_filter = error_filter_factory()
+
+
+def make_generator():
+    """make an html generator"""
+    return Generator(auto_domid=True, auto_for=True, auto_filter=True,
+                     markup_wrapper=Markup,
+                     filters=[label_filter, button_filter, error_filter])
+