Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Todo App Done with Flask #2

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
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
3 changes: 3 additions & 0 deletions 021_Todo_APP/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions 021_Todo_APP/.idea/inspectionProfiles/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions 021_Todo_APP/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions 021_Todo_APP/.idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions 021_Todo_APP/.idea/todo-redone.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 36 additions & 0 deletions 021_Todo_APP/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from flask import Flask, request, render_template, redirect, url_for
from flask_bootstrap import Bootstrap

#create the app
app = Flask(__name__)
bootstrap = Bootstrap(app)

#the database
todos = []
#routes
@app.route('/')
def index():
return render_template('index.html', todos=todos)
@app.route('/add', methods=['POST'])
def add():
task = request.form['todo']
todos.append({"task":task, "done":False})
return redirect(url_for('index'))
@app.route('/remove/<int:index>', methods=['GET'])
def remove(index):
del todos[index]
return redirect(url_for('index'))

@app.route('/edit/<int:index>', methods=['GET', 'POST'])
def edit(index):
if request.method == 'GET':
todo = todos[index]
return render_template('edit.html', todo=todo, index=index)
else:
task = request.form['todo']
todo = todos[index]
todo['task'] = task
return redirect(url_for('index'))

#run the app
app.run(debug=True)
4 changes: 4 additions & 0 deletions 021_Todo_APP/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[ A Todo App Done with Flask ]

It is written using the microframework Flask, and Bootstrap
enjoy !
23 changes: 23 additions & 0 deletions 021_Todo_APP/templates/edit.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{% extends "index.html" %}

{% block content %}

<div class="container-fluid">
<div class="container-fluid">
<div class="row">
<div class="col-sm-3 col-sm-offset-4">
<h1 class="text-center page-header">Edit</h1>
<form action=" {{ url_for('edit',index=index)}} " method="post">
<div class="input-group">
<input type="text" name="todo" class="form-control" value="{{ todo['task'] }}" required>
<span class="input-group-btn">
<button type="submit" class="btn btn-primary form-control">Save</button>
</span>
</div>
</form>
</div>
</div>
</div>
</div>

{% endblock %}
50 changes: 50 additions & 0 deletions 021_Todo_APP/templates/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{% extends "bootstrap/base.html" %}
{% block title %} todo {% endblock %}

{% block content %}
<div class="container-fluid">
<div class="row">
<div class="col-sm-3 col-sm-offset-4">
<h2 class="lead text-center">Tasks</h2>
<ul class="list-group" >
{% if not todos %}
<li class="list-group-item list-group-item-warning"><span class="glyphicon glyphicon-exclamation-sign"></span> No Tasks to Display</li>
{% else %}
{% for todo in todos %}
<div class="input-group">
<span class="input-group-addon">
<input type="checkbox" class="checkbox">
</span>
<li class="list-group-item list-group-item-default">
<div class="input-group">
{{ todo['task'] }}
<span class="input-group-btn"><a href="{{ url_for('edit', index=loop.index0) }}" class="edit btn btn-info glyphicon glyphicon-pencil"></a></span>
<span class="input-group-btn"><a href="{{ url_for('remove', index=loop.index0) }}" class="remove btn btn-danger glyphicon glyphicon-remove"></a></span>
</div>
</li>
</div>
{% endfor %}
{% endif %}
</ul>
</div>
</div>
</div>
<hr>

<div class="container-fluid">
<div class="row">
<div class="col-sm-3 col-sm-offset-4">
<form action=" {{ url_for('add') }} " method="post">
<div class="input-group">
<input type="text" name="todo" class="form-control" required>
<span class="input-group-btn">
<button type="submit" class="btn btn-primary form-control"><span class="glyphicon glyphicon-plus"></span></button>
</span>
</div>
</form>
</div>
</div>
</div>
</div>

{% endblock %}
Empty file added readme.md
Empty file.