Commits

Anonymous committed 79c7849

use submit fields

Comments (0)

Files changed (16)

newsmeme/forms.py

 import re
 
 from flaskext.wtf import Form, TextField, PasswordField, HiddenField, \
-    BooleanField, RadioField, RecaptchaField, TextAreaField, ValidationError, \
-    required, email, equal_to, url, optional, regexp
+    BooleanField, RadioField, RecaptchaField, TextAreaField, SubmitField, \
+    ValidationError, required, email, equal_to, url, optional, regexp
 
 from flaskext.babel import gettext, lazy_gettext as _
 
 
 class ContactForm(Form):
 
-    name = TextField(_("Your name"), 
-        validators=[
-            required(message=_('Your name is required'))
-        ])
+    name = TextField(_("Your name"), validators=[
+        required(message=_('Your name is required'))
+    ])
 
-    email = TextField(_("Your email address"),
-        validators=[
-            required(message=_("Email address required")),
-            email(message=_("A valid email address is required"))
-        ])
+    email = TextField(_("Your email address"), validators=[
+        required(message=_("Email address required")),
+        email(message=_("A valid email address is required"))
+    ])
 
-    subject = TextField(_("Subject"),
-        validators=[
-            required(message=_("Subject required"))
-        ])
+    subject = TextField(_("Subject"), validators=[
+        required(message=_("Subject required"))
+    ])
 
-    message = TextAreaField(_("Message"),
-        validators=[
-            required(message=_("Message required"))
-        ])
+    message = TextAreaField(_("Message"), validators=[
+        required(message=_("Message required"))
+    ])
 
+    submit = SubmitField(_("Send"))
 
 class MessageForm(Form):
 
-    subject = TextField(_("Subject"),
-        validators=[
-            required(message=_("Subject required"))
-        ])
+    subject = TextField(_("Subject"), validators=[
+        required(message=_("Subject required"))
+    ])
 
-    message = TextAreaField(_("Message"),
-        validators=[
-            required(message=_("Message required"))
-        ])
+    message = TextAreaField(_("Message"), validators=[
+        required(message=_("Message required"))
+    ])
+
+    submit = SubmitField(_("Send"))
 
 class LoginForm(Form):
 
     
     remember = BooleanField(_("Remember me"))
     
-    login = TextField(_("Username or email address"), 
-        validators=[
-            required(message=_("You must provide an email or username"))
-        ])
-    
+    login = TextField(_("Username or email address"), validators=[
+        required(message=_("You must provide an email or username"))
+    ])
+
     password = PasswordField(_("Password"))
 
+    submit = SubmitField(_("Login"))
 
 class SignupForm(Form):
 
     next = HiddenField()
 
-    username = TextField(_("Username"), 
-        validators=[
-            required(message=_("Username required")),
-            is_username
-        ])
-    
-    password = PasswordField(_("Password"), 
-        validators=[
-            required(message=_("Password required"))
-        ])
-    
-    password_again = PasswordField(_("Password again"), 
-        validators=[
-            equal_to("password", message=_("Passwords don't match"))
-        ])
-    
-    email = TextField(_("Email address"), 
-        validators=[
-            required(message=_("Email address required")), 
-            email(message=_("A valid email address is required"))
-        ])
-    
+    username = TextField(_("Username"), validators=[
+        required(message=_("Username required")),
+        is_username
+    ])
+
+    password = PasswordField(_("Password"), validators=[
+        required(message=_("Password required"))
+    ])
+
+    password_again = PasswordField(_("Password again"), validators=[
+        equal_to("password", message=_("Passwords don't match"))
+    ])
+
+    email = TextField(_("Email address"), validators=[
+        required(message=_("Email address required")), 
+        email(message=_("A valid email address is required"))
+    ])
+
     recaptcha = RecaptchaField(_("Copy the words appearing below"))
 
+    submit = SubmitField(_("Signup"))
+
     def validate_username(self, field):
         user = User.query.filter(User.username.like(field.data)).first()
         if user:
 
 class EditAccountForm(Form):
 
-    username = TextField("Username", 
-        validators=[
-            required(_("Username is required")),
-            is_username
-        ])
-    
-    email = TextField(_("Your email address"),
-        validators=[
-            required(message=_("Email address required")),
-            email(message=_("A valid email address is required"))
-        ])
+    username = TextField("Username", validators=[
+        required(_("Username is required")),
+        is_username
+    ])
+
+    email = TextField(_("Your email address"), validators=[
+        required(message=_("Email address required")),
+        email(message=_("A valid email address is required"))
+    ])
 
     receive_email = BooleanField(_("Receive private emails from friends"))
     
     email_alerts = BooleanField(_("Receive an email when somebody replies "
                                   "to your post or comment"))
 
+
+    submit = SubmitField(_("Save"))
+
     def __init__(self, user, *args, **kwargs):
         self.user = user
         kwargs['obj'] = self.user
 
 class PostForm(Form):
 
-    title = TextField(_("Title of your post"),
-        validators=[
-            required(message=_("Title required"))
-        ])
+    title = TextField(_("Title of your post"), validators=[
+        required(message=_("Title required"))
+    ])
 
-    link = TextField(_("Link"),
-        validators=[
-            optional(),
-            url(message=_("This is not a valid URL"))
-        ])
+    link = TextField(_("Link"), validators=[
+        optional(),
+        url(message=_("This is not a valid URL"))
+    ])
 
     description = TextAreaField(_("Description"))
 
                                  (Post.FRIENDS, _("Friends only")),
                                  (Post.PRIVATE, _("Just myself"))))
 
+    submit = SubmitField(_("Save"))
+
     def __init__(self, *args, **kwargs):
         self.post = kwargs.get('obj', None)
         super(PostForm, self).__init__(*args, **kwargs)
 
 class CommentForm(Form):
 
-    comment = TextAreaField(
-        validators=[
-            required(message=_("Comment is required"))
-        ])
+    comment = TextAreaField(validators=[
+        required(message=_("Comment is required"))
+    ])
+
+    submit = SubmitField(_("Save"))
+    cancel = SubmitField(_("Cancel"))
 
 class OpenIdSignupForm(Form):
     
     next = HiddenField()
 
-    username = TextField(_("Username"), 
-        validators=[required(_("Username required")),
-                    is_username])
+    username = TextField(_("Username"), validators=[
+        required(_("Username required")),
+        is_username
+    ])
     
-    email = TextField(_("Email address"), 
-        validators=[
-            required(message=_("Email address required")), 
-            email(message=_("Valid email address required"))
-        ])
+    email = TextField(_("Email address"), validators=[
+        required(message=_("Email address required")), 
+        email(message=_("Valid email address required"))
+    ])
     
     next = HiddenField()
 
     recaptcha = RecaptchaField(_("Copy the words appearing below"))
 
+    submit = SubmitField(_("Signup"))
+
     def validate_username(self, field):
         user = User.query.filter(User.username.like(field.data)).first()
         if user:
 
     next = HiddenField()
 
-    openid = TextField("OpenID",
-        validators=[
-            required(_("OpenID is required")), 
-            url(_("OpenID must be a valid URL"))
-        ])
+    openid = TextField("OpenID", validators=[
+        required(_("OpenID is required")), 
+        url(_("OpenID must be a valid URL"))
+    ])
 
+    submit = SubmitField(_("Login"))
+    
 class RecoverPasswordForm(Form):
 
-    email = TextField("Your email address",
-        validators=[
-            email(message=_("A valid email address is required"))
-        ])
+    email = TextField("Your email address", validators=[
+        email(message=_("A valid email address is required"))
+    ])
 
+    submit = SubmitField(_("Find password"))
 
 class ChangePasswordForm(Form):
 
     activation_key = HiddenField()
 
-    password = PasswordField("Password", 
-        validators=[
-            required(message=_("Password is required"))
-        ])
+    password = PasswordField("Password", validators=[
+        required(message=_("Password is required"))
+    ])
     
-    password_again = PasswordField(_("Password again"), 
-        validators=[
-            equal_to("password", message=_("Passwords don't match"))
-        ])
+    password_again = PasswordField(_("Password again"), validators=[
+        equal_to("password", message=_("Passwords don't match"))
+    ])
+
+    submit = SubmitField(_("Save"))
 
 class DeleteAccountForm(Form):
     
     recaptcha = RecaptchaField(_("Copy the words appearing below"))
 
+    submit = SubmitField(_("Delete"))
+
 class CommentAbuseForm(Form):
 
-    complaint = TextAreaField("Complaint", 
-        validators=[
-            required(message=_("You must enter the details of the complaint"))
-        ])
+    complaint = TextAreaField("Complaint", validators=[
+        required(message=_("You must enter the details of the complaint"))
+    ])
+
+
+    submit = SubmitField(_("Send"))

newsmeme/templates/account/change_password.html

             {{ form.password_again }}
             </li>
         <li>
-        <input type="submit" value="{{ _('save') }}">
+            {{ form.submit }}
         </li>
     </ul>
 </form>

newsmeme/templates/account/delete_account.html

             {{ form.recaptcha.label }} <br> {{ form.recaptcha }}
         </li>
         <li>
-        <input type="submit" value="{{ _('delete') }}">
+        {{ form.submit }}
             </li>
     </ul>
 </form>

newsmeme/templates/account/edit_account.html

             {{ form.email_alerts.label(class_="checkbox") }} {{ form.email_alerts }}
         </li>
         <li>
-        <input type="submit" value="{{ _('save') }}">
+            {{ form.submit }}
             </li>
     </ul>
 </form>

newsmeme/templates/account/login.html

             {{ form.remember }}
         </li>
         <li>
-        <input type="submit" value="{{ _('Login') }}">
+            {{ form.submit }}
             </li>
     </ul>
 </form>

newsmeme/templates/account/recover_password.html

         {{ form.email }}
         </li>
         <li>
-        <input type="submit" value="{{ _('find my account') }}">
+         {{ form.submit }}
         </li>
     </ul>
 </form>

newsmeme/templates/account/signup.html

             {{ form.recaptcha.label }} <br>{{ form.recaptcha }}
         </li>
         <li>
-        <input type="submit" value="{{ _('Sign up') }}">
+            {{ form.submit }}
             </li>
     </ul>
 </form>

newsmeme/templates/comment/edit_comment.html

             {{ form.comment }}
         </li>
         <li>
-        <input type="submit" value="{{ _('add comment') }}">
+        {{ form.submit }}
             </li>
         <li>
             {{ markdown_link() }}

newsmeme/templates/comment/report_abuse.html

             {{ form.complaint }}
         </li>
         <li>
-        <input type="submit" value="{{ _('report') }}">
+        {{ form.submit }}
             </li>
  
     </ul>

newsmeme/templates/contact.html

         {{ form.message }}
         </li>
         <li>
-        <input type="submit" value="{{ _('Send') }}">
+        {{ form.submit }}
         </li>
     </ul>
 </form>

newsmeme/templates/macros/_post.html

             {{ comment_form.comment }}
             </li>
         <li>
-            <input type="submit" value="add comment">
+        {{ comment_form.submit(value=_("Add comment")) }}
             </li>
             <li>
             </li>
             {{ form.comment }} 
             </li>
             <li>
-            <input type="submit" value="save">
-            <input type="button" value="cancel" onclick="$('#edit-comment-form-{{ comment.id }}').toggle(); return false;">
+            {{ form.submit }}
+            {{ form.cancel(onclick="$('#edit-comment-form-%d').toggle(); return false;" % comment.id) }}
             </li>
             {{ markdown_link() }}}
  

newsmeme/templates/openid/login.html

             {{ form.openid(size=30, class_="openid") }}
         </li>
         <li>
-        <input type="submit" value="{{ _('Login') }}">
+            {{ form.submit }}
         </li>
     </ul>
 </form>

newsmeme/templates/openid/signup.html

             {{ form.recaptcha.label }} <br> {{ form.recaptcha }}
         </li>
         <li>
-        <input type="submit" value="{{ _('Sign up') }}">
+        {{ form.submit }}
             </li>
+            
     </ul>
 </form>
 

newsmeme/templates/post/add_comment.html

             {{ form.comment }}
         </li>
         <li>
-        <input type="submit" value="{{ _('add comment') }}">
+        {{ form.submit }}
             </li>
         <li>
             {{ markdown_link() }}

newsmeme/templates/post/edit_post.html

             {% endfor %}
         </li>
         <li>
-        <input type="submit" value="{{ _('Save') }}">
+        {{ form.submit }}
         </li>
         <li>
             {{ markdown_link() }}

newsmeme/templates/user/send_message.html

         {{ form.message }}
         </li>
         <li>
-        <input type="submit" value="{{ _('Send') }}">
+        {{ form.submit }}
     </li>
     </ul> 
 </form>