Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions app.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from flask import Flask, render_template, request, redirect, url_for
rom flask import Flask, render_template, request, redirect, url_for, flash
from flask_sqlalchemy import SQLAlchemy
import os
from datetime import date , datetime

app = Flask(__name__)

app.secret_key = os.urandom(30)
# /// = relative path, //// = absolute path
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///db.sqlite'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
Expand All @@ -13,6 +15,9 @@ class Todo(db.Model):
id = db.Column(db.Integer, primary_key=True)
title = db.Column(db.String(100))
complete = db.Column(db.Boolean)
now = datetime.today()
dt_string = now.strftime('%Y-%m-%d %H:%M:%S')
created_at = db.Column(db.String, nullable=False, default=dt_string)


@app.route("/")
Expand All @@ -24,9 +29,12 @@ def home():
@app.route("/add", methods=["POST"])
def add():
title = request.form.get("title")
new_todo = Todo(title=title, complete=False)
db.session.add(new_todo)
db.session.commit()
if title == '':
flash(message='Input your Todo!', category='red')
else:
new_todo = Todo(title=title, complete=False)
db.session.add(new_todo)
db.session.commit()
return redirect(url_for("home"))


Expand All @@ -35,6 +43,7 @@ def update(todo_id):
todo = Todo.query.filter_by(id=todo_id).first()
todo.complete = not todo.complete
db.session.commit()
flash(message='Todo successfully updated!', category='green')
return redirect(url_for("home"))


Expand All @@ -43,8 +52,10 @@ def delete(todo_id):
todo = Todo.query.filter_by(id=todo_id).first()
db.session.delete(todo)
db.session.commit()
flash(message='Todo successfully deleted!', category='green')
return redirect(url_for("home"))


if __name__ == "__main__":
db.create_all()
app.run(debug=True)
47 changes: 47 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
beautifulsoup4==4.11.1
certifi==2021.10.8
charset-normalizer==2.1.0
click==8.1.3
colorama==0.4.5
distlib==0.3.4
dnspython==2.2.1
dominate==2.5.2
email-validator==1.2.1
filelock==3.4.2
Flask==2.2.2
Flask-Bootstrap==3.3.7.1
Flask-Login==0.6.2
Flask-SQLAlchemy==2.5.1
Flask-WTF==0.14.3
greenlet==1.1.2
gTTS==2.2.4
idna==3.3
importlib-metadata==4.12.0
itsdangerous==2.1.2
jason==0.1.7
Jinja2==3.1.2
MarkupSafe==2.1.1
numpy==1.23.0
pandas==1.4.3
Pillow==9.2.0
pipenv==2022.1.8
platformdirs==2.4.1
playsound==1.3.0
PyJWT==2.4.0
pyperclip==1.8.2
python-dateutil==2.8.2
pytz==2022.1
requests==2.28.1
six==1.16.0
soupsieve==2.3.2.post1
SQLAlchemy==1.4.40
ttkthemes==3.2.2
twilio==7.12.0
urllib3==1.26.10
virtualenv==20.13.0
virtualenv-clone==0.5.7
visitor==0.1.3
Werkzeug==2.2.2
window==0.0.3
WTForms==2.3.3
zipp==3.8.1
20 changes: 16 additions & 4 deletions templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,35 @@
<div style="margin-top: 50px;" class="ui container">
<h1 class="ui center aligned header">To Do App</h1>

<form class="ui form" action="/add" method="post">
<form class="ui form" action="{{url_for('add')}}" method="post">
<div class="field">
<label>Todo Title</label>
<input type="text" name="title" placeholder="Enter Todo..."><br>
</div>
{% with messages = get_flashed_messages(with_categories=true) %}
{% if messages %}
<ul>
{% for category, message in messages %}
<li style="color: {{ category }};">
<strong>{{ message }}</strong>
</li>
{% endfor %}
</ul>
{% endif %}
{% endwith %}

<button class="ui blue button" type="submit">Add</button>
</form>

<hr>

{% for todo in todo_list %}
<div class="ui segment">
<p class="ui big header">{{todo.id }} | {{ todo.title }}</p>

{% if todo.complete == False %}
<p class="ui big header">{{todo.id }} | {{ todo.title }} - {{todo.created_at}}</p>
<span class="ui gray label">Not Complete</span>
{% else %}
<p class="ui big header"><s>{{todo.id }} | {{ todo.title }} - {{todo.created_at}}</s></p>
<span class="ui green label">Completed</span>
{% endif %}

Expand All @@ -41,4 +53,4 @@ <h1 class="ui center aligned header">To Do App</h1>
</div>
</body>

</html>
</html>