changeset 1988:490c13d072f2

remove Submit widget The Submit widget was a mistake. The buttons carry no user input, and making it part of the form screws up POST form handling. Instead of being a widget, the submit button has its label kept in the class member submit_label of the Form, and is rendered by a new macro forms.render_submit.
author Cheer Xiao <xiaqqaix@gmail.com>
date Tue, 12 Feb 2013 10:28:18 +0800
parents ff71ef20d363
children ff77f6d8da38
files MoinMoin/apps/frontend/views.py MoinMoin/forms.py MoinMoin/items/__init__.py MoinMoin/items/ticket.py MoinMoin/search/__init__.py MoinMoin/templates/blog/utils.html MoinMoin/templates/delete.html MoinMoin/templates/destroy.html MoinMoin/templates/forms.html MoinMoin/templates/index.html MoinMoin/templates/login.html MoinMoin/templates/lookup.html MoinMoin/templates/lostpass.html MoinMoin/templates/modify.html MoinMoin/templates/openid_register.html MoinMoin/templates/recoverpass.html MoinMoin/templates/register.html MoinMoin/templates/rename.html MoinMoin/templates/revert.html MoinMoin/templates/search.html MoinMoin/templates/ticket.html MoinMoin/templates/utils.html
diffstat 22 files changed, 48 insertions(+), 44 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/apps/frontend/views.py	Tue Feb 12 01:11:36 2013 +0100
+++ b/MoinMoin/apps/frontend/views.py	Tue Feb 12 10:28:18 2013 +0800
@@ -47,7 +47,7 @@
 from MoinMoin.themes import render_template, contenttype_to_class
 from MoinMoin.apps.frontend import frontend
 from MoinMoin.forms import (OptionalText, RequiredText, URL, YourOpenID, YourEmail, RequiredPassword, Checkbox,
-                            InlineCheckbox, Select, Names, Tags, Natural, Submit, Hidden, MultiSelect)
+                            InlineCheckbox, Select, Names, Tags, Natural, Hidden, MultiSelect)
 from MoinMoin.items import BaseChangeForm, Item, NonExistent
 from MoinMoin.items.content import content_registry
 from MoinMoin import user, util
@@ -137,7 +137,7 @@
     refs = OptionalText.using(label='refs')
     tags = Tags.using(optional=True).using(label='tags')
     history = InlineCheckbox.using(label=L_('search also in non-current revisions'))
-    submit = Submit.using(default=L_('Lookup'))
+    submit_label = L_('Lookup')
 
 
 @frontend.route('/+lookup', methods=['GET', 'POST'])
@@ -165,7 +165,6 @@
     # TAGS might be there multiple times, thus we need multi:
     lookup_form = LookupForm.from_flat(request.values.items(multi=True))
     valid = lookup_form.validate()
-    lookup_form['submit'].set_default()  # XXX from_flat() kills all values
     if valid:
         history = bool(request.values.get('history'))
         idx_name = ALL_REVS if history else LATEST_REVS
@@ -241,7 +240,6 @@
 def search(item_name):
     search_form = SearchForm.from_flat(request.values)
     valid = search_form.validate()
-    search_form['submit'].set_default()  # XXX from_flat() kills all values
     query = search_form['q'].value
     if valid:
         history = bool(request.values.get('history'))
@@ -739,7 +737,7 @@
 
 class IndexForm(Form):
     contenttype = ContenttypeGroup
-    submit = Submit.using(default=L_('Filter'))
+    submit_label = L_('Filter')
 
 
 @frontend.route('/+index/', defaults=dict(item_name=''), methods=['GET', 'POST'])
@@ -756,7 +754,6 @@
     # values, eg. calling items with multi=True. See Werkzeug documentation for
     # more.
     form = IndexForm.from_flat(request.args.items(multi=True))
-    form['submit'].set_default()  # XXX from_flat() kills all values
     if not form['contenttype']:
         form['contenttype'].set(contenttype_groups)
 
@@ -1016,7 +1013,7 @@
     password2 = RequiredPassword.with_properties(placeholder=L_("Repeat the same password"))
     email = YourEmail
     openid = YourOpenID.using(optional=True)
-    submit = Submit.using(default=L_('Register'))
+    submit_label = L_('Register')
 
     validators = [ValidRegistration()]
 
@@ -1150,7 +1147,7 @@
 
     username = OptionalText.using(label=L_('Name')).with_properties(placeholder=L_("Your login name"))
     email = YourEmail.using(optional=True)
-    submit = Submit.using(default=L_('Recover password'))
+    submit_label = L_('Recover password')
 
     validators = [ValidLostPassword()]
 
@@ -1218,7 +1215,7 @@
         placeholder=L_("The login password you want to use"))
     password2 = RequiredPassword.using(label=L_('New password (repeat)')).with_properties(
         placeholder=L_("Repeat the same password"))
-    submit = Submit.using(default=L_('Change password'))
+    submit_label = L_('Change password')
 
     validators = [ValidPasswordRecovery()]
 
@@ -1284,7 +1281,10 @@
     username = RequiredText.using(label=L_('Name'), optional=False).with_properties(autofocus=True)
     password = RequiredPassword
     openid = YourOpenID.using(optional=True)
-    submit = Submit.using(default=L_('Log in'))
+    # This field results in a login_submit field in the POST form, which is in
+    # turn looked for by setup_user() in app.py as marker for login requests.
+    submit = Hidden.using(default='1')
+    submit_label = L_('Log in')
 
     validators = [ValidLogin()]
 
@@ -1361,19 +1361,21 @@
         placeholder=L_("The login password you want to use"))
     password2 = RequiredPassword.using(label=L_('New password (repeat)')).with_properties(
         placeholder=L_("Repeat the same password"))
-    submit = Submit.using(default=L_('Change password'))
+    submit_label = L_('Change password')
 
 
 class UserSettingsNotificationForm(Form):
     name = 'usersettings_notification'
     email = YourEmail
-    submit = Submit.using(default=L_('Save'))
+    submit_label = L_('Save')
 
 
 class UserSettingsNavigationForm(Form):
     name = 'usersettings_navigation'
+    # XXX Flatland insists a form having at least one element
+    dummy = Hidden
     # TODO: find a good way to handle quicklinks here
-    submit = Submit.using(default=L_('Save'))
+    submit_label = L_('Save')
 
 
 class UserSettingsOptionsForm(Form):
@@ -1383,7 +1385,7 @@
     scroll_page_after_edit = Checkbox.using(label=L_('Scroll page after edit'))
     show_comments = Checkbox.using(label=L_('Show comment sections'))
     disabled = Checkbox.using(label=L_('Disable this account forever'))
-    submit = Submit.using(default=L_('Save'))
+    submit_label = L_('Save')
 
 
 @frontend.route('/+usersettings', methods=['GET', 'POST'])
@@ -1406,7 +1408,7 @@
                                    key=lambda x: x[1])
         locales_keys = [l[0] for l in locales_available]
         locale = Select.using(label=L_('Locale')).with_properties(labels=dict(locales_available)).valued(*locales_keys)
-        submit = Submit.using(default=L_('Save'))
+        submit_label = L_('Save')
 
     class UserSettingsUIForm(Form):
         name = 'usersettings_ui'
@@ -1421,7 +1423,7 @@
             placeholder=L_("Editor textarea height (0=auto)"))
         results_per_page = Natural.using(label=L_('History results per page')).with_properties(
             placeholder=L_("Number of results per page (0=no paging)"))
-        submit = Submit.using(default=L_('Save'))
+        submit_label = L_('Save')
 
     form_classes = dict(
         personal=UserSettingsPersonalForm,
@@ -1488,7 +1490,6 @@
                     if success:
                         user_old_email = flaskg.user.email
                         d = dict(form.value)
-                        d.pop('submit')
                         for k, v in d.items():
                             flaskg.user.profile[k] = v
                         if (part == 'notification' and app.cfg.user_email_verification and
--- a/MoinMoin/forms.py	Tue Feb 12 01:11:36 2013 +0100
+++ b/MoinMoin/forms.py	Tue Feb 12 10:28:18 2013 +0800
@@ -148,8 +148,6 @@
 
 File = FileStorage.with_properties(widget=WIDGET_FILE)
 
-Submit = String.using(default=L_('OK'), optional=True).with_properties(widget=WIDGET_SUBMIT, class_=CLASS_BUTTON)
-
 Hidden = String.using(optional=True).with_properties(widget=WIDGET_HIDDEN)
 
 # optional=True is needed to get rid of the "required field" indicator on the UI (usually an asterisk)
--- a/MoinMoin/items/__init__.py	Tue Feb 12 01:11:36 2013 +0100
+++ b/MoinMoin/items/__init__.py	Tue Feb 12 10:28:18 2013 +0800
@@ -44,7 +44,7 @@
 from MoinMoin.util.interwiki import url_for_item
 from MoinMoin.util.registry import RegistryBase
 from MoinMoin.util.clock import timed
-from MoinMoin.forms import RequiredText, OptionalText, JSON, Tags, Submit
+from MoinMoin.forms import RequiredText, OptionalText, JSON, Tags
 from MoinMoin.constants.keys import (
     NAME, NAME_OLD, NAME_EXACT, WIKINAME, MTIME, SYSITEM_VERSION, ITEMTYPE,
     CONTENTTYPE, SIZE, ACTION, ADDRESS, HOSTNAME, USERID, COMMENT,
@@ -172,7 +172,7 @@
 
 class BaseChangeForm(TextChaizedForm):
     comment = OptionalText.using(label=L_('Comment')).with_properties(placeholder=L_("Comment about your change"))
-    submit = Submit
+    submit_label = L_('OK')
 
 
 class BaseMetaForm(Form):
--- a/MoinMoin/items/ticket.py	Tue Feb 12 01:11:36 2013 +0100
+++ b/MoinMoin/items/ticket.py	Tue Feb 12 10:28:18 2013 +0800
@@ -19,7 +19,7 @@
 
 from MoinMoin.i18n import L_
 from MoinMoin.themes import render_template
-from MoinMoin.forms import (Form, OptionalText, OptionalMultilineText, Submit, SmallNatural, Tags,
+from MoinMoin.forms import (Form, OptionalText, OptionalMultilineText, SmallNatural, Tags,
                             Reference, BackReference)
 from MoinMoin.storage.middleware.protecting import AccessDenied
 from MoinMoin.constants.keys import ITEMTYPE, CONTENTTYPE, ITEMID, CURRENT
@@ -66,7 +66,7 @@
     meta = TicketMetaForm
     backrefs = TicketBackRefForm
     message = OptionalMultilineText.using(label=L_("Message")).with_properties(rows=8, cols=80)
-    submit = Submit.using(default=L_("Update ticket"))
+    submit_label = L_("Update ticket")
 
     def _load(self, item):
         meta = item.prepare_meta_for_modify(item.meta)
@@ -137,7 +137,7 @@
             is_new = True
             # XXX suppress the "foo doesn't exist. Create it?" dummy content
             data_rendered = None
-            form['submit'] = L_('Submit ticket')
+            form.submit_label = L_('Submit ticket')
         else:
             is_new = False
             data_rendered = Markup(self.content._render_data())
--- a/MoinMoin/search/__init__.py	Tue Feb 12 01:11:36 2013 +0100
+++ b/MoinMoin/search/__init__.py	Tue Feb 12 10:28:18 2013 +0800
@@ -6,7 +6,7 @@
 """
 
 from MoinMoin.i18n import L_
-from MoinMoin.forms import Search, InlineCheckbox, Submit
+from MoinMoin.forms import Search, InlineCheckbox
 
 from flatland import Form, String, Boolean
 from flatland.validation import Validator
@@ -29,6 +29,6 @@
 class SearchForm(Form):
     q = Search
     history = InlineCheckbox.using(label=L_('search all revisions'))
-    submit = Submit.using(default=L_('Search'))
+    submit_label = L_('Search')
 
     validators = [ValidSearch()]
--- a/MoinMoin/templates/blog/utils.html	Tue Feb 12 01:11:36 2013 +0100
+++ b/MoinMoin/templates/blog/utils.html	Tue Feb 12 10:28:18 2013 +0800
@@ -61,7 +61,7 @@
     {{ gen.form.open(form, id='moin-searchform', method='get', action=url_for('frontend.search')) }}
         <div>
             {{ forms.render(form['q']) }}
-            {{ gen.button(form['submit'], type='submit', id='moin-search-submit') }}
+            {{ forms.render_submit(form, id='moin-search-submit') }}
             {{ forms.render_errors(form) }}
             <br />
             <input type="checkbox" id="moin-blog-search-this"
--- a/MoinMoin/templates/delete.html	Tue Feb 12 01:11:36 2013 +0100
+++ b/MoinMoin/templates/delete.html	Tue Feb 12 10:28:18 2013 +0800
@@ -12,7 +12,7 @@
     {{ forms.render(form['comment']) }}
     {{ forms.render_textcha(gen, form) }}
   </dl>
-  {{ forms.render(form['submit']) }}
+  {{ forms.render_submit(form) }}
 {{ gen.form.close() }}
 </div>
 {% endblock %}
--- a/MoinMoin/templates/destroy.html	Tue Feb 12 01:11:36 2013 +0100
+++ b/MoinMoin/templates/destroy.html	Tue Feb 12 10:28:18 2013 +0800
@@ -13,7 +13,7 @@
         {{ forms.render(form['comment']) }}
         {{ forms.render_textcha(gen, form) }}
       </dl>
-      {{ forms.render(form['submit']) }}
+      {{ forms.render_submit(form) }}
     {{ gen.form.close() }}
     </div>
 {% else %}
@@ -25,7 +25,7 @@
         {{ forms.render(form['comment']) }}
         {{ forms.render_textcha(gen, form) }}
       </dl>
-      {{ forms.render(form['submit']) }}
+      {{ forms.render_submit(form) }}
     {{ gen.form.close() }}
     </div>
 {% endif %}
--- a/MoinMoin/templates/forms.html	Tue Feb 12 01:11:36 2013 +0100
+++ b/MoinMoin/templates/forms.html	Tue Feb 12 10:28:18 2013 +0800
@@ -23,6 +23,10 @@
   <button type="submit">{{ text }}</button>
 {% endmacro %}
 
+{% macro render_submit(form) %}
+  {{ gen.input(type='submit', value=form.submit_label, class='button', **kwargs) }}
+{% endmacro %}
+
 {% macro render_textcha(gen, form) %}
     {% if form.textcha_question.value %}
     <dt class="moin-textcha">
@@ -52,7 +56,6 @@
       'small_natural': small_natural,
       'datetime': datetime,
       'search': search,
-      'submit': raw_input,
       'hidden': raw_input,
       'select': select,
       'multi_select': multi_select,
--- a/MoinMoin/templates/index.html	Tue Feb 12 01:11:36 2013 +0100
+++ b/MoinMoin/templates/index.html	Tue Feb 12 10:28:18 2013 +0800
@@ -51,7 +51,7 @@
                 </li>
                 {{ forms.render(form['contenttype']) }}
             </ul>
-            {{ forms.render(form['submit']) }}
+            {{ forms.render_submit(form) }}
             {{ gen.form.close() }}
         </div>
         </li>
--- a/MoinMoin/templates/login.html	Tue Feb 12 01:11:36 2013 +0100
+++ b/MoinMoin/templates/login.html	Tue Feb 12 10:28:18 2013 +0800
@@ -17,6 +17,7 @@
   {% endif %}
 </dl>
 {{ forms.render(form['submit']) }}
+{{ forms.render_submit(form) }}
 {{ gen.form.close() }}
 {% endif %}
 
@@ -29,6 +30,7 @@
   {{ forms.render(form['openid']) }}
 </dl>
 {{ forms.render(form['submit']) }}
+{{ forms.render_submit(form) }}
 {{ gen.form.close() }}
 {% endif %}
 
--- a/MoinMoin/templates/lookup.html	Tue Feb 12 01:11:36 2013 +0100
+++ b/MoinMoin/templates/lookup.html	Tue Feb 12 10:28:18 2013 +0800
@@ -23,7 +23,7 @@
                 {{ forms.render(lookup_form[e]) }}
             {% endfor %}
         </dl>
-        {{ gen.input(lookup_form['submit'], type='submit') }}
+        {{ forms.render_submit(lookup_form) }}
     {{ gen.form.close() }}
     {% else %}
     {% if not results %}
--- a/MoinMoin/templates/lostpass.html	Tue Feb 12 01:11:36 2013 +0100
+++ b/MoinMoin/templates/lostpass.html	Tue Feb 12 10:28:18 2013 +0800
@@ -11,7 +11,7 @@
     {{ forms.render(form['username']) }}
     {{ forms.render(form['email']) }}
   </dl>
-  {{ forms.render(form['submit']) }}
+  {{ forms.render_submit(form) }}
 {{ gen.form.close() }}
 </div>
 {% endblock %}
--- a/MoinMoin/templates/modify.html	Tue Feb 12 01:11:36 2013 +0100
+++ b/MoinMoin/templates/modify.html	Tue Feb 12 10:28:18 2013 +0800
@@ -39,11 +39,11 @@
     {{ forms.render_errors(form) }}
     {#
        Workaround:
-       For *Draw content, hide form['submit'] and form['comment'], since *Draw
+       For *Draw content, hide submit button and form['comment'], since *Draw
        POSTs originate from their respective applets.
     #}
     {% if not form['content_form'].is_draw %}
-        {{ forms.render(form['submit']) }}
+        {{ forms.render_submit(form) }}
         <dl>
             {{ forms.render_textcha(gen, form) }}
             {{ forms.render(form['comment']) }}
--- a/MoinMoin/templates/openid_register.html	Tue Feb 12 01:11:36 2013 +0100
+++ b/MoinMoin/templates/openid_register.html	Tue Feb 12 10:28:18 2013 +0800
@@ -17,7 +17,7 @@
     {{ forms.render(form['email']) }}
     {{ forms.render_textcha(gen, form) }}
   </dl>
-  {{ forms.render(form['submit']) }}
+  {{ forms.render_submit(form) }}
 {{ gen.form.close() }}
 </div>
 {% endblock %}
--- a/MoinMoin/templates/recoverpass.html	Tue Feb 12 01:11:36 2013 +0100
+++ b/MoinMoin/templates/recoverpass.html	Tue Feb 12 10:28:18 2013 +0800
@@ -11,6 +11,6 @@
     {{ forms.render(form['password1']) }}
     {{ forms.render(form['password2']) }}
   </dl>
-  {{ forms.render(form['submit']) }}
+  {{ forms.render_submit(form) }}
 {{ gen.form.close() }}
 {% endblock %}
--- a/MoinMoin/templates/register.html	Tue Feb 12 01:11:36 2013 +0100
+++ b/MoinMoin/templates/register.html	Tue Feb 12 10:28:18 2013 +0800
@@ -14,7 +14,7 @@
     {{ forms.render(form['openid']) }}
     {{ forms.render_textcha(gen, form) }}
   </dl>
-  {{ forms.render(form['submit']) }}
+  {{ forms.render_submit(form) }}
 {{ gen.form.close() }}
 </div>
 {% endblock %}
--- a/MoinMoin/templates/rename.html	Tue Feb 12 01:11:36 2013 +0100
+++ b/MoinMoin/templates/rename.html	Tue Feb 12 10:28:18 2013 +0800
@@ -13,7 +13,7 @@
     {{ forms.render(form['comment']) }}
     {{ forms.render_textcha(gen, form) }}
   </dl>
-  {{ forms.render(form['submit']) }}
+  {{ forms.render_submit(form) }}
 {{ gen.form.close() }}
 </div>
 {% endblock %}
--- a/MoinMoin/templates/revert.html	Tue Feb 12 01:11:36 2013 +0100
+++ b/MoinMoin/templates/revert.html	Tue Feb 12 10:28:18 2013 +0800
@@ -9,7 +9,7 @@
     {{ forms.render(form['comment']) }}
     {{ forms.render_textcha(gen, form) }}
   </dl>
-  {{ forms.render(form['submit']) }}
+  {{ forms.render_submit(form) }}
 {{ gen.form.close() }}
 </div>
 {% endblock %}
--- a/MoinMoin/templates/search.html	Tue Feb 12 01:11:36 2013 +0100
+++ b/MoinMoin/templates/search.html	Tue Feb 12 10:28:18 2013 +0800
@@ -25,7 +25,7 @@
     {{ gen.form.open(medium_search_form, id='moin-long-searchform', method='get', action=url_for('frontend.search', item_name=item_name)) }}
         <p>
         {{ forms.render(medium_search_form['q']) }}
-        {{ forms.render(medium_search_form['submit']) }}
+        {{ forms.render_submit(medium_search_form) }}
         </p>
         <p>
         {{ forms.render(medium_search_form['history']) }}
--- a/MoinMoin/templates/ticket.html	Tue Feb 12 01:11:36 2013 +0100
+++ b/MoinMoin/templates/ticket.html	Tue Feb 12 10:28:18 2013 +0800
@@ -49,7 +49,7 @@
         {{ forms.render(form['meta'][e]) }}
     {% endfor %}
     </dl>
-    {{ forms.render(form['submit']) }}
+    {{ forms.render_submit(form) }}
 
     <h2>Back references</h2>
     <dl>
--- a/MoinMoin/templates/utils.html	Tue Feb 12 01:11:36 2013 +0100
+++ b/MoinMoin/templates/utils.html	Tue Feb 12 10:28:18 2013 +0800
@@ -99,7 +99,7 @@
     {{ gen.form.open(form, id='moin-searchform', method='get', action=url_for('frontend.search')) }}
         <div>
             {{ forms.render(form['q']) }}
-            {{ gen.button(form['submit'], type='submit', id='moin-search-submit') }}
+            {{ forms.render_submit(form, id='moin-search-submit') }}
             {{ forms.render_errors(form) }}
         </div>
     {{ gen.form.close() }}