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

Colours for flavours

parent ed47600a
......@@ -79,6 +79,7 @@ class FlavourTypeForm(Form):
class FlavourEditForm(Form):
name = StringField('Flavour Name', validators=[Length(0, 64)])
characteristics = TextAreaField('Flavour Characteristics')
colour = StringField('Colour', validators=[Length(0,6)])
submit = SubmitField('Submit')
......
......@@ -337,6 +337,7 @@ def poststuff(type):
flavour = FlavourType()
flavour.name = form.name.data
flavour.characteristics = form.characteristics.data
flavour.colour = form.colour.data
flavour.author = current_user._get_current_object()
db.session.add(flavour)
......@@ -504,7 +505,7 @@ def ingredient(id):
@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)
return render_template('flavour.html', flavourtypes=flavour, type='flavour')
@main.route('/recipe/<int:id>/edit', methods=['GET', 'POST'])
@login_required
......@@ -665,16 +666,18 @@ def editflav(id):
flavour.name = form.name.data
flavour.characteristics = form.characteristics.data
flavour.colour = form.colour.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
form.colour.data = flavour.colour
return render_template('edit_recipe.html', form=form, type='flavour')
def addFlavourType(namedata, characteristicdata):
def addFlavourType(namedata, characteristicdata, colourdata):
if FlavourType.query.filter_by(name=namedata).first() != None:
flavourtype = FlavourType.query.filter_by(name=namedata).first()
else:
......@@ -682,6 +685,7 @@ def addFlavourType(namedata, characteristicdata):
flavourtype.name = namedata
flavourtype.author = current_user._get_current_object()
flavourtype.colour = colourdata
db.session.add(flavourtype)
......@@ -739,10 +743,11 @@ def editingredient(id):
print flavourtype_name
flavourtype_characteristics = flavour_entry['characteristics'].data
flavourtype_colour = flavour_entry['colour'].data
print flavourtype_characteristics
addFlavourType(flavourtype_name, flavourtype_characteristics)
addFlavourType(flavourtype_name, flavourtype_characteristics, flavourtype_colour)
print flavour_entry.flavours.data
......@@ -773,6 +778,7 @@ def editingredient(id):
for i, flavour in enumerate(ingredient.flavours):
form.flavours[i]['characteristics'].data = flavour.flavourtype.characteristics
form.flavours[i]['name'].data = flavour.flavourtype_name
form.flavours[i]['colour'].data = flavour.flavourtype.colour
for i, flavour in enumerate(ingredient.flavours):
......
......@@ -407,6 +407,7 @@ class FlavourType(db.Model):
id = db.Column(db.Integer(), primary_key=True, unique=True)
name = db.Column(db.String(64), unique=True)
characteristics = db.Column(db.Text)
colour = db.Column(db.String(6))
timestamp = db.Column(db.DateTime, index=True, default=datetime.utcnow)
author_id = db.Column(db.Integer, db.ForeignKey('users.id'))
......
This diff is collapsed.
......@@ -100,6 +100,7 @@
{{ super() }}
<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/themes/smoothness/jquery-ui.css" />
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/jquery-ui.min.js"></script>
<script type="text/javascript" src="{{ url_for('static', filename='jscolor.js') }}"></script>
<script>
$.ajax({
type: 'GET',
......@@ -142,6 +143,7 @@
}
});
$('#colour').addClass('color');
</script>
{{ moment.include_moment() }}
......@@ -242,6 +244,7 @@ function clone_field_list(selector) {
var selector_label = '#flavours-'+i+' > tbody > tr > th > label'
var prevalence = 'input#flavours-'+i+'-flavours-prevalence'
var label_select = 'label[for="flavours-'+i+'"]'
var colour = 'flavours-'+i+'-colour'
$('#flavours-'+i+'-flavours > tbody > tr:nth-child(2)').addClass('hide');
......@@ -252,7 +255,8 @@ function clone_field_list(selector) {
$('#flavours-'+i+'-characteristics').addClass('hide');
$('#flavours-'+i+'-flavours-ingredient_id').addClass('hide');
$(characteristics).addClass('steptext');
$("#"+colour).addClass('color')
.addClass('ingredtext');
$(characteristics).attr('placeholder', 'Flavour Description')
$(name).addClass('ingredtext');
......
......@@ -8,7 +8,7 @@
{% for flavour in flavourtypes %}
<div class="recipe-content">
<p><h4> {{ flavour.name }} </h4>
<p><h4 class="alert alert-success" style="background: #{{flavour.colour}}; border: 0px"> </h4> <h4> {{ flavour.name }} </h4>
Created by <a href="{{ url_for('.user', username=flavour.author.username) }}">{{ flavour.author.username }}</a></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