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
6ae7c41f
Commit
6ae7c41f
authored
Jan 27, 2015
by
Francesca Sargent
Browse files
Single view for Recipes, Cuisines and Methods
parent
cb938ae7
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
162 additions
and
92 deletions
+162
-92
flask/app/main/views.py
flask/app/main/views.py
+22
-57
flask/app/static/styles.css
flask/app/static/styles.css
+4
-0
flask/app/templates/cuisine.html
flask/app/templates/cuisine.html
+43
-14
flask/app/templates/method.html
flask/app/templates/method.html
+47
-9
flask/app/templates/recipe.html
flask/app/templates/recipe.html
+46
-12
No files found.
flask/app/main/views.py
View file @
6ae7c41f
...
...
@@ -321,70 +321,35 @@ def edit_profile_admin(id):
@
main
.
route
(
'/recipe/<int:id>'
,
methods
=
[
'GET'
,
'POST'
])
def
recipe
(
id
):
recipe
=
Recipe
.
query
.
get_or_404
(
id
)
form
=
CommentForm
()
if
form
.
validate_on_submit
():
comment
=
Comment
(
body
=
form
.
body
.
data
,
recipe
=
recipe
,
author
=
current_user
.
_get_current_object
())
db
.
session
.
add
(
comment
)
flash
(
'Your comment has been published.'
)
return
redirect
(
url_for
(
'.recipe'
,
id
=
recipe
.
id
,
page
=-
1
))
page
=
request
.
args
.
get
(
'page'
,
1
,
type
=
int
)
if
page
==
-
1
:
page
=
(
recipe
.
comments
.
count
()
-
1
)
/
\
current_app
.
config
[
'FLASKY_COMMENTS_PER_PAGE'
]
+
1
pagination
=
recipe
.
comments
.
order_by
(
Comment
.
timestamp
.
asc
()).
paginate
(
page
,
per_page
=
current_app
.
config
[
'FLASKY_COMMENTS_PER_PAGE'
],
error_out
=
False
)
comments
=
pagination
.
items
return
render_template
(
'recipe.html'
,
recipes
=
[
recipe
],
form
=
form
,
comments
=
comments
,
pagination
=
pagination
)
recipe
=
[
Recipe
.
query
.
get_or_404
(
id
)]
# form = CommentForm()
# if form.validate_on_submit():
# comment = Comment(body=form.body.data,
# recipe=recipe,
# author=current_user._get_current_object())
# db.session.add(comment)
# flash('Your comment has been published.')
# return redirect(url_for('.recipe', id=recipe.id, page=-1))
# page = request.args.get('page', 1, type=int)
# if page == -1:
# page = (recipe.comments.count() - 1) / \
# current_app.config['FLASKY_COMMENTS_PER_PAGE'] + 1
# pagination = recipe.comments.order_by(Comment.timestamp.asc()).paginate(
# page, per_page=current_app.config['FLASKY_COMMENTS_PER_PAGE'],
# error_out=False)
# comments = pagination.items
return
render_template
(
'recipe.html'
,
recipes
=
recipe
)
@
main
.
route
(
'/cuisine/<int:id>'
,
methods
=
[
'GET'
,
'POST'
])
def
cuisine
(
id
):
cuisine
=
Cuisine
.
query
.
get_or_404
(
id
)
form
=
CommentForm
()
if
form
.
validate_on_submit
():
comment
=
Comment
(
body
=
form
.
body
.
data
,
cuisine
=
cuisine
,
author
=
current_user
.
_get_current_object
())
db
.
session
.
add
(
comment
)
flash
(
'Your comment has been published.'
)
return
redirect
(
url_for
(
'.cuisine'
,
id
=
cuisine
.
id
,
page
=-
1
))
page
=
request
.
args
.
get
(
'page'
,
1
,
type
=
int
)
if
page
==
-
1
:
page
=
(
cuisine
.
comments
.
count
()
-
1
)
/
\
current_app
.
config
[
'FLASKY_COMMENTS_PER_PAGE'
]
+
1
pagination
=
cuisine
.
comments
.
order_by
(
Comment
.
timestamp
.
asc
()).
paginate
(
page
,
per_page
=
current_app
.
config
[
'FLASKY_COMMENTS_PER_PAGE'
],
error_out
=
False
)
comments
=
pagination
.
items
return
render_template
(
'cuisine.html'
,
recipes
=
[
cuisine
],
form
=
form
,
comments
=
comments
,
pagination
=
pagination
)
cuisine
=
[
Cuisine
.
query
.
get_or_404
(
id
)]
return
render_template
(
'cuisine.html'
,
cuisines
=
cuisine
)
@
main
.
route
(
'/method/<int:id>'
,
methods
=
[
'GET'
,
'POST'
])
def
method
(
id
):
method
=
Method
.
query
.
get_or_404
(
id
)
form
=
CommentForm
()
if
form
.
validate_on_submit
():
comment
=
Comment
(
body
=
form
.
body
.
data
,
method
=
method
,
author
=
current_user
.
_get_current_object
())
db
.
session
.
add
(
comment
)
flash
(
'Your comment has been published.'
)
return
redirect
(
url_for
(
'.method'
,
id
=
method
.
id
,
page
=-
1
))
page
=
request
.
args
.
get
(
'page'
,
1
,
type
=
int
)
if
page
==
-
1
:
page
=
(
method
.
comments
.
count
()
-
1
)
/
\
current_app
.
config
[
'FLASKY_COMMENTS_PER_PAGE'
]
+
1
pagination
=
method
.
comments
.
order_by
(
Comment
.
timestamp
.
asc
()).
paginate
(
page
,
per_page
=
current_app
.
config
[
'FLASKY_COMMENTS_PER_PAGE'
],
error_out
=
False
)
comments
=
pagination
.
items
return
render_template
(
'method.html'
,
recipes
=
[
method
],
form
=
form
,
comments
=
comments
,
pagination
=
pagination
)
method
=
[
Method
.
query
.
get_or_404
(
id
)]
return
render_template
(
'method.html'
,
methods
=
method
)
@
main
.
route
(
'/recipe/<int:id>/edit'
,
methods
=
[
'GET'
,
'POST'
])
...
...
flask/app/static/styles.css
View file @
6ae7c41f
...
...
@@ -149,3 +149,7 @@ ul#steps.form-control {
margin
:
5px
;
padding
:
5px
;
}
span
a
{
color
:
#fff
!important
;
}
flask/app/templates/cuisine.html
View file @
6ae7c41f
...
...
@@ -2,20 +2,49 @@
{% import "bootstrap/wtf.html" as wtf %}
{% import "_macros.html" as macros %}
{% block title %}Open Sauces - Recipe{% endblock %}
{% block cuisine %}
{% include '_cuisines.html' %}
<h4
id=
"comments"
>
Comments
</h4>
{% if current_user.can(Permission.COMMENT) %}
<div
class=
"comment-form"
>
{{ wtf.quick_form(form) }}
</div>
{% block title %}Open Sauces - cuisine{% endblock %}
{% block page_content %}
{% for cuisine in cuisines %}
<div
class=
"recipe-content"
>
<p><h4>
{{ cuisine.name }}
</h4>
Created by
<a
href=
"{{ url_for('.user', username=cuisine.author.username) }}"
>
{{ cuisine.author.username }}
</a></p>
<div
class=
"recipe-body"
></p>
<div
class=
"recipe-body"
>
{% if cuisine.methods %}
<p><strong>
Associated Methods:
</strong>
{% for method in cuisine.methods %}
<span
class=
"badge"
><a
href=
"{{ url_for('.method', id=method.id) }}"
>
{{ method.name }}
</a></span>
{% endfor %}
<br/>
{% endif %}
{% include '_comments.html' %}
{% if pagination %}
<div
class=
"pagination"
>
{{ macros.pagination_widget(pagination, '.recipe', fragment='#comments', id=recipes[0].id) }}
</div>
{% if cuisine.recipes %}
<strong>
Recipes:
</strong>
{% for recipe in cuisine.recipes %}
<span
class=
"badge"
><a
href=
"{{ url_for('.recipe', id=recipe.id) }}"
>
{{ recipe.name }}
</a></span>
{% endfor %}
<br/>
{% endif %}
<p>
{% if cuisine.description %}
{{ cuisine.description }}
{% else %}
{{ cuisine.description | safe }}
{% endif %}
</p>
<div
class=
"recipe-footer"
>
{% if current_user == cuisine.author %}
<a
href=
"{{ url_for('.editcuisine', id=cuisine.id) }}"
>
<span
class=
"label label-primary"
>
Edit
</span>
</a>
{% elif current_user.is_administrator() %}
<a
href=
"{{ url_for('.editcuisine', id=cuisine.id) }}"
>
<span
class=
"label label-danger"
>
Edit [Admin]
</span>
</a>
{% endif %}
<a
href=
"{{ url_for('.cuisine', id=cuisine.id) }}"
>
<span
class=
"label label-default"
>
Permalink
</span>
</a>
</div>
</div>
</div>
{% endfor %}
{% endblock %}
flask/app/templates/method.html
View file @
6ae7c41f
...
...
@@ -4,15 +4,53 @@
{% block title %}Open Sauces - Method{% endblock %}
{% block recipe %}
{% include '_methods.html' %}
<h4
id=
"comments"
>
Comments
</h4>
{% if current_user.can(Permission.COMMENT) %}
<div
class=
"comment-form"
>
{{ wtf.quick_form(form) }}
</div>
{% block page_content %}
{% for method in methods %}
<div
class=
"recipe-content"
>
<p><h4>
{{ method.name }}
</h4>
Created by
<a
href=
"{{ url_for('.user', username=method.author.username) }}"
>
{{ method.author.username }}
</a></p>
<div
class=
"recipe-body"
></p>
<div
class=
"recipe-body"
>
{% if method.cuisines %}
<p><strong>
Associated Cuisines:
</strong>
{% for cuisine in method.cuisines %}
<span
class=
"badge"
><a
href=
"{{ url_for('.cuisine', id=cuisine.id) }}"
>
{{ cuisine.name }}
</a></span>
{% endfor %}
<br/>
{% endif %}
{% i
nclude '_comments.html'
%}
{% if pagination %}
{% i
f method.recipes
%}
<strong>
Recipes:
</strong>
{% for recipe in method.recipes %}
<span
class=
"badge"
><a
href=
"{{ url_for('.recipe', id=recipe.id) }}"
>
{{ recipe.name }}
</a></span>
{% endfor %}
<br/>
{% endif %}
<p>
{% if method.description %}
{{ method.description }}
{% else %}
{{ method.description | safe }}
{% endif %}
</p>
<p>
{% if method.method_text %}
{{ method.method_text }}
{% else %}
{{ method.method_text | safe }}
{% endif %}
</p>
<div
class=
"recipe-footer"
>
{% if current_user == method.author %}
<a
href=
"{{ url_for('.editmethod', id=method.id) }}"
>
<span
class=
"label label-primary"
>
Edit
</span>
</a>
{% elif current_user.is_administrator() %}
<a
href=
"{{ url_for('.editmethod', id=method.id) }}"
>
<span
class=
"label label-danger"
>
Edit [Admin]
</span>
</a>
{% endif %}
<a
href=
"{{ url_for('.method', id=method.id) }}"
>
<span
class=
"label label-default"
>
Permalink
</span>
</a>
</div>
</div>
</div>
{% endfor %}
{% endblock %}
flask/app/templates/recipe.html
View file @
6ae7c41f
...
...
@@ -4,18 +4,52 @@
{% block title %}Open Sauces - Recipe{% endblock %}
{% block recipe %}
{% include '_recipes.html' %}
<h4
id=
"comments"
>
Comments
</h4>
{% if current_user.can(Permission.COMMENT) %}
<div
class=
"comment-form"
>
{{ wtf.quick_form(form) }}
{% block page_content %}
{% for recipe in recipes %}
<div
class=
"recipe-content"
>
<p><h4>
{{recipe.name }}
</h4>
Created by
<a
href=
"{{ url_for('.user', username=recipe.author.username) }}"
>
{{ recipe.author.username }}
</a></p>
<div
class=
"recipe-body"
>
{% if recipe.cuisines.count() > 0 %}
<p><strong>
Associated Cuisines:
</strong>
{% for cuisine in recipe.cuisines %}
<span
class=
"badge"
><a
href=
"{{ url_for('.cuisine', id=cuisine.id) }}"
>
{{ cuisine.name }}
</a></span>
{% endfor %}
<br/>
{% endif %}
{% if recipe.methods.count() > 0 %}
<strong>
Associated Methods:
</strong>
{% for method in recipe.methods %}
<span
class=
"badge"
>
<a
href=
"{{ url_for('.method', id=method.id) }}"
>
{{ method.name }}
</a>
</span>
{% endfor %}
<br/></p>
{% endif %}
<p>
{% if recipe.description %}
{{ recipe.description }}
{% else %}
{{ recipe.description | safe }}
{% endif %}
</p>
<p>
{% for step in recipe.steps %}
<p><b>
{{ step.step_id + 1 }}
</b>
. {{ step.step_text }}
</p>
{% endfor %}
<div
class=
"recipe-footer"
>
{% if current_user == recipe.author %}
<a
href=
"{{ url_for('.editrecipe', id=recipe.id) }}"
>
<span
class=
"label label-primary"
>
Edit
</span>
</a>
{% elif current_user.is_administrator() %}
<a
href=
"{{ url_for('.editrecipe', id=recipe.id) }}"
>
<span
class=
"label label-danger"
>
Edit [Admin]
</span>
</a>
{% endif %}
<a
href=
"{{ url_for('.recipe', id=recipe.id) }}"
>
<span
class=
"label label-default"
>
Permalink
</span>
</a>
<a
href=
"{{ url_for('.recipe', id=recipe.id) }}#comments"
>
<span
class=
"label label-primary"
>
{{ recipe.comments.count() }} Comments
</span>
</a>
</div>
</p>
</div>
{% endif %}
{% include '_comments.html' %}
{% if pagination %}
<div
class=
"pagination"
>
{{ macros.pagination_widget(pagination, '.recipe', fragment='#comments', id=recipes[0].id) }}
</div>
{% endif %}
{% endfor %}
{% 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