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

Pages and links for flavours, editing also

parent 2f0a492c
......@@ -76,6 +76,12 @@ class FlavourTypeForm(Form):
self.name.choices = [(flavour.name, flavour.name)
for flavour in FlavourType.query.order_by(FlavourType.name).all()]
class FlavourEditForm(Form):
name = StringField('Flavour Name', validators=[Length(0, 64)])
characteristics = TextAreaField('Flavour Characteristics')
submit = SubmitField('Submit')
class IngredientForm(Form):
name = StringField('Ingredient Name', validators=[Required(), Length(0,64)])
description = TextAreaField('Description')
......
......@@ -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
IngredientForm, FlavourTypeForm, FlavourForm, IngredientPostForm, FlavourEditForm
from .. import db
from ..models import Permission, Role, User, Recipe, Comment, Cuisine, RecipeSteps, Method, Ingredient, FlavourType, Flavour
from ..decorators import admin_required, permission_required
......@@ -130,6 +130,16 @@ def postall(type):
ingredients = pagination.items
return render_template('all_ingredients.html', user=user, ingredients=ingredients,
pagination=pagination, type=type)
if type == 'flavour':
query = FlavourType.query
page = request.args.get('page', 1, type=int)
pagination = query.order_by(FlavourType.timestamp.desc()).paginate(
page, per_page=current_app.config['FLASKY_POSTS_PER_PAGE'],
error_out=False)
flavourtypes = pagination.items
return render_template('all_flavours.html', user=user, flavourtypes=flavourtypes,
pagination=pagination, type=type)
......@@ -319,6 +329,21 @@ def poststuff(type):
flash('Your ingredient has been added.')
return redirect(url_for('.index'))
if type == 'flavour':
form = FlavourEditForm()
if current_user.can(Permission.WRITE_ARTICLES) and \
form.validate_on_submit():
flavour = FlavourType()
flavour.name = form.name.data
flavour.characteristics = form.characteristics.data
flavour.author = current_user._get_current_object()
db.session.add(flavour)
db.session.flush()
flash('Your flavour has been added.')
return redirect(url_for('.index'))
db.session.commit()
return render_template('post.html', form=form,
......@@ -476,6 +501,11 @@ def ingredient(id):
ingredient = [Ingredient.query.get_or_404(id)]
return render_template('ingredient.html', ingredients=ingredient)
@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)
@main.route('/recipe/<int:id>/edit', methods=['GET', 'POST'])
@login_required
def editrecipe(id):
......@@ -622,6 +652,28 @@ def editcuisine(id):
form.methods.data = returnListed(cuisine.methods)
return render_template('edit_recipe.html', form=form, type='cuisine')
@main.route('/flavour/<int:id>/edit', methods=['GET', 'POST'])
@login_required
def editflav(id):
db.session.autoflush = True
flavour = FlavourType.query.get_or_404(id)
if current_user != flavour.author and \
not current_user.can(Permission.ADMINISTER):
abort(403)
form = FlavourEditForm()
if form.validate_on_submit():
flavour.name = form.name.data
flavour.characteristics = form.characteristics.data
db.session.add(flavour)
flash('The cuisine has been updated.')
return redirect(url_for('.flavour', id=flavour.id))
form.name.data = flavour.name
form.characteristics.data = flavour.characteristics
return render_template('edit_recipe.html', form=form, type='flavour')
def addFlavourType(namedata, characteristicdata):
if FlavourType.query.filter_by(name=namedata).first() != None:
flavourtype = FlavourType.query.filter_by(name=namedata).first()
......
<ul class="recipes">
{% for flavour in flavourtypes %}
<li class="recipe">
<div class="recipe-content">
<p><h4><a href="{{ url_for('.flavour', id=flavour.id) }}">{{ flavour.name }}</a></h4>
Created by <a href="{{ url_for('.user', username=flavour.author.username) }}">{{ flavour.author.username }}</a><br/>
<div class="recipe-body">
{% if flavour.characteristics %}
{{ flavour.characteristics }}
{% endif %}
</div>
<div class="recipe-footer">
{% if current_user == flavour.author %}
<a href="{{ url_for('.editflav', id=flavour.id) }}">
<span class="label label-primary">Edit</span>
</a>
{% elif current_user.is_administrator() %}
<a href="{{ url_for('.editflav', id=flavour.id) }}">
<span class="label label-danger">Edit [Admin]</span>
</a>
{% endif %}
<a href="{{ url_for('.flavour', id=flavour.id) }}">
<span class="label label-default">Permalink</span>
</a>
</div>
</li>
{% endfor %}
</ul>
{% extends "base.html" %}
{% import "_macros.html" as macros %}
{% block title %}Flavours{% endblock %}
{% block page_content %}
<h3>View all Flavours</span></h3>
{% include '_flavours.html' %}
{% if pagination %}
{% endif %}
{% endblock %}
\ No newline at end of file
......@@ -40,6 +40,7 @@
<li><a href="{{ url_for('main.poststuff', type='recipe') }}">Recipe</a></li>
<li><a href="{{ url_for('main.poststuff', type='method') }}">Method</a></li>
<li><a href="{{ url_for('main.poststuff', type='ingredient') }}">Ingredient</a></li>
<li><a href="{{ url_for('main.poststuff', type='flavour') }}">Flavour</a></li>
</ul>
</li>
{% endif %}
......@@ -52,6 +53,7 @@
<li><a href="{{ url_for('main.postall', type='recipe') }}">Recipes</a></li>
<li><a href="{{ url_for('main.postall', type='method') }}">Methods</a></li>
<li><a href="{{ url_for('main.postall', type='ingredient') }}">Ingredients</a></li>
<li><a href="{{ url_for('main.postall', type='flavour') }}">Flavours</a></li>
</ul>
</li>
</ul>
......
......@@ -64,7 +64,7 @@ Created by <a href="{{ url_for('.user', username=cuisine.author.username) }}">{{
{% if new_flavours|length > 0 %}
<b>Flavours: </b>
{% for flavour in new_flavours %}
<span class="badge">{{ flavour.flavourtype_name }}</span>
<span class="badge"><a href="{{ url_for('.flavour', id=flavour.flavourtype.id) }}">{{ flavour.flavourtype_name }}</a></span>
{% endfor %}
{% endif %}</p>
......
{% extends "base.html" %}
{% import "bootstrap/wtf.html" as wtf %}
{% import "_macros.html" as macros %}
{% block title %}Open Sauces - Flavour{% endblock %}
{% block page_content %}
{% for flavour in flavourtypes %}
<div class="recipe-content">
<p><h4> {{ flavour.name }} </h4>
Created by <a href="{{ url_for('.user', username=flavour.author.username) }}">{{ flavour.author.username }}</a></p>
<div class="recipe-body">
<p>{% if flavour.characteristics %}
{{ flavour.characteristics }}
{% endif %}</p>
{% if flavour.flavours.count() > 0 %}
<strong>Ingredients: </strong>
{% for flav in flavour.flavours %}
<a href="{{ url_for('.ingredient', id=flav.ingredient.id) }}"><span class="badge">{{ flav.ingredient.name }}</span></a>
{% endfor %}<br/>
{% endif %}
</div>
<div class="recipe-footer">
{% if current_user == flavour.author %}
<a href="{{ url_for('.editflav', id=flavour.id) }}">
<span class="label label-primary">Edit</span>
</a>
{% elif current_user.is_administrator() %}
<a href="{{ url_for('.editflav', id=flavour.id) }}">
<span class="label label-danger">Edit [Admin]</span>
</a>
{% endif %}
<a href="{{ url_for('.flavour', id=flavour.id) }}">
<span class="label label-default">Permalink</span>
</a>
</div>
</div>
{% endfor %}
{% endblock %}
......@@ -19,7 +19,7 @@ Created by <a href="{{ url_for('.user', username=ingredient.author.username) }}"
{% if ingredient.flavours.count() > 0 %}
<b>Flavours: </b> {% for flavour in ingredient.flavours %}
<span class="badge">{{ flavour.flavourtype_name }}</span>
<span class="badge"><a href="{{ url_for('.flavour', id=flavour.flavourtype.id) }}">{{ flavour.flavourtype_name }}</a></span>
{% endfor %}
{% endif %}</p>
......
......@@ -20,6 +20,8 @@
{{ wtf.quick_form(form) }}
{% elif type == 'ingredient' %}
{{ wtf.quick_form(form) }}
{% elif type == 'flavour' %}
{{ wtf.quick_form(form) }}
{% endif %}
</div>
......
......@@ -39,7 +39,7 @@ Created by <a href="{{ url_for('.user', username=recipe.author.username) }}">{{
{% if new_flavours|length > 0 %}
<b>Flavours: </b>
{% for flavour in new_flavours %}
<span class="badge">{{ flavour.flavourtype_name }}</span>
<span class="badge"><a href="{{ url_for('.flavour', id=flavour.flavourtype.id) }}">{{ flavour.flavourtype_name }}</a></span>
{% endfor %}
{% endif %}</p>
......
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