Commits

xiaq committed 490c13d

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.

  • Participants
  • Parent commits ff71ef2

Comments (0)

Files changed (22)

File MoinMoin/apps/frontend/views.py

 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
     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'])
     # 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
 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'))
 
 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'])
     # 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)
 
     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()]
 
 
     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()]
 
         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()]
 
     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()]
 
         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):
     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'])
                                    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'
             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,
                     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

File MoinMoin/forms.py

 
 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)

File MoinMoin/items/__init__.py

 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,
 
 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):

File MoinMoin/items/ticket.py

 
 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
     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)
             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())

File MoinMoin/search/__init__.py

 """
 
 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
 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()]

File MoinMoin/templates/blog/utils.html

     {{ 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"

File MoinMoin/templates/delete.html

     {{ forms.render(form['comment']) }}
     {{ forms.render_textcha(gen, form) }}
   </dl>
-  {{ forms.render(form['submit']) }}
+  {{ forms.render_submit(form) }}
 {{ gen.form.close() }}
 </div>
 {% endblock %}

File MoinMoin/templates/destroy.html

         {{ forms.render(form['comment']) }}
         {{ forms.render_textcha(gen, form) }}
       </dl>
-      {{ forms.render(form['submit']) }}
+      {{ forms.render_submit(form) }}
     {{ gen.form.close() }}
     </div>
 {% else %}
         {{ forms.render(form['comment']) }}
         {{ forms.render_textcha(gen, form) }}
       </dl>
-      {{ forms.render(form['submit']) }}
+      {{ forms.render_submit(form) }}
     {{ gen.form.close() }}
     </div>
 {% endif %}

File MoinMoin/templates/forms.html

   <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">
       'small_natural': small_natural,
       'datetime': datetime,
       'search': search,
-      'submit': raw_input,
       'hidden': raw_input,
       'select': select,
       'multi_select': multi_select,

File MoinMoin/templates/index.html

                 </li>
                 {{ forms.render(form['contenttype']) }}
             </ul>
-            {{ forms.render(form['submit']) }}
+            {{ forms.render_submit(form) }}
             {{ gen.form.close() }}
         </div>
         </li>

File MoinMoin/templates/login.html

   {% endif %}
 </dl>
 {{ forms.render(form['submit']) }}
+{{ forms.render_submit(form) }}
 {{ gen.form.close() }}
 {% endif %}
 
   {{ forms.render(form['openid']) }}
 </dl>
 {{ forms.render(form['submit']) }}
+{{ forms.render_submit(form) }}
 {{ gen.form.close() }}
 {% endif %}
 

File MoinMoin/templates/lookup.html

                 {{ 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 %}

File MoinMoin/templates/lostpass.html

     {{ forms.render(form['username']) }}
     {{ forms.render(form['email']) }}
   </dl>
-  {{ forms.render(form['submit']) }}
+  {{ forms.render_submit(form) }}
 {{ gen.form.close() }}
 </div>
 {% endblock %}

File MoinMoin/templates/modify.html

     {{ 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']) }}

File MoinMoin/templates/openid_register.html

     {{ forms.render(form['email']) }}
     {{ forms.render_textcha(gen, form) }}
   </dl>
-  {{ forms.render(form['submit']) }}
+  {{ forms.render_submit(form) }}
 {{ gen.form.close() }}
 </div>
 {% endblock %}

File MoinMoin/templates/recoverpass.html

     {{ forms.render(form['password1']) }}
     {{ forms.render(form['password2']) }}
   </dl>
-  {{ forms.render(form['submit']) }}
+  {{ forms.render_submit(form) }}
 {{ gen.form.close() }}
 {% endblock %}

File MoinMoin/templates/register.html

     {{ forms.render(form['openid']) }}
     {{ forms.render_textcha(gen, form) }}
   </dl>
-  {{ forms.render(form['submit']) }}
+  {{ forms.render_submit(form) }}
 {{ gen.form.close() }}
 </div>
 {% endblock %}

File MoinMoin/templates/rename.html

     {{ forms.render(form['comment']) }}
     {{ forms.render_textcha(gen, form) }}
   </dl>
-  {{ forms.render(form['submit']) }}
+  {{ forms.render_submit(form) }}
 {{ gen.form.close() }}
 </div>
 {% endblock %}

File MoinMoin/templates/revert.html

     {{ forms.render(form['comment']) }}
     {{ forms.render_textcha(gen, form) }}
   </dl>
-  {{ forms.render(form['submit']) }}
+  {{ forms.render_submit(form) }}
 {{ gen.form.close() }}
 </div>
 {% endblock %}

File MoinMoin/templates/search.html

     {{ 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']) }}

File MoinMoin/templates/ticket.html

         {{ forms.render(form['meta'][e]) }}
     {% endfor %}
     </dl>
-    {{ forms.render(form['submit']) }}
+    {{ forms.render_submit(form) }}
 
     <h2>Back references</h2>
     <dl>

File MoinMoin/templates/utils.html

     {{ 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() }}