Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
FoAM
open sauces
Commits
5c086901
Commit
5c086901
authored
Jan 29, 2015
by
Francesca Sargent
Browse files
Fixed null ingredient problem
parent
cc30dbb4
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
4 deletions
+19
-4
flask/app/main/forms.py
flask/app/main/forms.py
+18
-1
flask/app/main/views.py
flask/app/main/views.py
+1
-3
No files found.
flask/app/main/forms.py
View file @
5c086901
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
)])
...
...
flask/app/main/views.py
View file @
5c086901
...
...
@@ -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
()):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment