Commit c37ec9f8 authored by Francesca Sargent 's avatar Francesca Sargent
Browse files

Commenting to others

parent f11231b9
......@@ -473,28 +473,77 @@ def recipe(id):
flash('Your comment has been published.')
return redirect(url_for('.recipe', id=recipe.id))
comments = Comment.query.filter_by(recipe=recipe).all()
return render_template('recipe.html', recipes=[recipe], ingredients=ingredients, form=form, comments=comments)
@main.route('/cuisine/<int:id>', methods=['GET', 'POST'])
def cuisine(id):
cuisine = [Cuisine.query.get_or_404(id)]
return render_template('cuisine.html', cuisines=cuisine)
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))
comments = Comment.query.filter_by(cuisine=cuisine).all()
return render_template('cuisine.html', cuisines=[cuisine], form=form, comments=comments)
@main.route('/method/<int:id>', methods=['GET', 'POST'])
def method(id):
method = [Method.query.get_or_404(id)]
return render_template('method.html', methods=method)
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))
comments = Comment.query.filter_by(method=method).all()
return render_template('method.html', methods=[method], form=form, comments=comments)
@main.route('/ingredient/<int:id>', methods=['GET', 'POST'])
def ingredient(id):
ingredient = [Ingredient.query.get_or_404(id)]
return render_template('ingredient.html', ingredients=ingredient)
ingredient = Ingredient.query.get_or_404(id)
form = CommentForm()
if form.validate_on_submit():
comment = Comment(body=form.body.data,
ingredient=ingredient,
author=current_user._get_current_object())
db.session.add(comment)
flash('Your comment has been published.')
return redirect(url_for('.ingredient', id=ingredient.id))
comments = Comment.query.filter_by(ingredient=ingredient).all()
return render_template('ingredient.html', ingredients=[ingredient], form=form, comments=comments)
@main.route('/flavour/<int:id>', methods=['GET', 'POST'])
def flavour(id):
flavour = [FlavourType.query.get_or_404(id)]
return render_template('flavour.html', flavourtypes=flavour, type='flavour')
flavour = FlavourType.query.get_or_404(id)
form = CommentForm()
if form.validate_on_submit():
comment = Comment(body=form.body.data,
flavourtype=flavour,
author=current_user._get_current_object())
db.session.add(comment)
flash('Your comment has been published.')
return redirect(url_for('.flavour', id=flavour.id))
comments = Comment.query.filter_by(flavourtype=flavour).all()
return render_template('flavour.html', flavourtypes=[flavour], type='flavour', form=form, comments=comments)
@main.route('/recipe/<int:id>/edit', methods=['GET', 'POST'])
@login_required
......
{% if comments %}
<ul class="comments">
{% for comment in comments %}
<li class="comment">
......@@ -33,3 +34,4 @@
</li>
{% endfor %}
</ul>
{% endif %}
......@@ -97,5 +97,13 @@ Created by <a href="{{ url_for('.user', username=cuisine.author.username) }}">{{
</div>
<h4 id="comments">Comments</h4>
{% if current_user.can(Permission.COMMENT) %}
<div class="comment-form">
{{ wtf.quick_form(form) }}
</div>
{% endif %}
{% include '_comments.html' %}
{% endfor %}
{% endblock %}
......@@ -42,5 +42,13 @@ Created by <a href="{{ url_for('.user', username=flavour.author.username) }}">{{
</div>
</div>
<h4 id="comments">Comments</h4>
{% if current_user.can(Permission.COMMENT) %}
<div class="comment-form">
{{ wtf.quick_form(form) }}
</div>
{% endif %}
{% include '_comments.html' %}
{% endfor %}
{% endblock %}
......@@ -48,5 +48,13 @@ Created by <a href="{{ url_for('.user', username=ingredient.author.username) }}"
</div>
</div>
<h4 id="comments">Comments</h4>
{% if current_user.can(Permission.COMMENT) %}
<div class="comment-form">
{{ wtf.quick_form(form) }}
</div>
{% endif %}
{% include '_comments.html' %}
{% endfor %}
{% endblock %}
......@@ -52,5 +52,13 @@ Created by <a href="{{ url_for('.user', username=method.author.username) }}">{{
</div>
<h4 id="comments">Comments</h4>
{% if current_user.can(Permission.COMMENT) %}
<div class="comment-form">
{{ wtf.quick_form(form) }}
</div>
{% endif %}
{% include '_comments.html' %}
{% 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