Skip to content

Commit

Permalink
developed CreateTaskForm and frontend functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
Morgan-Sell committed Nov 14, 2024
1 parent a046ba3 commit 85d59cf
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
17 changes: 17 additions & 0 deletions src/forms/task_form.py
Original file line number Diff line number Diff line change
@@ -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")
40 changes: 39 additions & 1 deletion src/main.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -99,5 +100,42 @@ def view_tasks(user_id):
return render_template("view_tasks.html", tasks=tasks)


@app.route("/add_task/<int:user_id>", 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)
4 changes: 4 additions & 0 deletions static/css/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,7 @@ body {
.styled-table tr:hover {
background-color: #e0e0e0; /* Soft hover effect */
}

.btn-thin {
padding: 8px 30px;
}
39 changes: 39 additions & 0 deletions templates/add_task.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{% extends "base.html" %}

{% block content %}
<style>
/* Full-page background image */
body {
background-image: url("{{ url_for('static', filename='img/background.png') }}");
background-size: cover;
background-position: center;
background-attachment: fixed;
}
</style>

<div class="d-flex justify-content-center align-items-center" style="min-height: 90vh;">
<div class="card p-4" style="width: 700px; border-radius: 15px; box-shadow: 0px 4px 12px rgba(0, 0, 0, 0.1);">
<div class="text-center mb-4">
<h2 class="mt-2" style="font-family: 'Lobster', cursive; font-size: 2rem; color: #333;">Add a Task to Your ToDo List</h2>
</div>
<form method="POST" action="{{ url_for('add_task', user_id=user_id) }}">
{{ form.hidden_tag() }}
<div class="form-group">
{{ form.title.label }}
{{ form.title(class="form-control") }}
</div>
<div class="form-group">
{{ form.description.label }}
{{ form.description(class="form-control") }}
</div>
<div class="form-group">
{{ form.status.label }}
{{ form.status(class="form-control") }}
</div>
<div class="text-center">
<button type="submit" class="btn btn-primary btn-thin mt-4">Create Task</button>
</div>
</form>
</div>
</div>
{% endblock %}

0 comments on commit 85d59cf

Please sign in to comment.