Skip to content

Commit

Permalink
Fully working deletes and headers with buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
z3ugma committed Jan 6, 2015
1 parent 1affa35 commit 9b39125
Show file tree
Hide file tree
Showing 4 changed files with 144 additions and 13 deletions.
25 changes: 20 additions & 5 deletions colorpicker.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,18 @@ 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):
title = TextField('title', validators = [Required()])
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__)
Expand Down Expand Up @@ -225,19 +230,29 @@ def edit(query):

return redirect(url_for('recipe', query=slug))

@app.route('/<query>/delete', methods = ['GET'])
@app.route('/<query>/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__':
Expand Down
88 changes: 88 additions & 0 deletions templates/delete.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Recipes</title>
<script src="http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.js"></script>
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css"></style>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>

<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css">


<link rel="stylesheet" type="text/css" href="http://fonts.googleapis.com/css?family=Ubuntu">
<style>

body {
font-family: 'Ubuntu', serif;
background-color: #E498AF;

}

.panel-primary{
border-color: #721330;
font-size:150%;

}

.panel-primary > .panel-heading {
background-color: #721330;
border-color: #721330;

}

a {
color: #4C0017;
}

a:focus, a:hover {
color: #4C0017;
}

</style>
</head>
<body>


<div class="container">
<div class="col-md-12">
<div class="header" style="background-color: #4C0017; color: #E498AF; margin-bottom: 20px; padding: 20px 10px;">
<h1>Delete {{recipe.title}}</h1>
</div>
</div>
<div class="col-md-12">
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title">Delete</h3>
</div>
<div class="panel-body">


<form action="" role="form" method="POST" name="delete_task">
{{form.hidden_tag()}}
<h3> Delete? {{form.deleterecipe}} </h3>

<input type="submit" value="Update Recipe" class="btn btn-default btn-md">
</form>

{% with messages = get_flashed_messages() %}
{% if messages %}
<ul class=flashes>
{% for message in messages %}
<li>{{ message }}</li>
{% endfor %}
</ul>
{% endif %}

{% endwith %}


</div>
</div>
</div>
</div>

</body>
</html>
38 changes: 33 additions & 5 deletions templates/edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,32 @@

<link rel="stylesheet" type="text/css" href="http://fonts.googleapis.com/css?family=Ubuntu">

<style>
body {
font-family: 'Ubuntu', serif;
<style> body {
font-family: 'Ubuntu', serif;
background-color: #A66FA6;

}

.panel-primary{
border-color: #609732;
font-size:150%;

}

.panel-primary > .panel-heading {
background-color: #609732;
border-color: #609732;

}

a {
color: #370037;
}

a:focus, a:hover {
color: #370037;
}

}
textarea {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
Expand All @@ -37,7 +58,14 @@

<div class="row">
<div class="col-md-12">
<h1>Edit {{recipe.title}}</h1>
<div class="header" style="background-color: #370037; color: #A66FA6; margin-bottom: 20px; padding: 20px 10px;">
<h1>Edit {{recipe.title}}

<a href="/" style = "margin-left: 15px;" class="btn btn-default btn-lg pull-right" role="button">Home</a>
<a href="/{{recipe.slug}}" class="btn btn-default btn-lg pull-right" role="button">Recipe</a>

</h1></div>


<div class="panel panel-primary">
<div class="panel-heading">
Expand Down
6 changes: 3 additions & 3 deletions templates/recipes.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@
<div class="col-md-12">
<div class="header" style="background-color: rgb{{avg[0]}}; color: rgb{{avg[3]}}; margin-bottom: 20px; padding: 20px 10px;">
<h1>{{title}}

<a href="{{url_for('edit' , query=query) }}" style="margin-left: 15px;" class="btn btn-default btn-lg pull-right" role="button">Edit</a>
<a href="{{url_for('delete' , query=query) }}" class="btn btn-default btn-lg pull-right" role="button">Delete</a>
<a href="{{url_for('edit' , query=query) }}" style="margin-left: 15px; " class="btn btn-default btn-lg pull-right" role="button">Edit</a>
<a href="/" class="btn btn-default btn-lg pull-right" role="button">Home</a>
</h1>
</div>
Expand Down Expand Up @@ -109,7 +109,7 @@ <h3 class="panel-title"></h3> Directions </h3>
<div class="img-wrapper"> <img src="{{i}}" /></div>
{% endfor%}
</div>
<a href="{{url_for('delete' , query=query) }}" style="margin-left: 15px;" class="btn btn-default btn-lg pull-right" role="button">Delete</a>

</div>
</body>
</html>

0 comments on commit 9b39125

Please sign in to comment.