Skip to content

Commit c23fd71

Browse files
committed
Complete Task Toggle added, bootsrtap fixed, forms fixed, year shown in the footer fixed, docstring for views added
1 parent 50836d2 commit c23fd71

File tree

10 files changed

+51
-80
lines changed

10 files changed

+51
-80
lines changed

todo_project/db.sqlite3

0 Bytes
Binary file not shown.

todo_project/requirements.txt

Lines changed: 4 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,5 @@
1-
alembic==1.13.2
21
asgiref==3.8.1
3-
blinker==1.8.1
4-
certifi==2024.8.30
5-
charset-normalizer==3.3.2
6-
click==8.1.7
7-
colorama==0.4.6
8-
comtypes==1.4.7
9-
distlib==0.3.8
10-
dj-database-url==2.3.0
11-
Django==5.0.4
12-
filelock==3.16.1
13-
Flask==3.0.3
14-
Flask-Login==0.6.3
15-
Flask-Migrate==4.0.7
16-
Flask-SQLAlchemy==3.1.1
17-
greenlet==3.0.3
18-
gunicorn==23.0.0
19-
idna==3.10
20-
itsdangerous==2.2.0
21-
Jinja2==3.1.3
22-
Mako==1.3.5
23-
MarkupSafe==2.1.5
24-
mysql-connector-python==9.0.0
25-
packaging==24.1
26-
pillow==10.4.0
27-
pipenv==2024.1.0
28-
platformdirs==4.3.6
29-
psycopg2-binary==2.9.10
30-
PyAudio==0.2.14
31-
pygame==2.6.0
32-
pypiwin32==223
33-
pyttsx3==2.97
34-
pywin32==306
35-
requests==2.32.3
36-
SpeechRecognition==3.10.4
37-
SQLAlchemy==2.0.31
38-
sqlparse==0.5.0
39-
typing_extensions==4.12.2
40-
tzdata==2024.1
41-
urllib3==2.2.3
42-
virtualenv==20.26.6
43-
Werkzeug==3.0.2
44-
whitenoise==6.8.2
2+
Django==5.1.7
3+
django-bootstrap5==25.1
4+
sqlparse==0.5.3
5+
tzdata==2025.2

todo_project/todo_app/forms.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
class TaskForm(forms.ModelForm):
55
class Meta:
66
model = Task
7-
fields = ['title', 'description', 'completed']
7+
fields = ['title', 'description']

todo_project/todo_app/static/css/styles.css

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -97,15 +97,6 @@ h1, h2 {
9797
color: #777;
9898
}
9999

100-
.task-item .task-actions a {
101-
color: #007bff;
102-
margin-left: 10px;
103-
text-decoration: none;
104-
}
105-
106-
.task-item .task-actions a:hover {
107-
text-decoration: underline;
108-
}
109100

110101
.task-item .completed {
111102
background-color: #28a745;

todo_project/todo_app/templates/todo_app/add_task.html

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{% extends 'todo_app/base.html' %}
2+
{% load django_bootstrap5 %}
23

34
{% block title %}Add Task{% endblock %}
45

@@ -7,18 +8,7 @@
78
<h2 class="text-center mb-4" >Add New Task</h2>
89
<form method="post">
910
{% csrf_token %}
10-
<div class="mb-3">
11-
<label for="id_title" class="form-label">Task Title</label>
12-
<input type="text" name="title" class="form-control" id="id_title" value="{{ form.title.value }}" required>
13-
</div>
14-
<div class="mb-3">
15-
<label for="id_description" class="form-label">Task Description</label>
16-
<textarea name="description" class="form-control" id="id_description" rows="4" required>{{ form.description.value }}</textarea>
17-
</div>
18-
<div class="mb-3 form-check">
19-
<input type="checkbox" name="completed" class="form-check-input" id="id_completed" {% if form.completed.value %}checked{% endif %}>
20-
<label class="form-check-label" for="id_completed">Mark as Completed</label>
21-
</div>
11+
{% bootstrap_form form %}
2212
<button type="submit" class="btn btn-primary">Save Task</button>
2313
</form>
2414
<a href="{% url 'task_list' %}" class="btn btn-link">Back to Task List</a>
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,32 @@
11
{% load static %}
2+
{% load django_bootstrap5 %}
23

34
<!DOCTYPE html>
45
<html lang="en">
56
<head>
67
<meta charset="UTF-8">
78
<meta name="viewport" content="width=device-width, initial-scale=1.0">
89
<title>{% block title %}To-Do App{% endblock %}</title>
9-
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-KyZXEJx3v8cHqK6+IH5QkKePBf7yEKXes2on/cbWY2g8faKqbE0Vw+zMmiTt8lZ9" crossorigin="anonymous">
1010
<link rel="stylesheet" href="{% static 'css/styles.css' %}">
11+
{% bootstrap_css %}
1112
</head>
1213
<body>
1314
<header>
1415
<h1>{% block header %}To-Do List{% endblock %}</h1>
1516
</header>
1617

1718
<div class="container mt-5">
19+
{% bootstrap_messages %}
1820
{% block content %}
1921
{% endblock %}
2022
</div>
2123

2224
<br>
2325

2426
<footer>
25-
<p>&copy; 2024 Your To-Do List App | <a href="#">Privacy Policy</a></p>
27+
<p>&copy; {% now 'Y' %} Your To-Do List App | <a href="#">Privacy Policy</a></p>
2628
</footer>
2729

28-
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-pzjw8f+ua7Kw1TIq0K3k5T0q3QfD2wCxnt4qZbG3M8C5TpNjA3dH5XIQyS1d7VZl" crossorigin="anonymous"></script>
30+
{% bootstrap_javascript %}
2931
</body>
3032
</html>

todo_project/todo_app/templates/todo_app/task_list.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,14 @@ <h2 class="text-center mb-4">To-Do List</h2>
1616
<p class="task-description">{{ task.description }}</p>
1717
{% if task.completed %}
1818
<span class="completed">Completed</span>
19+
<a href="{% url 'mark_completed' task.pk %}" class="btn btn-sm btn-outline-info">Mark as Uncompleted</a>
1920
{% else %}
2021
<a href="{% url 'mark_completed' task.pk %}" class="btn btn-sm btn-success">Mark as Completed</a>
2122
{% endif %}
2223
</div>
2324
<div class="task-actions">
24-
<a href="{% url 'update_task' task.pk %}" class="btn btn-warning btn-sm">Edit</a>
25-
<a href="{% url 'delete_task' task.pk %}" class="btn btn-danger btn-sm">Delete</a>
25+
<a href="{% url 'update_task' task.pk %}" class="btn btn-outline-warning">Edit</a>
26+
<a href="{% url 'delete_task' task.pk %}" class="btn btn-outline-danger">Delete</a>
2627
</div>
2728
</div>
2829
{% empty %}
Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
11
{% extends 'todo_app/base.html' %}
2+
{% load django_bootstrap5 %}
23

34
{% block title %}Update Task{% endblock %}
45

56
{% block content %}
6-
<div class="update-task-form">
7-
8-
{% endblock content %}
7+
<div class="add-task-form">
8+
<h2 class="text-center mb-4" >Update Task</h2>
9+
<form method="post">
10+
{% csrf_token %}
11+
{% bootstrap_form form %}
12+
<button type="submit" class="btn btn-primary">Save Task</button>
13+
</form>
14+
<a href="{% url 'task_list' %}" class="btn btn-link">Back to Task List</a>
15+
</div>
16+
{% endblock %}

todo_project/todo_app/views.py

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,19 @@
22
from .models import Task
33
from .forms import TaskForm
44

5-
# View to display the list of tasks
5+
66
def task_list(request):
7-
tasks = Task.objects.all()
7+
'''
8+
Bring the list of all the tasks.
9+
'''
10+
tasks = Task.objects.all().order_by('completed')
811
return render(request, 'todo_app/task_list.html', {'tasks': tasks})
912

10-
# View to add a new task
13+
1114
def add_task(request):
15+
'''
16+
Add a new Task.
17+
'''
1218
if request.method == 'POST':
1319
form = TaskForm(request.POST)
1420
if form.is_valid():
@@ -18,8 +24,11 @@ def add_task(request):
1824
form = TaskForm()
1925
return render(request, 'todo_app/add_task.html', {'form': form})
2026

21-
# View to update a task
27+
2228
def update_task(request, pk):
29+
'''
30+
Update an existing task.
31+
'''
2332
task = get_object_or_404(Task, pk=pk)
2433
if request.method == 'POST':
2534
form = TaskForm(request.POST, instance=task)
@@ -30,15 +39,21 @@ def update_task(request, pk):
3039
form = TaskForm(instance=task)
3140
return render(request, 'todo_app/update_task.html', {'form': form})
3241

33-
# View to delete a task
42+
3443
def delete_task(request, pk):
44+
'''
45+
Delete an existing task.
46+
'''
3547
task = get_object_or_404(Task, pk=pk)
3648
task.delete()
3749
return redirect('task_list')
3850

39-
# View to mark a task as completed
51+
4052
def mark_completed(request, pk):
53+
'''
54+
Toggle between complete and uncomplete a task.
55+
'''
4156
task = get_object_or_404(Task, pk=pk)
42-
task.completed = True
57+
task.completed = not task.completed
4358
task.save()
4459
return redirect('task_list')

todo_project/todo_project/settings.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@
3737
'django.contrib.sessions',
3838
'django.contrib.messages',
3939
'django.contrib.staticfiles',
40+
41+
'django_bootstrap5',
42+
4043
'todo_app',
4144
]
4245

0 commit comments

Comments
 (0)