Commit 6ae7c41f authored by Francesca Sargent 's avatar Francesca Sargent
Browse files

Single view for Recipes, Cuisines and Methods

parent cb938ae7
......@@ -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'])
......
......@@ -149,3 +149,7 @@ ul#steps.form-control {
margin: 5px;
padding: 5px;
}
span a {
color: #fff !important;
}
......@@ -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 %}
......@@ -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 %}
{% include '_comments.html' %}
{% if pagination %}
{% if 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 %}
......@@ -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 %}
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