diff --git a/src/config.py b/src/config.py index 2c4c25d..4ab3e73 100644 --- a/src/config.py +++ b/src/config.py @@ -10,3 +10,6 @@ class TaskStatus(Enum): NOT_STARTED = "Not Started" IN_PROGRESS = "In Progress" COMPLETED = "Completed" + + +TASK_STATUS_LIST = [status.value for status in TaskStatus] \ No newline at end of file diff --git a/src/forms/task_form.py b/src/forms/task_form.py new file mode 100644 index 0000000..6b99702 --- /dev/null +++ b/src/forms/task_form.py @@ -0,0 +1,17 @@ +from flask_wtf import FlaskForm +from wtforms import StringField, SubmitField, SelectField +from wtforms.validators import DataRequired + +from src.config import TaskStatus + + +class AddTaskForm(FlaskForm): + + title = StringField("Title:", validators=[DataRequired()]) + description = StringField("Description:", validators=[DataRequired()]) + status = SelectField( + "Status:", + choices=[(status.value, status.value) for status in TaskStatus], + validators=[DataRequired()] + ) + submit = SubmitField("Create Task") diff --git a/src/main.py b/src/main.py index aedf260..802c8e8 100644 --- a/src/main.py +++ b/src/main.py @@ -1,8 +1,9 @@ from flask import Flask, flash, redirect, render_template, request, url_for from flask_login import LoginManager, login_required, login_user +from src.forms.task_form import AddTaskForm from src.forms.user_forms import RegisterForm, LogInForm -from src.models import Base, SessionLocal, Users, engine +from src.models import Base, SessionLocal, Tasks, Users, engine from src.repository.users_repository import UsersRepository from src.repository.tasks_repository import TasksRespository from src.security import generate_password_hash @@ -99,5 +100,42 @@ def view_tasks(user_id): return render_template("view_tasks.html", tasks=tasks) +@app.route("/add_task/", methods=["GET", "POST"]) +@login_required +def add_task(user_id): + + # Print to confirm function entry + print("Entered add_task function") + + # Print user_id to confirm the URL parameter is being received correctly + print(f"Received user_id: {user_id}") + + + form = AddTaskForm() + + if form.validate_on_submit(): + + print("Form was submitted and validated successfully") + + + title = form.title.data + description = form.description.data + status = form.status.data + print(f"Form Data - Title: {title}, Description: {description}, Status: {status}") + + + session = SessionLocal() + task_repo = TasksRespository(session) + + task = Tasks(title=title, description=description, status=status, user_id=user_id) + task_repo.add_task(task) + session.close() + + flash("Task successfully created.", "success") + return redirect(url_for("view_tasks", user_id=user_id)) + + return render_template("add_task.html", form=form, user_id=user_id) + + if __name__ == "__main__": app.run(debug=True, port=5001) diff --git a/static/css/styles.css b/static/css/styles.css index 5933188..5c4a0aa 100644 --- a/static/css/styles.css +++ b/static/css/styles.css @@ -78,3 +78,7 @@ body { .styled-table tr:hover { background-color: #e0e0e0; /* Soft hover effect */ } + +.btn-thin { + padding: 8px 30px; +} \ No newline at end of file diff --git a/templates/add_task.html b/templates/add_task.html new file mode 100644 index 0000000..e22643f --- /dev/null +++ b/templates/add_task.html @@ -0,0 +1,39 @@ +{% extends "base.html" %} + +{% block content %} + + +
+
+
+

Add a Task to Your ToDo List

+
+
+ {{ form.hidden_tag() }} +
+ {{ form.title.label }} + {{ form.title(class="form-control") }} +
+
+ {{ form.description.label }} + {{ form.description(class="form-control") }} +
+
+ {{ form.status.label }} + {{ form.status(class="form-control") }} +
+
+ +
+
+
+
+{% endblock %} \ No newline at end of file