commit 5a81d86e806680b3cd48df6233b6b125168496e6 Author: s490133 Date: Sun Jun 23 17:35:47 2024 +0200 Upload files to "static" 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 0000000..0ecc3d7 Binary files /dev/null and b/static/todo.db differ