diff --git a/app.py b/app.py index 4b6ccca..3b66128 100644 --- a/app.py +++ b/app.py @@ -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 @@ -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("/") @@ -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")) @@ -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")) @@ -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) diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..7505681 --- /dev/null +++ b/requirements.txt @@ -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 diff --git a/templates/base.html b/templates/base.html index b40815c..e9aa20f 100644 --- a/templates/base.html +++ b/templates/base.html @@ -14,11 +14,23 @@

To Do App

-
+

+ {% with messages = get_flashed_messages(with_categories=true) %} + {% if messages %} + + {% endif %} + {% endwith %} +
@@ -26,11 +38,11 @@

To Do App

{% for todo in todo_list %}
-

{{todo.id }} | {{ todo.title }}

- {% if todo.complete == False %} +

{{todo.id }} | {{ todo.title }} - {{todo.created_at}}

Not Complete {% else %} +

{{todo.id }} | {{ todo.title }} - {{todo.created_at}}

Completed {% endif %} @@ -41,4 +53,4 @@

To Do App

- \ No newline at end of file +