commit 7397020d641c8c74e74a07588bee43806353be3b Author: Lidia Wojciechowska Date: Mon Jun 17 10:52:23 2024 +0200 Dodano nowe pliki diff --git a/README.md b/README.md new file mode 100644 index 0000000..3ca64cc --- /dev/null +++ b/README.md @@ -0,0 +1,11 @@ +# OPIS INSTALACJI PROJEKTU - Lidia Wojciechowska +Cały folder należy otworzyć w visual studio code, w terminalu wpisać takie polecenia jak: + + +pip install flask +pip install pyodbc +pip install configparser +Należy rowniez ustawic swoje dane w pliku 'dane.ini', aby zobaczyc na serwerze w swojej bazie (mssql) listę todo. +następnie run and debug +w trakcie debuggowania nalezy wcisnąć ctrl+ kliknąć w link http://localhost:4449 . +powinna działać aplikacja \ No newline at end of file diff --git a/abcd.css b/abcd.css new file mode 100644 index 0000000..145032a --- /dev/null +++ b/abcd.css @@ -0,0 +1,98 @@ +/* styles.css */ + +body { + background-color: lightblue; + color: #333; + font-family: Monospace; + margin: 20px; +} + +.container { + max-width: 800px; + margin: 0 auto; +} + +.header { + background-color: #f2c538; + color: #333; + padding: 10px; + text-align: center; +} + +.task { + margin-bottom: 10px; + padding: 10px; + border: 1px solid #ccc; + background-color: #fff; +} + +.task:hover { + background-color: #f9f9f9; +} + +.task .timestamp { + font-size: 12px; + color: #666; +} + +.btn { + background-color: #f2c538; + color: #333; + border: none; + padding: 8px 16px; + cursor: pointer; + text-decoration: none; + display: inline-block; + margin-right: 5px; +} + +.btn:hover { + background-color: #e0b52f; +} + +.form-container { + margin-top: 20px; +} + +.form-container input[type="text"] { + width: calc(100% - 100px); + padding: 10px; + margin-right: 10px; + font-size: 14px; +} + +.form-container input[type="submit"] { + background-color: #f2c538; + color: #333; + border: none; + padding: 8px 16px; + cursor: pointer; + font-size: 14px; +} + +.form-container input[type="submit"]:hover { + background-color: #e0b52f; +} + +.search-container { + margin-bottom: 20px; +} + +.search-container input[type="text"] { + width: 200px; + padding: 8px; + font-size: 14px; +} + +.search-container input[type="submit"] { + background-color: #f2c538; + color: #333; + border: none; + padding: 6px 12px; + cursor: pointer; + font-size: 14px; +} + +.search-container input[type="submit"]:hover { + background-color: #e0b52f; +} diff --git a/app.py b/app.py new file mode 100644 index 0000000..4f13cdb --- /dev/null +++ b/app.py @@ -0,0 +1,125 @@ +from flask import Flask, render_template, request, redirect, url_for +import pyodbc +import configparser +from datetime import datetime + +app = Flask(__name__, template_folder='.',static_folder='') + +class TodoList: + def __init__(self): + config = configparser.ConfigParser() + config.read('dane.ini') + + mssql_config = config['mssql'] + + self.conn = pyodbc.connect( + f"DRIVER={mssql_config['driver']};" + f"SERVER={mssql_config['server']};" + f"DATABASE={mssql_config['database']};" + f"UID={mssql_config['uid']};" + f"PWD={mssql_config['pwd']}" + ) + self.create_table() + + def create_table(self): + with self.conn.cursor() as cursor: + cursor.execute(''' + IF NOT EXISTS (SELECT * FROM sysobjects WHERE name='tasks' and xtype='U') + CREATE TABLE tasks ( + id INT PRIMARY KEY IDENTITY(1,1), + description NVARCHAR(255) NOT NULL + ) + ''') + self.conn.commit() + + def add_task(self, description): + description_with_timestamp = self.add_timestamp(description) + with self.conn.cursor() as cursor: + cursor.execute('INSERT INTO tasks (description) VALUES (?)', (description_with_timestamp,)) + self.conn.commit() + + def remove_task(self, task_id): + with self.conn.cursor() as cursor: + cursor.execute('DELETE FROM tasks WHERE id = ?', (task_id,)) + self.conn.commit() + + def edit_task(self, task_id, new_description): + new_description_with_timestamp = self.add_timestamp(new_description) + with self.conn.cursor() as cursor: + cursor.execute('UPDATE tasks SET description = ? WHERE id = ?', (new_description_with_timestamp, task_id)) + self.conn.commit() + + def get_tasks(self): + with self.conn.cursor() as cursor: + cursor.execute('SELECT id, description FROM tasks') + tasks = [] + for row in cursor.fetchall(): + task_dict = { + 'id': row.id, + 'description': row.description + } + tasks.append(task_dict) + return tasks + + def get_task(self, task_id): + with self.conn.cursor() as cursor: + cursor.execute('SELECT id, description FROM tasks WHERE id = ?', (task_id,)) + return cursor.fetchone() + + def add_timestamp(self, description): + return f"{description} (added/edited on {datetime.now().strftime('%Y-%m-%d %H:%M:%S')})" + + + def __del__(self): + self.conn.close() + +todo_list = TodoList() + +@app.route('/') +def index(): + tasks = todo_list.get_tasks() + return render_template('todo_list.html', tasks=tasks) + +@app.route('/add', methods=['GET', 'POST']) +def add_task(): + if request.method == 'POST': + description = request.form['description'] + todo_list.add_task(description) + return redirect(url_for('index')) + return render_template('task_add.html') + +@app.route('/delete/') +def delete_task(task_id): + todo_list.remove_task(task_id) + return redirect(url_for('index')) + + + + +@app.route('/search', methods=['GET', 'POST']) +def search_tasks(): + if request.method == 'POST': + keyword = request.form['keyword'].lower() + tasks = todo_list.get_tasks() + matching_tasks = [task for task in tasks if keyword in task['description'].lower()] + return render_template('task_search.html', tasks=matching_tasks, keyword=request.form['keyword']) + return render_template('task_search.html') + +@app.route('/edit/', methods=['GET', 'POST']) +def edit_task(task_id): + task = todo_list.get_task(task_id) + if request.method == 'POST': + new_description = request.form['description'] + todo_list.edit_task(task_id, new_description) + return redirect(url_for('index')) + return render_template('task_edit.html', task=task) + +@app.route('/long') +def long_tasks(): + tasks = todo_list.get_tasks() + long_tasks = list(filter(lambda task: len(task['description']) > 60, tasks)) + return render_template('long.html', tasks=long_tasks) + + +if __name__ == '__main__': + app.run('localhost', 4449, debug=True) diff --git a/dane.ini b/dane.ini new file mode 100644 index 0000000..2b02294 --- /dev/null +++ b/dane.ini @@ -0,0 +1,8 @@ +[mssql] +driver=ODBC Driver 17 for SQL Server +server=mssql-2017.labs.wmi.amu.edu.pl +database=dbad_s490058 +uid=dbad_s490058 +pwd=MLJ8HKkKxJ + +#https://www.geeksforgeeks.org/flask-rendering-templates/ \ No newline at end of file diff --git a/long.html b/long.html new file mode 100644 index 0000000..b398d0e --- /dev/null +++ b/long.html @@ -0,0 +1,18 @@ + + + + + + Long Tasks + + + +

Long Tasks

+
    + {% for task in tasks %} +
  • {{ task.description }}
  • + {% endfor %} +
+ Back to TODO List + + diff --git a/opis_instalacji.txt b/opis_instalacji.txt new file mode 100644 index 0000000..28c013c --- /dev/null +++ b/opis_instalacji.txt @@ -0,0 +1,11 @@ +OPIS INSTALACJI PROJEKTU - Lidia Wojciechowska +Cały folder należy otworzyć w visual studio code, w terminalu wpisać takie polecenia jak: + + +pip install flask +pip install pyodbc +pip install configparser +Należy rowniez ustawic swoje dane w pliku 'dane.ini', aby zobaczyc na serwerze w swojej bazie listę todo. +następnie run and debug +w trakcie debuggowania nalezy wcisnąć ctrl+ kliknąć w link http://localhost:4449 . +powinna działać aplikacja \ No newline at end of file diff --git a/task_add.html b/task_add.html new file mode 100644 index 0000000..05d0be4 --- /dev/null +++ b/task_add.html @@ -0,0 +1,16 @@ + + + + Add Task + + + +

Add Task

+
+ + + +
+ Back to List + + diff --git a/task_edit.html b/task_edit.html new file mode 100644 index 0000000..77e0c0e --- /dev/null +++ b/task_edit.html @@ -0,0 +1,16 @@ + + + + Edit Task + + + +

Edit Task

+
+ + + +
+ Back to List + + diff --git a/task_search.html b/task_search.html new file mode 100644 index 0000000..af33eaa --- /dev/null +++ b/task_search.html @@ -0,0 +1,24 @@ + + + + Search Tasks + + + +

Search Tasks

+
+ + + +
+ Back to List + {% if keyword %} +

Search Results for "{{ keyword }}"

+
    + {% for task in tasks %} +
  • {{ task.description }} Edit Delete
  • + {% endfor %} +
+ {% endif %} + + diff --git a/todo_list.html b/todo_list.html new file mode 100644 index 0000000..d6ad604 --- /dev/null +++ b/todo_list.html @@ -0,0 +1,18 @@ + + + + TODO List + + + +

TODO List

+ Add Task + Search Tasks + Show Long Tasks +
    + {% for task in tasks %} +
  • {{ task.description }} Edit Delete
  • + {% endfor %} +
+ +