Commit cc52f021 authored by Francesca Sargent 's avatar Francesca Sargent
Browse files

Added a Recipe Step with wtforms.FormField

parent 9468c24a
from flask.ext.wtf import Form
import os
from wtforms import StringField, TextAreaField, BooleanField, SelectField,\
SubmitField, FormField
SubmitField, FormField, IntegerField, FloatField, FieldList
from wtforms.validators import Required, Length, Email, Regexp, Optional
from wtforms import ValidationError, validators
from flask.ext.pagedown.fields import PageDownField
......@@ -52,14 +52,19 @@ class EditProfileAdminForm(Form):
raise ValidationError('Username already in use.')
class RecipeStepForm(Form):
recipe_step_id = StringField('Step Number', validators=[Required(), Length(0,2)])
recipe_step_text = TextAreaField(validators=[Required()])
step_id = IntegerField('Step Number', [validators.NumberRange(min=0, max=10)])
step_text = TextAreaField()
def __init__(self, *args, **kwargs):
kwargs['csrf_enabled'] = False
super(RecipeStepForm, self).__init__(*args, **kwargs)
class RecipeForm(Form):
name = StringField('Recipe Name', validators=[Required(), Length(0, 64)])
description = PageDownField('Recipe Description')
# recipestep = FormField(RecipeStepForm)
steps = FormField(RecipeStepForm)
cuisines = StringField('Cuisine', validators=[Required()])
methods = StringField('Method', validators=[Required()])
submit = SubmitField('Submit')
......
......@@ -319,6 +319,7 @@ def editrecipe(id):
recipe.name = form.name.data
recipe.description = form.description.data
recipe.steps = [RecipeSteps(step_id = form.steps.step_id.data, step_text = form.steps.step_text.data)]
db.session.add(recipe)
flash('The recipe has been updated.')
return redirect(url_for('.recipe', id=recipe.id))
......
......@@ -319,9 +319,9 @@ db.event.listen(Recipe.body, 'set', Recipe.on_changed_body)
class RecipeSteps(db.Model):
__tablename__ = 'recipesteps'
id = db.Column(db.Integer, primary_key=True)
recipe_id = db.Column(db.Integer, db.ForeignKey('recipes.id'))
recipe_step_id = db.Column(db.Integer)
recipe_step_text = db.Column(db.Text)
recipe_name = db.Column(db.Integer, db.ForeignKey('recipes.id'))
step_id = db.Column(db.Integer)
step_text = db.Column(db.Text)
class Cuisine(db.Model):
__tablename__ = 'cuisines'
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment