From 5a81d86e806680b3cd48df6233b6b125168496e6 Mon Sep 17 00:00:00 2001 From: s490133 Date: Sun, 23 Jun 2024 17:35:47 +0200 Subject: [PATCH] Upload files to "static" --- static/index.html | 45 ++++++++++++++++++++ static/instalacja.txt | 2 + static/instrukcja | 13 ++++++ static/main.py | 93 ++++++++++++++++++++++++++++++++++++++++++ static/todo.db | Bin 0 -> 12288 bytes 5 files changed, 153 insertions(+) create mode 100644 static/index.html create mode 100644 static/instalacja.txt create mode 100644 static/instrukcja create mode 100644 static/main.py create mode 100644 static/todo.db diff --git a/static/index.html b/static/index.html new file mode 100644 index 0000000..c3043d8 --- /dev/null +++ b/static/index.html @@ -0,0 +1,45 @@ + + + + + + Aplikacja To-Do + + + +

Aplikacja To-Do

+ +

Zadania

+ + +

Wykonane zadania

+ + +

Dodaj nowe zadanie

+
+ +

+ +
+ + diff --git a/static/instalacja.txt b/static/instalacja.txt new file mode 100644 index 0000000..49dc094 --- /dev/null +++ b/static/instalacja.txt @@ -0,0 +1,2 @@ +Flask==2.0.2 +sqlite3 diff --git a/static/instrukcja b/static/instrukcja new file mode 100644 index 0000000..08bf069 --- /dev/null +++ b/static/instrukcja @@ -0,0 +1,13 @@ + +1przejdz do + + cd aplikacja + +2 zainstaluj + pip install -r instalacja.txt +3 odpal funkcje + python main1.py +4 w przeglądarce wpisz + + http://localhost:5000 + diff --git a/static/main.py b/static/main.py new file mode 100644 index 0000000..b669336 --- /dev/null +++ b/static/main.py @@ -0,0 +1,93 @@ +from flask import Flask, render_template, request, redirect, url_for +import sqlite3 + +app = Flask(__name__) + +def initialize_database(): + conn = sqlite3.connect('todo.db') + c = conn.cursor() + c.execute('''CREATE TABLE IF NOT EXISTS tasks + (id INTEGER PRIMARY KEY AUTOINCREMENT, + task TEXT NOT NULL, + completed INTEGER DEFAULT 0)''') + conn.commit() + conn.close() + +def add_task(task): + conn = sqlite3.connect('todo.db') + c = conn.cursor() + c.execute("INSERT INTO tasks (task) VALUES (?)", (task,)) + conn.commit() + conn.close() + +def delete_task(task_id): + conn = sqlite3.connect('todo.db') + c = conn.cursor() + c.execute("DELETE FROM tasks WHERE id=?", (task_id,)) + conn.commit() + conn.close() + +def view_tasks(): + conn = sqlite3.connect('todo.db') + c = conn.cursor() + c.execute("SELECT * FROM tasks WHERE completed=0") + tasks = c.fetchall() + conn.close() + return tasks + +def view_tasks_complited(): + conn = sqlite3.connect('todo.db') + c = conn.cursor() + c.execute("SELECT * FROM tasks WHERE completed=1") + tasks = c.fetchall() + conn.close() + return tasks + +def update_task(task_id, task=None): + conn = sqlite3.connect('todo.db') + c = conn.cursor() + if task: + c.execute("UPDATE tasks SET task=? WHERE id=?", (task, task_id)) + conn.commit() + conn.close() + +def complete_task(task_id): + conn = sqlite3.connect('todo.db') + c = conn.cursor() + c.execute("UPDATE tasks SET completed=? WHERE id=?", (1, task_id)) + conn.commit() + conn.close() + +initialize_database() + +@app.route('/') +def index(): + tasks = view_tasks() + completed_tasks = view_tasks_complited() + return render_template('index.html', tasks=tasks, completed_tasks=completed_tasks) + +@app.route('/add', methods=['POST']) +def add(): + task = request.form['task'] + add_task(task) + return redirect(url_for('index')) + +@app.route('/update/', methods=['POST']) +def update(task_id): + task = request.form['task'] + update_task(task_id, task) + return redirect(url_for('index')) + +@app.route('/delete/', methods=['POST']) +def delete(task_id): + delete_task(task_id) + return redirect(url_for('index')) + +@app.route('/complete/', methods=['POST']) +def complete(task_id): + complete_task(task_id) + return redirect(url_for('index')) + +if __name__ == '__main__': + app.run(debug=True) + diff --git a/static/todo.db b/static/todo.db new file mode 100644 index 0000000000000000000000000000000000000000..0ecc3d7760b4ccec71afd6f6954f33d1de222410 GIT binary patch literal 12288 zcmeI&zfZzI6bJA-@OOeWES*f=2!R-klbcmegO-Z*h%%9ro`%Q|v1M`7Kh?!JGO&BC zX_PKbEarR3_3qmDUXxF!m-PC|?MIsK$In9*(E;0GoUUOh7Qz-9VX6J`Tz} z>y3v`10Cs~*Ve_U({?4*%5iVbtr@ds)~EHpybplN5P$##AOHafKmY;|fB*y_009Ur zRe;j!cDyMRSJ^Jxcu|2G_4WRD|37EeJdMH%0SG_<0uX=z1Rwwb2tWV=5P-nH5ZL5- Kn