changeset 226:029cb888d253

use flatland filters for autofocus/placeholder html5 attrs, use html5 input field types email/url/search
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sat, 14 May 2011 17:39:38 +0200
parents bac248bcf98c
children 7099a64c00ad
files MoinMoin/apps/frontend/views.py MoinMoin/templates/layout.html MoinMoin/templates/register.html MoinMoin/templates/usersettings.html MoinMoin/util/forms.py
diffstat 5 files changed, 50 insertions(+), 33 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/apps/frontend/views.py	Mon May 09 23:58:03 2011 +0200
+++ b/MoinMoin/apps/frontend/views.py	Sat May 14 17:39:38 2011 +0200
@@ -743,11 +743,11 @@
     """a simple user registration form"""
     name = 'register'
 
-    username = String.using(label=L_('Name')).validated_by(Present())
-    password1 = String.using(label=L_('Password')).validated_by(Present())
-    password2 = String.using(label=L_('Password')).validated_by(Present())
-    email = String.using(label=L_('E-Mail')).validated_by(IsEmail())
-    openid = String.using(label=L_('OpenID'), optional=True).validated_by(URLValidator())
+    username = String.using(label=L_('Name')).with_properties(placeholder=L_("The login name you want to use")).validated_by(Present())
+    password1 = String.using(label=L_('Password')).with_properties(placeholder=L_("The login password you want to use")).validated_by(Present())
+    password2 = String.using(label=L_('Password')).with_properties(placeholder=L_("Repeat the same password")).validated_by(Present())
+    email = String.using(label=L_('E-Mail')).with_properties(placeholder=L_("Your E-Mail address")).validated_by(IsEmail())
+    openid = String.using(label=L_('OpenID'), optional=True).with_properties(placeholder=L_("Your OpenID address")).validated_by(URLValidator())
     submit = String.using(default=L_('Register'), optional=True)
 
     validators = [ValidRegistration()]
@@ -759,12 +759,12 @@
     """
     name = 'openid'
 
-    username = String.using(label=L_('Name')).validated_by(Present())
-    password1 = String.using(label=L_('Password')).validated_by(Present())
-    password2 = String.using(label=L_('Password')).validated_by(Present())
+    username = String.using(label=L_('Name')).with_properties(placeholder=L_("The login name you want to use")).validated_by(Present())
+    password1 = String.using(label=L_('Password')).with_properties(placeholder=L_("The login password you want to use")).validated_by(Present())
+    password2 = String.using(label=L_('Password')).with_properties(placeholder=L_("Repeat the same password")).validated_by(Present())
 
-    email = String.using(label=L_('E-Mail')).validated_by(IsEmail())
-    openid = String.using(label=L_('OpenID')).validated_by(URLValidator())
+    email = String.using(label=L_('E-Mail')).with_properties(placeholder=L_("Your E-Mail address")).validated_by(IsEmail())
+    openid = String.using(label=L_('OpenID')).with_properties(placeholder=L_("Your OpenID address")).validated_by(URLValidator())
     submit = String.using(optional=True)
 
     validators = [ValidRegistration()]
@@ -882,8 +882,8 @@
     """a simple password lost form"""
     name = 'lostpass'
 
-    username = String.using(label=L_('Name'), optional=True)
-    email = String.using(label=L_('E-Mail'), optional=True).validated_by(IsEmail())
+    username = String.using(label=L_('Name'), optional=True).with_properties(placeholder=L_("Your login name"))
+    email = String.using(label=L_('E-Mail'), optional=True).with_properties(placeholder=L_("Your E-Mail address")).validated_by(IsEmail())
     submit = String.using(default=L_('Recover password'), optional=True)
 
     validators = [ValidLostPassword()]
@@ -949,10 +949,10 @@
     """a simple password recovery form"""
     name = 'recoverpass'
 
-    username = String.using(label=L_('Name')).validated_by(Present())
-    token = String.using(label=L_('Recovery token')).validated_by(Present())
-    password1 = String.using(label=L_('New password')).validated_by(Present())
-    password2 = String.using(label=L_('New password (repeat)')).validated_by(Present())
+    username = String.using(label=L_('Name')).with_properties(placeholder=L_("Your login name")).validated_by(Present())
+    token = String.using(label=L_('Recovery token')).with_properties(placeholder=L_("The recovery token that has been sent to you")).validated_by(Present())
+    password1 = String.using(label=L_('New password')).with_properties(placeholder=L_("The login password you want to use")).validated_by(Present())
+    password2 = String.using(label=L_('New password (repeat)')).with_properties(placeholder=L_("Repeat the same password")).validated_by(Present())
     submit = String.using(default=L_('Change password'), optional=True)
 
     validators = [ValidPasswordRecovery()]
@@ -1024,7 +1024,7 @@
     """
     name = 'login'
 
-    username = String.using(label=L_('Name'), optional=False).validated_by(Present())
+    username = String.using(label=L_('Name'), optional=False).with_properties(autofocus=True).validated_by(Present())
     password = String.using(label=L_('Password'), optional=False).validated_by(Present())
     openid = String.using(label=L_('OpenID'), optional=True).validated_by(Present(), URLValidator())
 
@@ -1114,16 +1114,16 @@
 
 class UserSettingsPasswordForm(Form):
     name = 'usersettings_password'
-    password_current = String.using(label=L_('Current Password')).validated_by(Present())
-    password1 = String.using(label=L_('New password')).validated_by(Present())
-    password2 = String.using(label=L_('New password (repeat)')).validated_by(Present())
+    password_current = String.using(label=L_('Current Password')).with_properties(placeholder=L_("Your current login password")).validated_by(Present())
+    password1 = String.using(label=L_('New password')).with_properties(placeholder=L_("The login password you want to use")).validated_by(Present())
+    password2 = String.using(label=L_('New password (repeat)')).with_properties(placeholder=L_("Repeat the same password")).validated_by(Present())
     submit = String.using(default=L_('Change password'), optional=True)
     validators = [ValidChangePass()]
 
 
 class UserSettingsNotificationForm(Form):
     name = 'usersettings_notification'
-    email = String.using(label=L_('E-Mail')).validated_by(IsEmail())
+    email = String.using(label=L_('E-Mail')).with_properties(placeholder=L_("Your E-Mail address")).validated_by(IsEmail())
     submit = String.using(default=L_('Save'), optional=True)
 
 
@@ -1157,9 +1157,9 @@
     # these forms can't be global because we need app object, which is only available within a request:
     class UserSettingsPersonalForm(Form):
         name = 'usersettings_personal' # "name" is duplicate
-        name = String.using(label=L_('Name')).validated_by(Present())
-        aliasname = String.using(label=L_('Alias-Name'), optional=True)
-        openid = String.using(label=L_('OpenID'), optional=True).validated_by(URLValidator())
+        name = String.using(label=L_('Name')).with_properties(placeholder=L_("The login name you want to use")).validated_by(Present())
+        aliasname = String.using(label=L_('Alias-Name'), optional=True).with_properties(placeholder=L_("Your alias name (informational)"))
+        openid = String.using(label=L_('OpenID'), optional=True).with_properties(placeholder=L_("Your OpenID address")).validated_by(URLValidator())
         #timezones_keys = sorted(Locale('en').time_zones.keys())
         timezones_keys = [unicode(tz) for tz in pytz.common_timezones]
         timezone = Enum.using(label=L_('Timezone')).valued(*timezones_keys)
@@ -1176,8 +1176,8 @@
                                   key=lambda x: x[1])
         themes_keys = [t[0] for t in themes_available]
         theme_name = Enum.using(label=L_('Theme name')).with_properties(labels=dict(themes_available)).valued(*themes_keys)
-        css_url = String.using(label=L_('User CSS URL'), optional=True).validated_by(URLValidator())
-        edit_rows = Integer.using(label=L_('Editor size')).validated_by(Converted())
+        css_url = String.using(label=L_('User CSS URL'), optional=True).with_properties(placeholder=L_("Give the URL of your custom CSS (optional)")).validated_by(URLValidator())
+        edit_rows = Integer.using(label=L_('Editor size')).with_properties(placeholder=L_("Editor textarea height (0=auto)")).validated_by(Converted())
         submit = String.using(default=L_('Save'), optional=True)
 
     dispatch = dict(
--- a/MoinMoin/templates/layout.html	Mon May 09 23:58:03 2011 +0200
+++ b/MoinMoin/templates/layout.html	Sat May 14 17:39:38 2011 +0200
@@ -22,7 +22,7 @@
             <input type="hidden" name="do" value="fullsearch" />
             <input type="hidden" name="context" value="180" />
             <label for="moin-searchinput">{{ _('Search') }}</label>
-            <input id="moin-searchinput" type="text" name="value" value="{{ request.values.get('value', '') }}" size="20" />
+            <input id="moin-searchinput" type="search" name="value" value="{{ request.values.get('value', '') }}" size="20" />
             <input id="moin-titlesearch" name="titlesearch" type="submit" value="{{ _('Titles') }}" />
             <input id="moin-fullsearch" name="fullsearch" type="submit" value="{{ _('Text') }}" />
         </div>
--- a/MoinMoin/templates/register.html	Mon May 09 23:58:03 2011 +0200
+++ b/MoinMoin/templates/register.html	Sat May 14 17:39:38 2011 +0200
@@ -10,8 +10,8 @@
     {{ forms.render_field(gen, form['username'], 'text') }}
     {{ forms.render_field(gen, form['password1'], 'password') }}
     {{ forms.render_field(gen, form['password2'], 'password') }}
-    {{ forms.render_field(gen, form['email'], 'text') }}
-    {{ forms.render_field(gen, form['openid'], 'text') }}
+    {{ forms.render_field(gen, form['email'], 'email') }}
+    {{ forms.render_field(gen, form['openid'], 'url') }}
     {{ forms.render_textcha(gen, form) }}
   </dl>
   {{ gen.input(form['submit'], type='submit') }}
--- a/MoinMoin/templates/usersettings.html	Mon May 09 23:58:03 2011 +0200
+++ b/MoinMoin/templates/usersettings.html	Sat May 14 17:39:38 2011 +0200
@@ -21,7 +21,7 @@
   <dl>
     {{ forms.render_field(gen, form['name'], 'text') }}
     {{ forms.render_field(gen, form['aliasname'], 'text') }}
-    {{ forms.render_field(gen, form['openid'], 'text') }}
+    {{ forms.render_field(gen, form['openid'], 'url') }}
     {{ forms.render_select(gen, form['timezone']) }}
     {{ forms.render_select(gen, form['locale']) }}
   </dl>
@@ -49,7 +49,7 @@
 {{ gen.form.open(form, method="post", action=url_for('frontend.usersettings', part=part)) }}
   {{ forms.render_errors(form) }}
   <dl>
-    {{ forms.render_field(gen, form['email'], 'text') }}
+    {{ forms.render_field(gen, form['email'], 'email') }}
   </dl>
   {{ gen.input(form['submit'], type='submit') }}
 {{ gen.form.close() }}
@@ -62,7 +62,7 @@
   {{ forms.render_errors(form) }}
   <dl>
     {{ forms.render_select(gen, form['theme_name']) }}
-    {{ forms.render_field(gen, form['css_url'], 'text') }}
+    {{ forms.render_field(gen, form['css_url'], 'url') }}
     {{ forms.render_field(gen, form['edit_rows'], 'text') }}
   </dl>
   {{ gen.input(form['submit'], type='submit') }}
--- a/MoinMoin/util/forms.py	Mon May 09 23:58:03 2011 +0200
+++ b/MoinMoin/util/forms.py	Sat May 14 17:39:38 2011 +0200
@@ -41,6 +41,22 @@
     return contents
 required_filter.tags = set(['input', 'label'])
 
+def autofocus_filter(tagname, attributes, contents, context, bind):
+    if bind is not None:
+        autofocus = bind.properties.get('autofocus')
+        if autofocus:
+            attributes[u'autofocus'] = u'autofocus'
+    return contents
+required_filter.tags = set(['input', 'textarea', ])
+
+def placeholder_filter(tagname, attributes, contents, context, bind):
+    if bind is not None:
+        placeholder = bind.properties.get('placeholder')
+        if placeholder:
+            attributes[u'placeholder'] = placeholder
+    return contents
+required_filter.tags = set(['input', 'textarea', ])
+
 def error_filter_factory(class_='moin-error'):
     """Returns an HTML generation filter annotating field CSS class on error.
 
@@ -65,5 +81,6 @@
     return Generator(auto_domid=True, auto_for=True, auto_filter=True,
                      markup_wrapper=Markup,
                      filters=[label_filter, button_filter,
-                              error_filter, required_filter])
+                              error_filter,
+                              required_filter, placeholder_filter, autofocus_filter])