Commit 6438d879 authored by Francesca Sargent 's avatar Francesca Sargent
Browse files

Added menus

parent 9563f370
......@@ -593,6 +593,23 @@ def flavour(id):
return render_template('flavour.html', flavourtypes=[flavour], type='flavour', form=form, comments=comments)
@main.route('/menu/<int:id>', methods=['GET', 'POST'])
def menu(id):
menu = Menu.query.get_or_404(id)
form = CommentForm()
if form.validate_on_submit():
comment = Comment(body=form.body.data,
menu=menu,
author=current_user._get_current_object())
db.session.add(comment)
flash('Your comment has been published.')
return redirect(url_for('.menu', id=menu.id))
comments = Comment.query.filter_by(menu=menu).all()
return render_template('menu.html', menus=[menu], type='menu', form=form, comments=comments)
@main.route('/recipe/<int:id>/edit', methods=['GET', 'POST'])
@login_required
def editrecipe(id):
......@@ -763,6 +780,67 @@ def editflav(id):
return render_template('edit_recipe.html', form=form, type='flavour')
@main.route('/menu/<int:id>/edit', methods=['GET', 'POST'])
@login_required
def editmenu(id):
db.session.autoflush = True
menu = Menu.query.get_or_404(id)
if current_user != menu.author and \
not current_user.can(Permission.ADMINISTER):
abort(403)
menurecipes = len(menu.recipes)
if len(menu.recipes) == 0:
recipescount = 1
else:
recipescount = len(menu.recipes)
class M(MenuForm):
title = StringField('Menu Title', validators=[Required(), Length(0, 64)])
description = PageDownField('Recipe Description')
recipes = FieldList(FormField(MenuRecipeForm), min_entries=recipescount)
submit = SubmitField('Submit')
form = M()
if form.validate_on_submit():
menu.title = form.title.data
menu.description = form.description.data
for index,recipe_entry in enumerate(form.recipes.entries):
if recipe_entry.recipe_id == '':
pass
else:
recipe = Recipe.query.filter_by(id=recipe_entry.recipe_id).first()
recipe_id = recipe_entry.recipe_id.data
if index is 0:
menu.recipes = addRecipe(recipe_id)
else:
recipe = addRecipe(recipe_id)
menu.recipes.extend(recipe)
menu.author = current_user._get_current_object()
db.session.add(menu)
flash('The cuisine has been updated.')
return redirect(url_for('.menu', id=menu.id))
form.title.data = menu.title
form.description.data = menu.description
print form.recipes.data
for i, recipe in enumerate(menu.recipes):
form.recipes[i].recipe_id.data = recipe.id
print recipe.id
return render_template('edit_recipe.html', form=form, type='menu', menurecipes=menurecipes)
def addFlavourType(namedata, characteristicdata, colourdata):
if FlavourType.query.filter_by(name=namedata).first() != None:
flavourtype = FlavourType.query.filter_by(name=namedata).first()
......
<ul class="recipes">
{% for menu in menus %}
<li class="recipe">
<div class="recipe-thumbnail">
</div>
<div class="recipe-content">
<div class="recipe-date"><b>{{ moment(menu.timestamp).fromNow() }}</b></div>
<div class="recipe-author">
<h4><a href="{{ url_for('.menu', id=menu.id) }}">{{ menu.title }}</a></h4>
<a href="{{ url_for('.user', username=menu.author.username) }}">{{ menu.author.username }}</a></div>
<div class="recipe-body">
<p>{% if menu.description %}
{{ menu.description }}
{% endif %}</p>
<div class="recipe-footer">
{% if current_user == menu.author %}
<a href="{{ url_for('.editmenu', id=menu.id) }}">
<span class="label label-primary">Edit</span>
</a>
{% elif current_user.is_administrator() %}
<a href="{{ url_for('.editmenu', id=menu.id) }}">
<span class="label label-danger">Edit [Admin]</span>
</a>
{% endif %}
<a href="{{ url_for('.menu', id=menu.id) }}">
<span class="label label-default">Permalink</span>
</a>
<a href="{{ url_for('.menu', id=menu.id) }}#comments">
<span class="label label-primary">{{ menu.comments.count() }} Comments</span>
</a>
</div>
</div>
</li>
{% endfor %}
</ul>
{% extends "base.html" %}
{% import "_macros.html" as macros %}
{% block title %}Recipes{% endblock %}
{% block page_content %}
<h3>View all Menus</span></h3>
{% include '_menus.html' %}
{% if pagination %}
<!-- <div class="pagination">
{{ macros.pagination_widget(pagination, '.user', username=user.username) }}
</div> -->
{% endif %}
{% endblock %}
\ No newline at end of file
......@@ -366,7 +366,8 @@ function clone_field_list(selector) {
{% if type == 'menu' %}
<script>
var recipecount = parseInt('{% if menu %}{{menu.recipes.count()}}{% else %}0{% endif %}')
var recipecount = parseInt('{{ menurecipes }}')
console.log(recipecount)
$('#recipes').css({
'border' : '0px',
......@@ -375,9 +376,7 @@ function clone_field_list(selector) {
'box-shadow' : '0px 0px 0px 0px rgba(255,255,255, 255)'
});
$('#recipes > li').css({
'display' : 'block'
})
$('#recipes').addClass('steptext');
......@@ -385,7 +384,7 @@ function clone_field_list(selector) {
$('#recipes > li > label').hide()
$('#recipes-'+i+' > tbody > tr:nth-child(1) > th > label').hide()
$('label[for="recipes-'+i+'-recipe_id"]').text("Recipe ")
$('label[for="recipes-'+i+'-recipe_id"]').text("Recipe " + (i + 1) + " ")
}
$('ul#recipes').after('<div id="add_another_button">Add</div><div class="remove_this">Remove</div>')
......@@ -408,7 +407,9 @@ function clone_field_list(selector) {
$("div.remove_this").click(function(e) {
$('ul#recipes li:last').remove();
e.preventDefault();
var lis = document.querySelectorAll('.steptext').length;
var lis = document.querySelectorAll('input[type=select]').length;
console.log(lis)
if (lis === 1) {
$(this).fadeOut();
......@@ -423,7 +424,6 @@ function clone_field_list(selector) {
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('2')
});
new_element.find('label').each(function() {
var new_for = $(this).attr('for').replace('-' + (elem_num - 1) + '-', '-' + elem_num + '-');
......
{% extends "base.html" %}
{% import "bootstrap/wtf.html" as wtf %}
{% import "_macros.html" as macros %}
{% block title %}Open Sauces - Recipe{% endblock %}
{% block page_content %}
{% for menu in menus %}
<div class="recipe-content">
<p><h4> {{menu.title }} </h4>
Created by <a href="{{ url_for('.user', username=menu.author.username) }}">{{ menu.author.username }}</a></p>
<div class="recipe-body">
<p>{% if menu.description %}
{{ menu.description }}
{% endif %} </p>
<p><strong>Courses: </strong><br/> <ol>
{% for recipe in menu.recipes %}<li><a href="{{ url_for('.recipe', id=recipe.id) }}"> {{ recipe.name }} </a></li>{% endfor %}
</ol>
</p>
</div>
<div class="recipe-footer">
{% if current_user == menu.author %}
<a href="{{ url_for('.editmenu', id=menu.id) }}">
<span class="label label-primary">Edit</span>
</a>
{% elif current_user.is_administrator() %}
<a href="{{ url_for('.editmenu', id=menu.id) }}">
<span class="label label-danger">Edit [Admin]</span>
</a>
{% endif %}
<a href="{{ url_for('.menu', id=menu.id) }}">
<span class="label label-default">Permalink</span>
</a>
<a href="{{ url_for('.menu', id=menu.id) }}#comments">
<span class="label label-primary">{{ menu.comments.count() }} Comments</span>
</a>
</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 %}
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