Commit 0ac48993 authored by Francesca Sargent 's avatar Francesca Sargent
Browse files

Commenting throughout, including on Recipe Steps

parent c37ec9f8
......@@ -191,3 +191,9 @@ class MethodForm(Form):
class CommentForm(Form):
body = StringField('Enter your comment', validators=[Required()])
submit = SubmitField('Submit')
class StepCommentForm(Form):
body = StringField('Enter your comment', validators=[Required()])
recipe_step_id = IntegerField(validators=[Required()])
submit = SubmitField('Add')
......@@ -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, IngredientPostForm, FlavourEditForm
IngredientForm, FlavourTypeForm, FlavourForm, IngredientPostForm, FlavourEditForm, StepCommentForm
from .. import db
from ..models import Permission, Role, User, Recipe, Comment, Cuisine, RecipeSteps, Method, Ingredient, FlavourType, Flavour
from ..decorators import admin_required, permission_required
......@@ -464,7 +464,7 @@ def recipe(id):
ingredients = list(set(ingredients))
form = CommentForm()
form = CommentForm(prefix="form")
if form.validate_on_submit():
comment = Comment(body=form.body.data,
recipe=recipe,
......@@ -474,7 +474,17 @@ def recipe(id):
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)
stepform = StepCommentForm(prefix="stepform")
if stepform.validate_on_submit() and stepform.submit.data:
step_comment = Comment(body=stepform.body.data,
recipe=recipe,
recipestep=RecipeSteps.query.get(stepform.recipe_step_id.data),
author=current_user._get_current_object())
db.session.add(step_comment)
flash('Your comment has been published.')
return redirect(url_for('.recipe', id=recipe.id))
return render_template('recipe.html', recipes=[recipe], ingredients=ingredients, comments=comments, stepform=stepform, form=form)
@main.route('/cuisine/<int:id>', methods=['GET', 'POST'])
def cuisine(id):
......
......@@ -31,6 +31,10 @@ ul.recipes li.recipe:hover {
div.recipe-date {
float: right;
}
.recipe-date {
float:right;
}
div.recipe-author {
font-weight: bold;
}
......@@ -334,4 +338,8 @@ input[type=range]:focus::-ms-fill-lower {
}
input[type=range]:focus::-ms-fill-upper {
background: #367ebd;
}
.notes {
display: none;
}
\ No newline at end of file
{% if comments %}
<ul class="comments">
{% for comment in comments %}
{% if comment.recipe_step_id == step.id %}
<li class="comment">
<div class="comment-thumbnail">
<a href="{{ url_for('.user', username=comment.author.username) }}">
<img class="img-rounded profile-thumbnail" src="{{ comment.author.gravatar(size=40) }}">
</a>
</div>
<div class="comment-content">
<div class="comment-date">{{ moment(comment.timestamp).fromNow() }}</div>
<div class="comment-author"><a href="{{ url_for('.user', username=comment.author.username) }}">{{ comment.author.username }}</a></div>
<div class="comment-body">
{% if comment.disabled %}
<p></p><i>This comment has been disabled by a moderator.</i></p>
{% endif %}
{% if moderate or not comment.disabled %}
{% if comment.body_html %}
{{ comment.body_html | safe }}
{% else %}
{{ comment.body }}
{% endif %}
{% endif %}
</div>
{% if moderate %}
<br>
{% if comment.disabled %}
<a class="btn btn-default btn-xs" href="{{ url_for('.moderate_enable', id=comment.id, page=page) }}">Enable</a>
{% else %}
<a class="btn btn-danger btn-xs" href="{{ url_for('.moderate_disable', id=comment.id, page=page) }}">Disable</a>
{% endif %}
{% endif %}
</div>
</li>
{% endif %}
{% endfor %}
</ul>
{% endif %}
......@@ -144,6 +144,23 @@
});
$('#colour').addClass('color');
$('.recipe_id').hide()
$('input[name="stepform-recipe_step_id"]').each(function(i, key) {
recipe_id = $('.recipe_id').text()
$(this).val(recipe_id + i);
});
$('input[name="stepform-recipe_step_id"]').hide()
$("label[for='stepform-recipe_step_id']").hide()
$('div.recipe-content > div > h4').after('<a><span class="glyphicon glyphicon-comment"></span></a>');
$('.glyphicon-comment').click(function(i) {
child = $('div.recipe_step_render').find('div.notes')
$(child).fadeToggle()
})
</script>
{{ moment.include_moment() }}
......@@ -173,8 +190,6 @@
$('ul#steps').after('<div id="add_another_button">Add</div><div class="remove_this">Remove</div>')
$('div#add_another_button').click(function () {
console.log('clicked');
last_li = $(this).prev('li')
......
......@@ -8,7 +8,7 @@
{% for recipe in recipes %}
<div class="recipe-content">
<p><h4> {{recipe.name }} </h4>
<p><h4> {{recipe.name }} </h4> <span class="recipe_id"> {{ recipe.id }}</span>
Created by <a href="{{ url_for('.user', username=recipe.author.username) }}">{{ recipe.author.username }}</a></p>
<div class="recipe-body">
......@@ -51,10 +51,21 @@ Created by <a href="{{ url_for('.user', username=recipe.author.username) }}">{{
{{ recipe.description | safe }}
{% endif %} </p>
<p><h4>Recipe Steps</h4>
<h4>Recipe Steps</h4>
{% for step in recipe.steps %}
<p><b>{{ step.step_id + 1 }}</b>. {{ step.step_text }} <br/>
{% if step.ingredients %}<em>Ingredients: </em>{% for ingredient in step.ingredients %} <span class="badge"> <a href="{{ url_for('.ingredient', id=ingredient.id) }}"> {{ ingredient.name }} </a> </span>{% endfor %}{% endif %}</p>
<div class= "recipe_step_render"><b>{{ step.step_id + 1 }}</b>. {{ step.step_text }} <br/>
{% if step.ingredients %}<em>Ingredients: </em>{% for ingredient in step.ingredients %} <span class="badge"> <a href="{{ url_for('.ingredient', id=ingredient.id) }}"> {{ ingredient.name }} </a> </span>{% endfor %}{% endif %}
<div class="notes">
<h4 id="comments">Notes</h4>
{% if current_user.can(Permission.COMMENT) %}
<div class="comment-form">
{{ wtf.quick_form(stepform) }}
</div>
{% include '_step_comments.html' %}
{% endif %}
</div>
</div>
{% endfor %}
<div class="recipe-footer">
......
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