Skip to content

Commit

Permalink
Deprecated WTF - corrections
Browse files Browse the repository at this point in the history
  • Loading branch information
Hassan Arouss committed Jul 1, 2015
1 parent 86180b5 commit 4b21ebb
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 45 deletions.
41 changes: 21 additions & 20 deletions web/challenges.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,49 +8,50 @@

from ast import literal_eval
from flask import request, render_template, redirect, url_for, flash
from flask.ext import wtf, login
from flask.ext import login
from wtforms import Form, HiddenField, validators, TextField, TextAreaField, SelectField
from web.database import Challenge, Category, Tag
from web import webapp
from web import webdb as db


class ManageChallengeForm(wtf.Form):
id = wtf.HiddenField('', [
wtf.validators.Required()
class ManageChallengeForm(Form):
id = HiddenField('', [
validators.Required()
])
title = wtf.TextField('Title', [
wtf.validators.Required(),
wtf.validators.Length(max=64)
title = TextField('Title', [
validators.Required(),
validators.Length(max=64)
])
description = wtf.TextAreaField('Description')
description = TextAreaField('Description')
# TODO:
# -field must be a number
# -number must be a valid level value
level = wtf.SelectField('Level', [
wtf.validators.Required(),
wtf.validators.Length(max=1)
level = SelectField('Level', [
validators.Required(),
validators.Length(max=1)
],
choices=[(i, i) for i in range(1, 6)],
)
# TODO:
# -field must be a number
# -number must be a valid challenge id
requirement = wtf.TextField('Requirement')
flag = wtf.TextField('Flag', [
wtf.validators.Required(),
wtf.validators.Length(max=256)
requirement = TextField('Requirement')
flag = TextField('Flag', [
validators.Required(),
validators.Length(max=256)
])
url = wtf.TextField('URL', [
wtf.validators.Required(),
wtf.validators.Length(max=256)
url = TextField('URL', [
validators.Required(),
validators.Length(max=256)
])
# TODO: enable multiple selection
categories = wtf.SelectField('Categories',
categories = SelectField('Categories',
choices=[(category.id, category.name) \
for category in db.session.query(Category).all()]
)
# TODO: enable multiple selection
tags = wtf.SelectField('Tags',
tags = SelectField('Tags',
choices=[(tag.id, tag.label) \
for tag in db.session.query(Tag).all()]
)
Expand Down
31 changes: 16 additions & 15 deletions web/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,21 @@
import hashlib
import time
from flask import request, render_template, redirect, url_for, flash
from flask.ext import wtf, login
from wtforms import Form, TextField, validators, PasswordField
from flask.ext import login
from web import webapp
from web import webdb as db
from database import User


class LoginForm(wtf.Form):
username = wtf.TextField('Username', [
wtf.validators.Required(),
wtf.validators.Length(max=64)
class LoginForm(Form):
username = TextField('Username', [
validators.Required(),
validators.Length(max=64)
])
password = wtf.PasswordField('Password', [
wtf.validators.Required(),
wtf.validators.Length(max=256)
password = PasswordField('Password', [
validators.Required(),
validators.Length(max=256)
])

def validate(self):
Expand All @@ -44,14 +45,14 @@ def get_user(self):
return db.session.query(User).filter_by(username=self.username.data).first()


class RegistrationForm(wtf.Form):
username = wtf.TextField('Username', [
wtf.validators.Required(),
wtf.validators.Length(max=64)
class RegistrationForm(Form):
username = TextField('Username', [
validators.Required(),
validators.Length(max=64)
])
password = wtf.PasswordField('Password', [
wtf.validators.Required(),
wtf.validators.Length(max=256)
password = PasswordField('Password', [
validators.Required(),
validators.Length(max=256)
])

def validate(self):
Expand Down
11 changes: 6 additions & 5 deletions web/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,20 @@

from sets import Set
from flask import request, render_template
from flask.ext import wtf, login
from flask.ext import login
from wtforms import Form, TextField, SelectField
from web.database import Category, Challenge
from web import webapp
from web import webdb as db


class SearchForm(wtf.Form):
challenges = wtf.TextField('Challenges')
categories = wtf.SelectField('Categories',
class SearchForm(Form):
challenges = TextField('Challenges')
categories = SelectField('Categories',
choices=[(category.id, category.name) \
for category in db.session.query(Category).all()]
)
tags = wtf.TextField('Tags')
tags = TextField('Tags')

def validate(self):
return True
Expand Down
11 changes: 6 additions & 5 deletions web/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@
"""

from flask import request, render_template, url_for, redirect, flash
from flask.ext import wtf, login
from flask.ext import login
from wtforms import Form, PasswordField, validators
from web import webapp
from web import webdb as db
from database import User, Challenge


class SettingsForm(wtf.Form):
new_password = wtf.PasswordField('New password', [
wtf.validators.Required(),
wtf.validators.Length(max=256)
class SettingsForm(Form):
new_password = PasswordField('New password', [
validators.Required(),
validators.Length(max=256)
])

def validate(self):
Expand Down

0 comments on commit 4b21ebb

Please sign in to comment.