diff --git a/colorpicker.py b/colorpicker.py index 6faae25..79910e1 100644 --- a/colorpicker.py +++ b/colorpicker.py @@ -51,6 +51,7 @@ def gettitle(recipe): from wtforms.fields import TextField from wtforms.validators import Required from wtforms.fields import StringField +from wtforms.fields import BooleanField from wtforms.widgets import TextArea class RecipeForm(Form): @@ -58,6 +59,10 @@ class RecipeForm(Form): ingredients = StringField(u'Ingredients', widget=TextArea(),validators = [Required()]) directions = StringField(u'directions', widget=TextArea(), validators = [Required()]) +class DeleteForm(Form): + deleterecipe = BooleanField('deleterecipe') + + from flask import * app = Flask(__name__) @@ -225,19 +230,29 @@ def edit(query): return redirect(url_for('recipe', query=slug)) -@app.route('//delete', methods = ['GET']) +@app.route('//delete', methods = ['GET', 'POST']) def delete(query): + form = DeleteForm() recipe = list(r.table('recipes').filter({'slug': query}).run(g.rdb_conn)) - if recipe: recipe = recipe[0] else: abort(404) - id = recipe['id'] + if request.method == 'GET': + + return render_template("delete.html", query=query, recipe=recipe, form=form) + + if request.method == 'POST': + if 'deleterecipe' in request.form: + + id = recipe['id'] - r.table('recipes').get(id).delete().run(g.rdb_conn) - return redirect(url_for('index')) + r.table('recipes').get(id).delete().run(g.rdb_conn) + return redirect(url_for('index')) + else: + flash("Are you sure? Check the box") + return render_template("delete.html", query=query, recipe=recipe, form=form) if __name__ == '__main__': diff --git a/templates/delete.html b/templates/delete.html new file mode 100644 index 0000000..699aee2 --- /dev/null +++ b/templates/delete.html @@ -0,0 +1,88 @@ + + + + + + + Recipes + + + + + + + + + + + + + +
+
+
+

Delete {{recipe.title}}

+
+
+
+
+
+

Delete

+
+
+ + +
+ {{form.hidden_tag()}} +

Delete? {{form.deleterecipe}}

+ + +
+ +{% with messages = get_flashed_messages() %} + {% if messages %} +
    + {% for message in messages %} +
  • {{ message }}
  • + {% endfor %} +
+ {% endif %} + +{% endwith %} + + +
+
+
+
+ + + diff --git a/templates/edit.html b/templates/edit.html index 77217e7..7a831dd 100644 --- a/templates/edit.html +++ b/templates/edit.html @@ -14,11 +14,32 @@ -