diff --git a/week-0/day-3/my_todo_app/todo_app/__init__.py b/week-0/day-3/my_todo_app/todo_app/__init__.py index 86fb09d8..6d530c8b 100644 --- a/week-0/day-3/my_todo_app/todo_app/__init__.py +++ b/week-0/day-3/my_todo_app/todo_app/__init__.py @@ -4,69 +4,26 @@ from flask import request from flask import render_template +from todo_app.extensions import mysql -# 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): +def create_app(): # create and configure the app app = Flask(__name__, instance_relative_config=True) - # ensure the instance folder exists try: os.makedirs(app.instance_path) 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 - - def get_todos_by_name(name): - try: - return select_todos(name) - except: - return None - - - # http://127.0.0.1:5000/todos?name=duster - @app.route('/todos') - def todos(): - name = request.args.get('name') - print('---------') - print(name) - 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) - + app.config['MYSQL_DATABASE_HOST'] = 'localhost' + app.config['MYSQL_DATABASE_USER'] = 'root' + app.config['MYSQL_DATABASE_PASSWORD'] = 'swapnil159' + app.config['MYSQL_DATABASE_DB'] = 'todo_app' + #app.config['MYSQL_DATABASE_CHARSET'] = 'utf-8' + mysql.init_app(app) - @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' + from . import todo + app.register_blueprint(todo.bp) return app diff --git a/week-0/day-3/my_todo_app/todo_app/__init__.pyc b/week-0/day-3/my_todo_app/todo_app/__init__.pyc index 45e35a62..c9bb8483 100644 Binary files a/week-0/day-3/my_todo_app/todo_app/__init__.pyc and b/week-0/day-3/my_todo_app/todo_app/__init__.pyc differ diff --git a/week-0/day-3/my_todo_app/todo_app/__pycache__/__init__.cpython-35.pyc b/week-0/day-3/my_todo_app/todo_app/__pycache__/__init__.cpython-35.pyc new file mode 100644 index 00000000..e1da2b98 Binary files /dev/null and b/week-0/day-3/my_todo_app/todo_app/__pycache__/__init__.cpython-35.pyc differ diff --git a/week-0/day-3/my_todo_app/todo_app/__pycache__/extensions.cpython-35.pyc b/week-0/day-3/my_todo_app/todo_app/__pycache__/extensions.cpython-35.pyc new file mode 100644 index 00000000..c0dac54b Binary files /dev/null and b/week-0/day-3/my_todo_app/todo_app/__pycache__/extensions.cpython-35.pyc differ diff --git a/week-0/day-3/my_todo_app/todo_app/__pycache__/todo.cpython-35.pyc b/week-0/day-3/my_todo_app/todo_app/__pycache__/todo.cpython-35.pyc new file mode 100644 index 00000000..98717b37 Binary files /dev/null and b/week-0/day-3/my_todo_app/todo_app/__pycache__/todo.cpython-35.pyc differ diff --git a/week-0/day-3/my_todo_app/todo_app/extensions.py b/week-0/day-3/my_todo_app/todo_app/extensions.py new file mode 100644 index 00000000..cad33c96 --- /dev/null +++ b/week-0/day-3/my_todo_app/todo_app/extensions.py @@ -0,0 +1,3 @@ +from flaskext.mysql import MySQL + +mysql = MySQL() \ No newline at end of file diff --git a/week-0/day-3/my_todo_app/todo_app/extensions.pyc b/week-0/day-3/my_todo_app/todo_app/extensions.pyc new file mode 100644 index 00000000..fa0ba305 Binary files /dev/null and b/week-0/day-3/my_todo_app/todo_app/extensions.pyc differ diff --git a/week-0/day-3/my_todo_app/todo_app/screenshots/add.png b/week-0/day-3/my_todo_app/todo_app/screenshots/add.png new file mode 100644 index 00000000..300759a2 Binary files /dev/null and b/week-0/day-3/my_todo_app/todo_app/screenshots/add.png differ diff --git a/week-0/day-3/my_todo_app/todo_app/screenshots/all.png b/week-0/day-3/my_todo_app/todo_app/screenshots/all.png new file mode 100644 index 00000000..fa406a5c Binary files /dev/null and b/week-0/day-3/my_todo_app/todo_app/screenshots/all.png differ diff --git a/week-0/day-3/my_todo_app/todo_app/screenshots/num1.png b/week-0/day-3/my_todo_app/todo_app/screenshots/num1.png new file mode 100644 index 00000000..152ff3e5 Binary files /dev/null and b/week-0/day-3/my_todo_app/todo_app/screenshots/num1.png differ diff --git a/week-0/day-3/my_todo_app/todo_app/screenshots/num3.png b/week-0/day-3/my_todo_app/todo_app/screenshots/num3.png new file mode 100644 index 00000000..dff9e1c9 Binary files /dev/null and b/week-0/day-3/my_todo_app/todo_app/screenshots/num3.png differ diff --git a/week-0/day-3/my_todo_app/todo_app/templates/todo_view.html b/week-0/day-3/my_todo_app/todo_app/templates/todo_view.html index 24236a13..3219422d 100644 --- a/week-0/day-3/my_todo_app/todo_app/templates/todo_view.html +++ b/week-0/day-3/my_todo_app/todo_app/templates/todo_view.html @@ -1,7 +1,7 @@ List of my todos:
{% for todo in todos %} -{{todo}}
+ {{todo[0]}}
{% endfor %} ---- LIST ENDS HERE --- diff --git a/week-0/day-3/my_todo_app/todo_app/todo.py b/week-0/day-3/my_todo_app/todo_app/todo.py new file mode 100644 index 00000000..905c2ee3 --- /dev/null +++ b/week-0/day-3/my_todo_app/todo_app/todo.py @@ -0,0 +1,53 @@ +from flask import ( + Blueprint, flash, g, redirect, render_template, request, url_for +) +from werkzeug.exceptions import abort + +bp = Blueprint('todo', __name__) + +from todo_app.extensions import mysql + +def select_todos(name,num): + cur = mysql.get_db().cursor() + cur.execute("SELECT todos FROM todo WHERE name = %s LIMIT %s",(name,num)) + todo_list = cur.fetchall() + return todo_list + +def insert_todo(name, todo): + print(name,todo) + conn = mysql.connect() + cur = conn.cursor() + cur.execute("INSERT INTO todo (name, todos) VALUES (%s, %s)",(name,todo)) + conn.commit() + cur.close() + conn.close() + return + +def add_todo_by_name(name, todo): + # call DB function + insert_todo(name, todo) + return + +def get_todos_by_name(name,num): + return select_todos(name,num) + + + +# http://127.0.0.1:5000/todos?name=duster +@bp.route('/todos') +def todos(): + name = request.args.get('name') + num = int(request.args.get('num')) + person_todo_list = get_todos_by_name(name,num) + if person_todo_list == None: + return render_template('404.html'), 404 + else: + return render_template('todo_view.html',todos=person_todo_list) + + +@bp.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' \ No newline at end of file diff --git a/week-0/day-3/my_todo_app/todo_app/todo.pyc b/week-0/day-3/my_todo_app/todo_app/todo.pyc new file mode 100644 index 00000000..4cf213bd Binary files /dev/null and b/week-0/day-3/my_todo_app/todo_app/todo.pyc differ