First Form Added

debrice 2012-02-04 11:14:47 -08:00
parent 82ecef8433
commit 1de9c3493e

@ -130,8 +130,8 @@ The `models.py`
name = db.Column(db.String(50), unique=True)
email = db.Column(db.String(120), unique=True)
password = db.Column(db.String(20))
role = db.Column(db.Integer, default=USER.USER)
status = db.Column(db.Integer, default=USER.NEW)
role = db.Column(db.SmallInteger, default=USER.USER)
status = db.Column(db.SmallInteger, default=USER.NEW)
def __init__(self, name=None, email=None, password=None):
self.name = name
@ -173,6 +173,26 @@ First about the constants file, I like to have my constants their own file and
### First form
Now that we've done our object model, time to build the form that goes with it. We'll start with a registration form. The form will request the user's name, email and password. We'll use validators to ensure the user submitted correct values. Finally, a Repcaptcha field (provided by flask) will avoid machine registration. Just in case you plan on having Term of Service, I added a BooleanField called accept_tos. Since this field is required, the user will have to check the checkbox generated by this field on the box.
from flaskext.wtf import Form, TextField, PasswordField, BooleanField, RecaptchaField
from flaskext.wtf import Required, Email, EqualTo
class RegisterForm(Form):
name = TextField('NickName', [Required()])
email = TextField('Email address', [Required(), Email()])
password = PasswordField('Password', [
Required(),
EqualTo('confirm', message='Passwords must match')
])
confirm = PasswordField('Repeat Password')
accept_tos = BooleanField('I accept the TOS', [Required()])
repcaptcha = RecaptchaField()
The first parameters for the field is the label we'll want to display for the field. For example the name field will be labelled as NickName on the form.
Form more details of what can be done with WTF check [http://wtforms.simplecodes.com/docs/dev/]
### First view