Source

n0v4pl4n3t / app / forms.py

Full commit
from flaskext import wtf
from flaskext.wtf import validators
from wtforms.fields import Field
from wtforms.widgets import TextInput

class UpdateForm(wtf.Form):
    message = wtf.TextAreaField('message', validators=[validators.Required()])

class TagListField(Field):
    widget = TextInput()

    def _value(self):
        if self.data:
            return u', '.join(self.data)
        else:
            return u''

    def process_formdata(self, valuelist):
        if valuelist:
            data = [x.strip() for x in valuelist[0].split(',')]
            self.data = []
            for item in data:
                if item:
                    self.data.append(item)
        else:
            self.data = []

class LinkForm(wtf.Form):
    link = wtf.TextField('link', validators=[validators.Required()])
    tags = TagListField('tags')

class ArticleForm(wtf.Form):
    content = wtf.TextAreaField('content', validators=[validators.Required()])
    title = wtf.TextField('title', validators=[validators.Required()])
    tags = TagListField('tags')