Commits

Thomas Waldmann  committed 4010e5e

fix usersettings, support name being a list

add a jinja2 macro render_fieldlist for a simple rendering of such lists

  • Participants
  • Parent commits 90df744
  • Branches namespaces

Comments (0)

Files changed (3)

File MoinMoin/apps/frontend/views.py

 from flaskext.babel import format_date
 from flaskext.themes import get_themes_list
 
-from flatland import Form, String, Integer, Boolean, Enum
+from flatland import Form, String, Integer, Boolean, Enum, List
 from flatland.validation import Validator, Present, IsEmail, ValueBetween, URLValidator, Converted, ValueAtLeast
 
 from jinja2 import Markup
     # 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')).with_properties(placeholder=L_("The login name you want to use")).validated_by(Present())
+        name = List.using(label=L_('Name')).of(String.with_properties(placeholder=L_("The login name you want to use")).validated_by(Present()))
         display_name = String.using(label=L_('Display-Name'), optional=True).with_properties(placeholder=L_("Your display 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())

File MoinMoin/templates/forms.html

   {% endif %}
 {% endmacro %}
 
+{% macro render_fieldlist(gen, fieldlist, field_type) %}
+  <dt>
+    {{ gen.label(fieldlist) }}
+  </dt>
+  <dd>
+  {% for field in fieldlist %}
+      {{ gen.input(field, type=field_type) }}
+      {{ render_errors(field) }}
+  {% endfor %}
+  </dd>
+{% endmacro %}
+
 {% macro render_field(gen, field, field_type) %}
   <dt>
     {{ gen.label(field) }}

File MoinMoin/templates/usersettings_forms.html

 {{ gen.form.open(form, method="post", action=url_for('frontend.usersettings')) }}
 {{ forms.render_errors(form) }}
 <dl>
-    {{ forms.render_field(gen, form['name'], 'text') }}
+    {{ forms.render_fieldlist(gen, form['name'], 'text') }}
     {{ forms.render_field(gen, form['display_name'], 'text') }}
     {{ forms.render_field(gen, form['openid'], 'url') }}
     {{ forms.render_select(gen, form['timezone']) }}