From 4d414c18e32e58b31cf938b2e5b3f83753cf457a Mon Sep 17 00:00:00 2001 From: Aayushi Varma <59158445+aayuv17@users.noreply.github.com> Date: Thu, 8 Oct 2020 19:50:08 +0530 Subject: [PATCH 1/6] create app.py --- To-Do-List/app.py | 70 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 To-Do-List/app.py diff --git a/To-Do-List/app.py b/To-Do-List/app.py new file mode 100644 index 000000000..ef5eb9886 --- /dev/null +++ b/To-Do-List/app.py @@ -0,0 +1,70 @@ +from flask import Flask, render_template, request, flash, redirect, url_for +from flask import get_flashed_messages, session +from flask_sqlalchemy import SQLAlchemy +from datetime import datetime + +app = Flask(__name__) +app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite://' +app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False +app.secret_key = 'any random secret' +db = SQLAlchemy(app) + + +class TODO(db.Model): + id = db.Column(db.Integer, primary_key=True) + content = db.Column(db.String(200), nullable=False) + date_created = db.Column(db.DateTime, default=datetime.utcnow) + + def __repr__(self): + return '' % self.id + + +@app.route('/', methods=['POST', 'GET']) +def hello(): + db.create_all() + if request.method == 'POST': + task = request.form['content'] + new_task = TODO(content=task) + try: + db.session.add(new_task) + db.session.commit() + flash('Successfully added!') + return redirect('/') + except: + flash('An error occurred') + return redirect('/') + else: + tasks = TODO.query.order_by(TODO.date_created).all() + return render_template("toDoListTemplate.html", tasks=tasks) + + +@app.route('/delete/') +def delete(id): + task = TODO.query.get_or_404(id) + try: + db.session.delete(task) + db.session.commit() + flash('Successfully deleted') + return redirect('/') + except: + flash('An error occurred') + return redirect('/') + + +@app.route('/modify/', methods=['POST', 'GET']) +def modify(id): + task = TODO.query.get_or_404(id) + if request.method == 'POST': + task.content = request.form['content'] + try: + db.session.commit() + flash("Successfully updated") + return redirect('/') + except: + flash("An error occurred") + return redirect('/') + else: + return render_template("toDoListTemplate.html", tasks=tasks) + +if __name__ == '__main__': + app.run(debug=True) From 3290d53d751dd0a8eeb25a6ddb02cc0480eedd5d Mon Sep 17 00:00:00 2001 From: Aayushi Varma <59158445+aayuv17@users.noreply.github.com> Date: Thu, 8 Oct 2020 19:51:37 +0530 Subject: [PATCH 2/6] create html file --- To-Do-List/templates/toDoListTemplate.html | 91 ++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 To-Do-List/templates/toDoListTemplate.html diff --git a/To-Do-List/templates/toDoListTemplate.html b/To-Do-List/templates/toDoListTemplate.html new file mode 100644 index 000000000..9c40575fa --- /dev/null +++ b/To-Do-List/templates/toDoListTemplate.html @@ -0,0 +1,91 @@ + + + + {% block head %} + + + + + + + + {% endblock %} + + + {% block body %} +
+ {% with msg=get_flashed_messages() %} + {% if msg %} + {% for message in msg %} + {{ message }} +
+ {% endfor %} + {% endif %} + {% endwith %} +

To-Do List

+
+
+ + +
+
+ + {% if tasks %} + + + + + + {% for task in tasks %} + + + + + + + {% endfor %} + {% else %} + No items in list + {% endif %} +
Task Added Actions
{{ task.content }} {{ task.date_created.date() }} + Delete +
+ Update +
+
+
+
+ + {% endblock %} + + From 0fd7bf8047cd662acefde564b8c37bac7ea4cce0 Mon Sep 17 00:00:00 2001 From: Aayushi Varma <59158445+aayuv17@users.noreply.github.com> Date: Thu, 8 Oct 2020 19:52:13 +0530 Subject: [PATCH 3/6] create styles.css --- To-Do-List/static/styles.css | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 To-Do-List/static/styles.css diff --git a/To-Do-List/static/styles.css b/To-Do-List/static/styles.css new file mode 100644 index 000000000..ea478413e --- /dev/null +++ b/To-Do-List/static/styles.css @@ -0,0 +1,19 @@ +.content{ + text-align: center; + display: inline-block; + overflow-x: auto; +} +body{ + font-family:Abel; + text-align: center; + background-color:azure; +} +#modifyTask{ + text-align:left; +} +a:link { + color: blue; +} +a:visited{ + color: blue; +} From d46c906646300e3dcd14c622d8626bc883aa8e40 Mon Sep 17 00:00:00 2001 From: Aayushi Varma <59158445+aayuv17@users.noreply.github.com> Date: Thu, 8 Oct 2020 20:01:48 +0530 Subject: [PATCH 4/6] create README.md --- To-Do-List/README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 To-Do-List/README.md diff --git a/To-Do-List/README.md b/To-Do-List/README.md new file mode 100644 index 000000000..a7721732f --- /dev/null +++ b/To-Do-List/README.md @@ -0,0 +1,10 @@ +# To-Do List +A to-do list application made using Python's flask framework + +# Usage +Run the script in the terminal and access http://localhost:5000 in your web browser to view the application + +# Requirements +- install the flask module as: pip install flask +- install the flask_sqlalchemy module as: pip install flask_sqlalchemy +- install sqlite if required From 031efa1e6f7ca43c8e511889705bd188d01667fb Mon Sep 17 00:00:00 2001 From: Aayushi Varma <59158445+aayuv17@users.noreply.github.com> Date: Thu, 8 Oct 2020 21:36:22 +0530 Subject: [PATCH 5/6] updated app.py --- To-Do-List/app.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/To-Do-List/app.py b/To-Do-List/app.py index ef5eb9886..a5a2a11e6 100644 --- a/To-Do-List/app.py +++ b/To-Do-List/app.py @@ -1,5 +1,4 @@ -from flask import Flask, render_template, request, flash, redirect, url_for -from flask import get_flashed_messages, session +from flask import Flask, render_template, request, flash, redirect from flask_sqlalchemy import SQLAlchemy from datetime import datetime @@ -30,7 +29,7 @@ def hello(): db.session.commit() flash('Successfully added!') return redirect('/') - except: + except Exception: flash('An error occurred') return redirect('/') else: @@ -46,7 +45,7 @@ def delete(id): db.session.commit() flash('Successfully deleted') return redirect('/') - except: + except Exception: flash('An error occurred') return redirect('/') @@ -60,11 +59,13 @@ def modify(id): db.session.commit() flash("Successfully updated") return redirect('/') - except: + except Exception: flash("An error occurred") return redirect('/') else: - return render_template("toDoListTemplate.html", tasks=tasks) + return render_template("toDoListTemplate.html", tasks=task) + if __name__ == '__main__': app.run(debug=True) + From d8a32b56bea20bd60a6f1a48f5e5bb573c5b4b2b Mon Sep 17 00:00:00 2001 From: Aayushi Varma <59158445+aayuv17@users.noreply.github.com> Date: Thu, 8 Oct 2020 21:39:21 +0530 Subject: [PATCH 6/6] updated app.py --- To-Do-List/app.py | 1 - 1 file changed, 1 deletion(-) diff --git a/To-Do-List/app.py b/To-Do-List/app.py index a5a2a11e6..310807b10 100644 --- a/To-Do-List/app.py +++ b/To-Do-List/app.py @@ -68,4 +68,3 @@ def modify(id): if __name__ == '__main__': app.run(debug=True) -