Commits

danjac  committed 3182d3c

starting forms tidy

  • Participants
  • Parent commits de3f6c5

Comments (0)

Files changed (2)

File newsmeme/forms.py

-# -*- coding: utf-8 -*-
-"""
-    forms.py
-    ~~~~~~~~
-
-    Description of the module goes here...
-
-    :copyright: (c) 2010 by Dan Jacob.
-    :license: BSD, see LICENSE for more details.
-"""
-import re
-
-from flaskext.wtf import Form, TextField, PasswordField, HiddenField, \
-    BooleanField, RadioField, RecaptchaField, TextAreaField, SubmitField, \
-    ValidationError, required, email, equal_to, url, optional, regexp
-
-from flaskext.babel import gettext, lazy_gettext as _
-
-from newsmeme.models import User, Post
-from newsmeme.extensions import db
-
-USERNAME_RE = r'^[\w.+-]+$'
-
-is_username = regexp(USERNAME_RE, 
-                     message=_("You can only use letters, numbers or dashes"))
-
-class ContactForm(Form):
-
-    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"))])
-
-    subject = TextField(_("Subject"), validators=[
-        required(message=_("Subject required"))])
-
-    message = TextAreaField(_("Message"), validators=[
-        required(message=_("Message required"))])
-
-    submit = SubmitField(_("Send"))
-
-class MessageForm(Form):
-
-    subject = TextField(_("Subject"), validators=[
-        required(message=_("Subject required"))])
-
-    message = TextAreaField(_("Message"), validators=[
-        required(message=_("Message required"))])
-
-    submit = SubmitField(_("Send"))
-
-class LoginForm(Form):
-
-    next = HiddenField()
-    
-    remember = BooleanField(_("Remember me"))
-    
-    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"))])
-
-    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:
-            raise ValidationError, gettext("This username is taken")
-
-    def validate_email(self, field):
-        user = User.query.filter(User.email.like(field.data)).first()
-        if user:
-            raise ValidationError, gettext("This email is taken")
-
-
-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"))])
-
-    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
-        super(EditAccountForm, self).__init__(*args, **kwargs)
-        
-    def validate_username(self, field):
-        user = User.query.filter(db.and_(
-                User.username.like(field.data),
-                db.not_(User.id==self.user.id))).first()
-
-        if user:
-            raise ValidationError, gettext("This username is taken")
-
-    def validate_email(self, field):
-        user = User.query.filter(db.and_(
-                User.email.like(field.data),
-                db.not_(User.id==self.user.id))).first()
-        if user:
-            raise ValidationError, gettext("This email is taken")
-
-
-class PostForm(Form):
-
-    title = TextField(_("Title of your post"), validators=[
-        required(message=_("Title required"))])
-
-    link = TextField(_("Link"), validators=[
-        optional(),
-        url(message=_("This is not a valid URL"))])
-
-    description = TextAreaField(_("Description"))
-
-    tags = TextField(_("Tags"))
-
-    access = RadioField(_("Who can see this post ?"), 
-                        default=Post.PUBLIC, 
-                        coerce=int,
-                        choices=((Post.PUBLIC, _("Everyone")),
-                                 (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)
-
-    def validate_link(self, field):
-        posts = Post.query.public().filter_by(link=field.data)
-        if self.post:
-            posts = posts.filter(db.not_(Post.id==self.post.id))
-        if posts.count():
-            raise ValidationError, gettext("This link has already been posted")
-
-class CommentForm(Form):
-
-    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])
-    
-    email = TextField(_("Email address"), validators=[
-        required(message=_("Email address required")), 
-        email(message=_("Valid email address 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:
-            raise ValidationError, gettext("This username is taken")
-
-    def validate_email(self, field):
-        user = User.query.filter(User.email.like(field.data)).first()
-        if user:
-            raise ValidationError, gettext("This email is taken")
-
-class OpenIdLoginForm(Form):
-
-    next = HiddenField()
-
-    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"))])
-
-    submit = SubmitField(_("Find password"))
-
-class ChangePasswordForm(Form):
-
-    activation_key = HiddenField()
-
-    password = PasswordField("Password", validators=[
-        required(message=_("Password is required"))])
-    
-    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"))])
-
-
-    submit = SubmitField(_("Send"))

File newsmeme/forms/__init__.py

+# -*- coding: utf-8 -*-
+"""
+    forms.py
+    ~~~~~~~~
+
+    Description of the module goes here...
+
+    :copyright: (c) 2010 by Dan Jacob.
+    :license: BSD, see LICENSE for more details.
+"""
+import re
+
+from flaskext.wtf import Form, TextField, PasswordField, HiddenField, \
+    BooleanField, RadioField, RecaptchaField, TextAreaField, SubmitField, \
+    ValidationError, required, email, equal_to, url, optional, regexp
+
+from flaskext.babel import gettext, lazy_gettext as _
+
+from newsmeme.models import User, Post
+from newsmeme.extensions import db
+
+USERNAME_RE = r'^[\w.+-]+$'
+
+is_username = regexp(USERNAME_RE, 
+                     message=_("You can only use letters, numbers or dashes"))
+
+class ContactForm(Form):
+
+    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"))])
+
+    subject = TextField(_("Subject"), validators=[
+                        required(message=_("Subject required"))])
+
+    message = TextAreaField(_("Message"), validators=[
+                            required(message=_("Message required"))])
+
+    submit = SubmitField(_("Send"))
+
+class MessageForm(Form):
+
+    subject = TextField(_("Subject"), validators=[
+                        required(message=_("Subject required"))])
+
+    message = TextAreaField(_("Message"), validators=[
+                            required(message=_("Message required"))])
+
+    submit = SubmitField(_("Send"))
+
+class LoginForm(Form):
+
+    next = HiddenField()
+    
+    remember = BooleanField(_("Remember me"))
+    
+    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"))])
+
+    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:
+            raise ValidationError, gettext("This username is taken")
+
+    def validate_email(self, field):
+        user = User.query.filter(User.email.like(field.data)).first()
+        if user:
+            raise ValidationError, gettext("This email is taken")
+
+
+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"))])
+
+    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
+        super(EditAccountForm, self).__init__(*args, **kwargs)
+        
+    def validate_username(self, field):
+        user = User.query.filter(db.and_(
+                User.username.like(field.data),
+                db.not_(User.id==self.user.id))).first()
+
+        if user:
+            raise ValidationError, gettext("This username is taken")
+
+    def validate_email(self, field):
+        user = User.query.filter(db.and_(
+                User.email.like(field.data),
+                db.not_(User.id==self.user.id))).first()
+        if user:
+            raise ValidationError, gettext("This email is taken")
+
+
+class PostForm(Form):
+
+    title = TextField(_("Title of your post"), validators=[
+                      required(message=_("Title required"))])
+
+    link = TextField(_("Link"), validators=[
+                     optional(),
+                     url(message=_("This is not a valid URL"))])
+
+    description = TextAreaField(_("Description"))
+
+    tags = TextField(_("Tags"))
+
+    access = RadioField(_("Who can see this post ?"), 
+                        default=Post.PUBLIC, 
+                        coerce=int,
+                        choices=((Post.PUBLIC, _("Everyone")),
+                                 (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)
+
+    def validate_link(self, field):
+        posts = Post.query.public().filter_by(link=field.data)
+        if self.post:
+            posts = posts.filter(db.not_(Post.id==self.post.id))
+        if posts.count():
+            raise ValidationError, gettext("This link has already been posted")
+
+class CommentForm(Form):
+
+    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])
+    
+    email = TextField(_("Email address"), validators=[
+                      required(message=_("Email address required")), 
+                      email(message=_("Valid email address 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:
+            raise ValidationError, gettext("This username is taken")
+
+    def validate_email(self, field):
+        user = User.query.filter(User.email.like(field.data)).first()
+        if user:
+            raise ValidationError, gettext("This email is taken")
+
+class OpenIdLoginForm(Form):
+
+    next = HiddenField()
+
+    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"))])
+
+    submit = SubmitField(_("Find password"))
+
+class ChangePasswordForm(Form):
+
+    activation_key = HiddenField()
+
+    password = PasswordField("Password", validators=[
+                             required(message=_("Password is required"))])
+    
+    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"))])
+
+
+    submit = SubmitField(_("Send"))