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
a025eb10
Commit
a025eb10
authored
Feb 19, 2015
by
Francesca Sargent
Browse files
Multiple Flavour adding, removed flavours in Post Ingredient stage for now
parent
de8ef3ba
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
77 additions
and
40 deletions
+77
-40
flask/app/main/forms.py
flask/app/main/forms.py
+5
-0
flask/app/main/views.py
flask/app/main/views.py
+32
-28
flask/app/templates/base.html
flask/app/templates/base.html
+40
-12
No files found.
flask/app/main/forms.py
View file @
a025eb10
...
...
@@ -83,6 +83,11 @@ class IngredientForm(Form):
submit
=
SubmitField
(
'Submit'
)
class
IngredientPostForm
(
Form
):
name
=
StringField
(
'Ingredient Name'
,
validators
=
[
Required
(),
Length
(
0
,
64
)])
description
=
TextAreaField
(
'Description'
)
submit
=
SubmitField
(
'Submit'
)
...
...
flask/app/main/views.py
View file @
a025eb10
...
...
@@ -10,7 +10,7 @@ from wtforms import ValidationError, validators, widgets
from
flask.ext.pagedown.fields
import
PageDownField
from
.forms
import
EditProfileForm
,
EditProfileAdminForm
,
RecipeForm
,
\
CommentForm
,
CuisineForm
,
RecipeStepForm
,
MethodForm
,
RecipeEditForm
,
SplitStringField
,
\
IngredientForm
,
FlavourTypeForm
,
FlavourForm
IngredientForm
,
FlavourTypeForm
,
FlavourForm
,
IngredientPostForm
from
..
import
db
from
..models
import
Permission
,
Role
,
User
,
Recipe
,
Comment
,
Cuisine
,
RecipeSteps
,
Method
,
Ingredient
,
FlavourType
,
Flavour
from
..decorators
import
admin_required
,
permission_required
...
...
@@ -248,45 +248,50 @@ def poststuff(type):
return
redirect
(
url_for
(
'.index'
))
if
type
==
'ingredient'
:
form
=
IngredientForm
()
form
=
IngredientPostForm
()
if
current_user
.
can
(
Permission
.
WRITE_ARTICLES
)
and
\
form
.
validate_on_submit
():
ingredient
=
Ingredient
()
if
Ingredient
.
query
.
filter_by
(
name
=
form
.
name
.
data
).
first
()
is
None
:
ingredient
=
Ingredient
()
else
:
ingredient
=
Ingredient
.
query
.
filter_by
(
name
=
form
.
name
.
data
).
first
()
ingredient
.
name
=
form
.
name
.
data
ingredient
.
description
=
form
.
description
.
data
ingredient
.
author
=
current_user
.
_get_current_object
()
for
index
,
flavour_entry
in
enumerate
(
form
.
flavours
.
entries
):
if
flavour_entry
[
'name'
].
data
==
''
:
pass
else
:
flavourtype_name
=
flavour_entry
[
'name'
].
data
#
for index,flavour_entry in enumerate(form.flavours.entries):
#
if flavour_entry['name'].data == '':
#
pass
#
else:
#
flavourtype_name = flavour_entry['name'].data
print
flavourtype_name
#
print flavourtype_name
flavourtype_characteristics
=
flavour_entry
[
'characteristics'
].
data
#
flavourtype_characteristics = flavour_entry['characteristics'].data
print
flavourtype_characteristics
#
print flavourtype_characteristics
addFlavourType
(
flavourtype_name
,
flavourtype_characteristics
)
#
addFlavourType(flavourtype_name, flavourtype_characteristics)
print
flavour_entry
.
flavours
.
data
#
print flavour_entry.flavours.data
flavour_ingredient_id
=
ingredient
.
id
flavour_flavourtype_name
=
flavour
_entry
[
'name'
].
data
flavour_prevalence
=
flavour_entry
.
flavours
[
'prevalence'
].
data
#
flavour_ingredient_id = ingredient.id
#
flavour_flavourtype_name = flavour
type_name
#
flavour_prevalence = flavour_entry.flavours['prevalence'].data
print
flavour_prevalence
#
print flavour_prevalence
if
flavour_entry
[
'name'
].
data
==
[]:
pass
else
:
for
flavour
in
flavour_entry
.
name
:
if
flavour
is
''
:
continue
else
:
addFlavour
(
flavour_ingredient_id
,
flavour_flavourtype_name
,
flavour_prevalence
)
#
if flavour_entry['name'].data == []:
#
pass
#
else:
#
for flavour in flavour_entry.name:
#
if flavour is '':
#
continue
#
else:
#
addFlavour(flavour_ingredient_id, flavour_flavourtype_name, flavour_prevalence)
db
.
session
.
add
(
ingredient
)
db
.
session
.
flush
()
...
...
@@ -603,7 +608,6 @@ def addFlavourType(namedata, characteristicdata):
flavourtype
=
FlavourType
()
flavourtype
.
name
=
namedata
flavourtype
.
characteristics
=
characteristicdata
flavourtype
.
author
=
current_user
.
_get_current_object
()
db
.
session
.
add
(
flavourtype
)
...
...
@@ -670,7 +674,7 @@ def editingredient(id):
print
flavour_entry
.
flavours
.
data
flavour_ingredient_id
=
ingredient
.
id
flavour_flavourtype_name
=
flavour_entry
.
flavours
[
'
flavourtype_name
'
].
data
flavour_flavourtype_name
=
flavourtype_name
flavour_prevalence
=
flavour_entry
.
flavours
[
'prevalence'
].
data
print
flavour_prevalence
...
...
@@ -703,7 +707,7 @@ def editingredient(id):
form
.
flavours
[
i
].
flavours
[
'ingredient_id'
].
data
=
flavour
.
ingredient_id
form
.
flavours
[
i
].
flavours
[
'flavourtype_name'
].
data
=
flavour
.
flavourtype_name
return
render_template
(
'edit_recipe.html'
,
form
=
form
,
type
=
'ingredient
'
)
return
render_template
(
'edit_recipe.html'
,
form
=
form
,
type
=
'ingredient
edit'
,
ingredient
=
ingredient
)
@
main
.
route
(
'/flavourtype/<int:id>/edit'
,
methods
=
[
'GET'
,
'POST'
])
@
login_required
...
...
flask/app/templates/base.html
View file @
a025eb10
...
...
@@ -140,11 +140,6 @@
}
});
$
(
'
#flavours-flavours-prevalence
'
).
attr
(
'
type
'
,
'
range
'
);
$
(
'
#flavours-flavours-prevalence
'
).
attr
(
'
min
'
,
'
1
'
);
$
(
'
#flavours-flavours-prevalence
'
).
attr
(
'
max
'
,
'
10
'
);
</script>
{{ moment.include_moment() }}
...
...
@@ -227,11 +222,11 @@ function clone_field_list(selector) {
</script>
{% endif %}
{% if type == 'ingredient' %}
{% if type ==
'ingredientedit' or type ==
'ingredient' %}
<script>
console
.
log
(
'
ingredient
'
)
var
flavourcount
=
parseInt
(
'
{% if ingredient
s
%}{%for ingredient in ingredients
%}{{ingredient.flavours.count()}}{%
endfor %}{%
else %}0{% endif %}
'
)
var
flavourcount
=
parseInt
(
'
{% if ingredient %}{{ingredient.flavours.count()}}{% else %}0{% endif %}
'
)
console
.
log
(
flavourcount
);
for
(
i
=
0
;
i
<=
flavourcount
;
i
++
)
{
...
...
@@ -247,8 +242,13 @@ function clone_field_list(selector) {
var
label_select
=
'
label[for="flavours-
'
+
i
+
'
"]
'
$
(
'
#flavours-
'
+
i
+
'
-flavours > tbody > tr:nth-child(2)
'
).
addClass
(
'
hide
'
);
$
(
'
#flavours-
'
+
i
+
'
-flavours > tbody > tr:nth-child(3)
'
).
addClass
(
'
hide
'
);
var
tohide
=
$
(
'
#flavours-
'
+
i
+
'
-flavours > tbody > tr:nth-child(3)
'
)
$
(
tohide
).
addClass
(
'
hide
'
);
$
(
'
#flavours-
'
+
i
+
'
-flavours > tbody > tr:nth-child(1)
'
).
addClass
(
'
hide
'
);
$
(
'
#flavours-
'
+
i
+
'
-characteristics
'
).
addClass
(
'
hide
'
);
$
(
'
#flavours-
'
+
i
+
'
-flavours-ingredient_id
'
).
addClass
(
'
hide
'
);
$
(
characteristics
).
addClass
(
'
steptext
'
);
...
...
@@ -261,6 +261,10 @@ function clone_field_list(selector) {
$
(
prevalence
).
attr
(
'
placeholder
'
,
'
Prevalence out of 10
'
)
$
(
prevalence
).
attr
(
'
type
'
,
'
range
'
);
$
(
prevalence
).
attr
(
'
min
'
,
'
1
'
);
$
(
prevalence
).
attr
(
'
max
'
,
'
10
'
);
}
$
(
'
ul#flavours
'
).
after
(
'
<div id="add_another_button">Add</div><div class="remove_this">Remove</div>
'
)
...
...
@@ -294,27 +298,51 @@ $("div.remove_this").click(function(e) {
function
clone_field_list
(
selector
)
{
var
new_element
=
$
(
selector
).
clone
(
true
);
var
new_select
=
$
(
'
select:last
'
).
clone
(
true
);
var
elem_id
=
new_element
.
find
(
'
:input
'
)[
0
].
id
;
var
elem_num
=
parseInt
(
elem_id
.
replace
(
/.*-
(\d{1,4})
-.*/m
,
'
$1
'
))
+
1
;
new_element
.
find
(
'
:input
'
).
each
(
function
()
{
var
id
=
$
(
this
).
attr
(
'
id
'
,
function
(
i
,
txt
)
{
return
txt
.
replace
(
/
\d
+/
,
elem_num
);
});
var
name
=
$
(
this
).
attr
(
'
name
'
,
function
(
i
,
txt
)
{
return
txt
.
replace
(
/
\d
+/
,
elem_num
);
});
$
(
this
).
val
(
''
)
$
(
this
).
addClass
(
'
steptext
'
);
$
(
this
).
html
(
''
);
$
(
this
).
val
(
''
);
});
new_element
.
find
(
'
label
'
).
each
(
function
()
{
new_element
.
find
(
'
label
:first
'
).
each
(
function
()
{
var
new_for
=
$
(
this
).
attr
(
'
for
'
).
replace
(
'
-
'
+
(
elem_num
-
1
)
+
'
-
'
,
'
-
'
+
elem_num
+
'
-
'
);
$
(
this
).
attr
(
'
for
'
,
new_for
);
$
(
this
).
html
(
'
Flavour
'
+
(
elem_num
+
1
))
});
new_element
.
find
(
'
select:first
'
).
each
(
function
()
{
var
id
=
$
(
this
).
attr
(
'
id
'
,
'
null
'
);
var
name
=
$
(
this
).
attr
(
'
name
'
,
'
null
'
);
});
new_element
.
find
(
'
input[type=range]
'
).
each
(
function
()
{
var
id
=
$
(
this
).
attr
(
'
id
'
,
function
(
i
,
txt
)
{
return
txt
.
replace
(
/
\d
+/
,
elem_num
);
});
var
name
=
$
(
this
).
attr
(
'
name
'
,
function
(
i
,
txt
)
{
return
txt
.
replace
(
/
\d
+/
,
elem_num
);
});
$
(
this
).
find
(
'
label:last
'
).
each
(
function
()
{
var
new_for
=
$
(
this
).
attr
(
'
for
'
).
replace
(
'
-
'
+
(
elem_num
-
1
)
+
'
-
'
,
'
-
'
+
elem_num
+
'
-
'
);
$
(
this
).
attr
(
'
for
'
,
new_for
);
$
(
this
).
html
(
'
Prevalence out of 10
'
+
(
elem_num
+
1
))
})
});
new_select
.
each
(
function
(){
var
id
=
$
(
this
).
attr
(
'
id
'
,
function
(
i
,
txt
)
{
return
txt
.
replace
(
/
\d
+/
,
elem_num
);
});
var
name
=
$
(
this
).
attr
(
'
name
'
,
function
(
i
,
txt
)
{
return
txt
.
replace
(
/
\d
+/
,
elem_num
);
});
name
=
$
(
'
#name
'
).
val
()
$
(
this
).
find
(
'
option
'
)
.
val
(
'
{% if ingredient %}{{ingredient.id}}{% else %}1{% endif %}
'
)
$
(
this
).
addClass
(
'
hide
'
)
})
$
(
selector
).
after
(
new_element
)
$
(
new_element
).
after
(
new_select
)
}
</script>
{% endif %}
{% endblock %}
...
...
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