Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions docs/user-stories.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@

- [X] As a user, I want to see a list of my to-do items to know what to work on.
- [ ] As a user, I want to submit a form to add new items to my list.
- [ ] As a user, I want to filter the list of items to see completed tasks, uncompleted tasks, or all tasks.
- [ ] As a user, I want to click a button to mark an item as done.
- [X] As a user, I want to filter the list of items to see completed tasks, uncompleted tasks, or all tasks.
- [ ] As a user, I want to click a button to mark an item as done.
- [ ] As a user, I want to delete a task in case I don't need to do it anymore.
- [ ] As a user, I want to edit a task description so I can change what I already entered.
- [ ] As an anonymous user, I want to register with an email and password so that I can login.
- [ ] As a logged in user, I want to see only my tasks to keep them private.

5 changes: 5 additions & 0 deletions flasktodo/static/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,8 @@ li.completed {
text-decoration: line-through;
}

div.filter {
display: flex;
list-style: none;
justify-content: space-around;
}
8 changes: 7 additions & 1 deletion flasktodo/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,17 @@

{% block content %}
<h1>A simple to-do application</h1>

<div class="filter">
<li><a href="{{ url_for('todos.completed') }}">Completed</a></li>
<li><a href="{{ url_for('todos.uncompleted') }}">Uncompleted</a></li>
<li><a href="/">All</a></li>
<ul>
{% for todo in todos %}
<li class="{{ "completed" if todo['completed'] }}">
{{ todo['description'] }}
<form class="done" action="{{ url_for('todos.done', id=todo['id']) }}" method="post">
<button type="submit" name="done" value='Done'>Done</button>
</form>
</li>
{% endfor %}
</ul>
Expand Down
51 changes: 48 additions & 3 deletions flasktodo/todos.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from flask import Blueprint, render_template
from flask import (
Blueprint, flash, g, redirect, render_template, request, url_for
)

from . import db


bp = Blueprint("todos", __name__)

@bp.route("/")
@bp.route("/", methods=('GET', 'POST'))
def index():
"""View for home page which shows list of to-do items."""

Expand All @@ -16,3 +17,47 @@ def index():

return render_template("index.html", todos=todos)

@bp.route("/completed", methods=['GET', 'POST'])
def completed():


cur = db.get_db().cursor()

cur.execute('SELECT * FROM todos WHERE completed = True')
todos = cur.fetchall()
cur.close()

return render_template("index.html", todos=todos)


@bp.route("/uncompleted", methods=['GET'])
def uncompleted():


cur = db.get_db().cursor()

cur.execute('SELECT * FROM todos WHERE completed = FALSE')
todos = cur.fetchall()
cur.close()

return render_template("index.html", todos=todos)


@bp.route("/<int:id>/done", methods=('POST' ,))
def done(id):
"""This sets a task to completed"""
cur = db.get_db().cursor()

# Update the individual task and sets it to complete
cur.execute(
'UPDATE todos SET completed = True'
' WHERE id= %s ',
(id,)
)
g.db.commit()

cur.execute('SELECT * FROM todos')
todos = cur.fetchall()
cur.close()

return redirect(url_for('todos.index'))
7 changes: 3 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
setuptools.setup(
name="flasktodo",
version="0.0.1",
author="Zach Fedor",
author_email="zachfedor@gmail.com",
url="https://github.com/ts-cset/flask-todo",
author="Lee Enck",
author_email="eaglesfootball33@gmail.com",
url="https://github.com/LeeEnck/flask-todo",
description="A simple to-do application",
long_description=long_description,
long_description_content_type="text/markdown",
Expand All @@ -18,4 +18,3 @@
tests_require=['pytest'],
python_requires='>=3.6',
)

11 changes: 11 additions & 0 deletions tests/test_todos.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,14 @@ def test_todo_list(client):
assert response.data.count(b'<li class="">') == 2
assert response.data.count(b'<li class="completed">') == 1

def test_completed(client):
response = client.get('/completed')
assert b'clean room' not in response.data

assert response.data.count(b'<li class="completed">') == 1

def test_uncompleted(client):
response = client.get('/uncompleted')
assert b'clean room' not in response.data

assert response.data.count(b'<li class="completed">') == 0