Commit 5c086901 authored by Francesca Sargent 's avatar Francesca Sargent
Browse files

Fixed null ingredient problem

parent cc30dbb4
from flask.ext.wtf import Form
import os
import re
import wtforms
from wtforms import StringField, TextAreaField, BooleanField, SelectField,\
SubmitField, FormField, IntegerField, FloatField, FieldList, Field
......@@ -10,21 +11,37 @@ from .. import db
from ..models import Role, User, Cuisine, Recipe, RecipeSteps, Method, Ingredient
def chomp(s):
return s[:-1] if s.endswith(',') else s
class NameForm(Form):
name = StringField('What is your name?', validators=[Required()])
submit = SubmitField('Submit')
class SplitStringField(StringField):
def process_formdata(self, valuelist):
if valuelist:
if len(valuelist) == 1 and valuelist[0] == '':
self.data = []
else:
self.data = [x.strip() for x in valuelist[0].split(',')]
valuelist = chomp(valuelist[0])
print valuelist
data = [x.strip() for x in valuelist.split(',')]
for i, s in enumerate(data):
word = s
regexp = re.compile(r'^[,.]*$')
if regexp.search(word) is not None:
s = []
data.append(s)
self.data = data
else:
self.data = []
class EditProfileForm(Form):
name = StringField('Real name', validators=[Length(0, 64)])
location = StringField('Location', validators=[Length(0, 64)])
......
......@@ -374,13 +374,12 @@ def recipe(id):
for ingredient in step.ingredients:
ingredients.append(ingredient)
if ingredient.name in ingredients:
print "match"
print ''
else:
ingredients.append(ingredient)
ingredients = list(set(ingredients))
print ingredients
......@@ -503,7 +502,6 @@ def editrecipe(id):
form.methods.data = returnListed(recipe.methods)
for i, step in enumerate(recipe.steps):
print "Step "+str(step.step_id)+" ingredients:", returnListed(step.ingredients)
form.steps[i].ingredients.data = returnListed(step.ingredients)
for i in range(0, recipe.steps.count()):
......
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