<s> from wtforms import TextField , TextAreaField , SelectField , BooleanField <EOL> from wtforms . validators import DataRequired <EOL> from flask . ext . babel import lazy_gettext as _ <EOL> from . _base import BaseForm <EOL> from . . models import Node <EOL> class NodeForm ( BaseForm ) : <EOL> title = TextField ( <EOL> _ ( '<STR_LIT>' ) , validators = [ DataRequired ( ) ] , <EOL> description = _ ( '<STR_LIT>' ) <EOL> ) <EOL> urlname = TextField ( <EOL> _ ( '<STR_LIT>' ) , validators = [ DataRequired ( ) ] , <EOL> description = _ ( '<STR_LIT>' ) <EOL> ) <EOL> description = TextAreaField ( _ ( '<STR_LIT>' ) ) <EOL> role = SelectField ( <EOL> _ ( '<STR_LIT>' ) , <EOL> description = _ ( '<STR_LIT>' ) , <EOL> choices = [ <EOL> ( '<STR_LIT:user>' , _ ( '<STR_LIT>' ) ) , <EOL> ( '<STR_LIT>' , _ ( '<STR_LIT>' ) ) , <EOL> ( '<STR_LIT>' , _ ( '<STR_LIT>' ) ) <EOL> ] , <EOL> default = '<STR_LIT:user>' , <EOL> ) <EOL> on_home = BooleanField ( _ ( '<STR_LIT>' ) , default = True ) <EOL> def validate_urlname ( self , field ) : <EOL> if self . _obj and self . _obj . urlname == field . data : <EOL> return <EOL> if Node . query . filter_by ( urlname = field . data ) . count ( ) : <EOL> raise ValueError ( _ ( '<STR_LIT>' ) ) <EOL> def save ( self ) : <EOL> node = Node ( ** self . data ) <EOL> node . save ( ) <EOL> return node </s>
