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
2 changes: 2 additions & 0 deletions week-0/day-3/my_todo_app/todo_app/404.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<h3>404 </h3>
<h4>Record Not Found</h4>
92 changes: 50 additions & 42 deletions week-0/day-3/my_todo_app/todo_app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,12 @@

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']

todo_store['rahul']=['Go for music','learn swimming','yes']
todo_store['prashant']=['have to study','have to drink tea','yes']
todo_store['depo']=['have to study','have to drink coffee','yes']
todo_store['sanjay']=['have to study economics','have to drink coffee','yes']
def create_app(test_config=None):
# create and configure the app
app = Flask(__name__, instance_relative_config=True)
Expand All @@ -22,51 +17,64 @@ def create_app(test_config=None):
os.makedirs(app.instance_path)
except OSError:
pass

def todo_view(todos):
the_view='List of my todos'+'<br/>'
for todo in todos:
the_view+=todo+'<br/>'
the_view+='----The end of List-----'
return the_view
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

def get_todos_by_name(name):
def get_todos_byname(name):
try:
return select_todos(name)
except:
return None


# http://127.0.0.1:5000/todos?name=duster
def insert_todos(name,todo):
global todo_store
current_todos=todo_store[name]
current_todos.append(todo)
todo_store[name]=current_todos
return
def add_todo_byname(name,todo):
insert_todos(name,todo)
#call DB function
return
'''def get_todos_byname(name):
if name=='rahul':
return
elif name=='shivang':
return['speaking French','Learning to cook','yes']
elif name=='prashant':
return['have to study','have to drink tea','yes']
else:
return[]'''
@app.route('/todos')
def todos():
name = request.args.get('name')
print('---------')
name=request.args.get('name')
num=(int)(request.args.get('num'))
print('---------------')
print(name)
print('---------')

person_todo_list = get_todos_by_name(name)
if person_todo_list == None:
return render_template('404.html'), 404
print('---------------')
my_todos=[]
full_todo_list=get_todos_byname(name)
if(full_todo_list==None):
return render_template ('404.html'),404
else:
return render_template('todo_view.html',todos=person_todo_list)


half_todo_list=full_todo_list[0:num]
#return todo_view(half_todo_list)
return render_template ('todo_view.html', todos=half_todo_list)

# a simple page that list my todos
@app.route('/add_todos')
def add_todos():
name = request.args.get('name')
todo = request.args.get('todo')
add_todo_by_name(name, todo)
def add_todos(): #this todos are not persistent as it will work as static data
name=request.args.get('name')
todo=request.args.get('todo')
add_todo_byname(name,todo)
print('-----------')
print(name,todo)
print('-----------')
return 'Added Successfully'

return app

Binary file not shown.
1 change: 0 additions & 1 deletion week-0/day-3/my_todo_app/todo_app/templates/todo_view.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@
{% for todo in todos %}
{{todo}}<br/>
{% endfor %}

---- LIST ENDS HERE ---