Skip to content

todo #99

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

todo #99

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
Binary file not shown.
67 changes: 20 additions & 47 deletions week-0/day-3/my_todo_app/todo_app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,6 @@
from flask import Flask
from flask import request

from flask import render_template

# our fake db
todo_store = {}
todo_store['depo'] = ['Go for run', 'Listen Rock Music']
todo_store['shivang'] = ['Read book', 'Play Fifa', 'Drink Coffee']
todo_store['raj'] = ['Study', 'Brush']
todo_store['sanket'] = ['Sleep', 'Code']
todo_store['aagam'] = ['play cricket', 'have tea']

def create_app(test_config=None):
# create and configure the app
app = Flask(__name__, instance_relative_config=True)
Expand All @@ -23,50 +13,33 @@ def create_app(test_config=None):
except OSError:
pass

def select_todos(name):
global todo_store
return todo_store[name]

def insert_todo(name, todo):
global todo_store
current_todos = todo_store[name]
current_todos.append(todo)
todo_store[name] = current_todos
return

def add_todo_by_name(name, todo):
# call DB function
insert_todo(name, todo)
return

# a simple page that list my todos
def get_todos_by_name(name):
try:
return select_todos(name)
except:
return None

if name=='raj':
return ['Eat','Sleep','Repeat']
elif name=='shivang':
return ['Brush','Study']
elif name=='manish':
return ['sleep','code']
else:
return []

# http://127.0.0.1:5000/todos?name=duster
@app.route('/todos')
def todos():
name = request.args.get('name')
print('---------')
name=request.args.get('name')
print('------')
print(name)
print('---------')
print('------')

person_todo_list = get_todos_by_name(name)
if person_todo_list == None:
return render_template('404.html'), 404
else:
return render_template('todo_view.html',todos=person_todo_list)
todo_l=get_todos_by_name(name)
return todo_view(todo_l)

def todo_view(todos):
the_view = 'List of my todos:' + '<br/>'
for todo in todos:
the_view += ( todo + '<br/>' )

@app.route('/add_todos')
def add_todos():
name = request.args.get('name')
todo = request.args.get('todo')
add_todo_by_name(name, todo)
return 'Added Successfully'
the_view += '---LIST ENDS HERE---'
return the_view

return app

Binary file not shown.