Upload files to "static"
This commit is contained in:
commit
5a81d86e80
45
static/index.html
Normal file
45
static/index.html
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Aplikacja To-Do</title>
|
||||||
|
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='styles.css') }}">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>Aplikacja To-Do</h1>
|
||||||
|
|
||||||
|
<h2>Zadania</h2>
|
||||||
|
<ul>
|
||||||
|
{% for task in tasks %}
|
||||||
|
<li>
|
||||||
|
{{ task[1] }}
|
||||||
|
<form action="{{ url_for('delete', task_id=task[0]) }}" method="post">
|
||||||
|
<button type="submit">Usuń</button>
|
||||||
|
</form>
|
||||||
|
<form action="{{ url_for('complete', task_id=task[0]) }}" method="post">
|
||||||
|
<button type="submit">Wykonane</button>
|
||||||
|
</form>
|
||||||
|
</li>
|
||||||
|
{% endfor %}
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<h2>Wykonane zadania</h2>
|
||||||
|
<ul>
|
||||||
|
{% for task in completed_tasks %}
|
||||||
|
<li>{{ task[1] }}
|
||||||
|
<form action="{{ url_for('delete', task_id=task[0]) }}" method="post">
|
||||||
|
<button type="submit">Usuń</button>
|
||||||
|
</form>
|
||||||
|
</li>
|
||||||
|
{% endfor %}
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<h2>Dodaj nowe zadanie</h2>
|
||||||
|
<form action="{{ url_for('add') }}" method="post">
|
||||||
|
<label for="task">Wpisz Zadanie:</label>
|
||||||
|
<input type="text" id="task" name="task" required><br><br>
|
||||||
|
<button type="submit">Dodaj zadanie</button>
|
||||||
|
</form>
|
||||||
|
</body>
|
||||||
|
</html>
|
2
static/instalacja.txt
Normal file
2
static/instalacja.txt
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
Flask==2.0.2
|
||||||
|
sqlite3
|
13
static/instrukcja
Normal file
13
static/instrukcja
Normal file
@ -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
|
||||||
|
|
93
static/main.py
Normal file
93
static/main.py
Normal file
@ -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/<int:task_id>', methods=['POST'])
|
||||||
|
def update(task_id):
|
||||||
|
task = request.form['task']
|
||||||
|
update_task(task_id, task)
|
||||||
|
return redirect(url_for('index'))
|
||||||
|
|
||||||
|
@app.route('/delete/<int:task_id>', methods=['POST'])
|
||||||
|
def delete(task_id):
|
||||||
|
delete_task(task_id)
|
||||||
|
return redirect(url_for('index'))
|
||||||
|
|
||||||
|
@app.route('/complete/<int:task_id>', methods=['POST'])
|
||||||
|
def complete(task_id):
|
||||||
|
complete_task(task_id)
|
||||||
|
return redirect(url_for('index'))
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
app.run(debug=True)
|
||||||
|
|
BIN
static/todo.db
Normal file
BIN
static/todo.db
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user