From a41328708a0a16c95e16268073704ccf4d7d94f4 Mon Sep 17 00:00:00 2001 From: Andros Fenollosa Date: Tue, 27 Sep 2016 13:47:54 +0200 Subject: [PATCH 1/2] Update footer --- .gitignore | 3 ++- src/app.py | 8 +------- src/database.sqlite | Bin 0 -> 28672 bytes src/templates/layouts/master.html | 20 ++++++++++++++++++++ src/wsgi.py | 5 +++++ 5 files changed, 28 insertions(+), 8 deletions(-) create mode 100644 src/database.sqlite create mode 100644 src/wsgi.py diff --git a/.gitignore b/.gitignore index 9823b10..7ce219a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ src/ENV -src/database.sqlite +log.err +log.info diff --git a/src/app.py b/src/app.py index 388f96d..e6d588b 100644 --- a/src/app.py +++ b/src/app.py @@ -5,7 +5,7 @@ from markdown import markdown from database import db, User, Note app = Flask(__name__) - +app.secret_key = 'secret' def login_required(f): # Decoration: check login in session @@ -170,9 +170,3 @@ def delete_note(): db.session.commit() return redirect(url_for('dashboard', id=id)) - -# App -if __name__ == "__main__": - app.secret_key = 'secret' - app.debug = True - app.run() diff --git a/src/database.sqlite b/src/database.sqlite new file mode 100644 index 0000000000000000000000000000000000000000..ca8a11b8328cecf829ee79ebe4c0d8bad80da1d0 GIT binary patch literal 28672 zcmeI5O^h7H6~|}2i-}Fl5`nP@iYWOIY_p8KHbf#EU@=RuVjS?=D4bADckOJM{uuYi z;PoXUCyu!#S06bzA0kpDUm`IVZaGEDEr%SVoT5mHa>?(#>YkZ3F^a?mNEvo_rl+gw zz5n~a|9e$to1M2V`No;uvdV2^&JP|LtgH-PHfAswJjU09eD!}0@nWri!_Sqa*Y|t* z*x=cJeRypBpM$lBtHJsU>wkE-T7TqzH^=J{frvmvAR-VEhzLXkA_5VCh(JUjBJg!W z;DaYuA3SmV_{vY8XzVC+McL@r+J!6ITUWQu)vZ@9Z5z32P8~hsQ*-h1)$Jc_Uon?| zbk$tGcIncFIeMh=P3FwoTURc;zIEl)=Gn8S^{Ttsn5)}Az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n z11cM~cjc<9yIUL_A^lpsR6RBj^fA`+HxDA_L6N$WE!k4wo={bGqR_2VoVnkew@VKJ zwF1X_j`ogg+@uUhvB#Bu8m{1TS&i7G(!od`Z?MN6ks+Fh96{;C9tG($ZvL?p`DN8( z-cAyNZ#iAHoKqZhnRiL}Tc?AcUu!#FXPzptY7h#*O- zO8U;bxV{SUH$hVluV{V{e(8Yb<+qDYmnnS}I|&CKx-9~q%;d-Li>Q=p->8fW(jE+ z&h2|imXP-iu2#vV_e-Tr1H|7WbV9ylbXTtXnjj**-H0r9iPU{AT%YI1g1Acp1UP!a z#K~!+sS(x)^j_-@W-3X4)_vEfn^Jx~qri9Kzh)5ctu>8TB6*1P(Np YW2a}p0Xsek`MS#9 + + diff --git a/src/wsgi.py b/src/wsgi.py new file mode 100644 index 0000000..3239d41 --- /dev/null +++ b/src/wsgi.py @@ -0,0 +1,5 @@ +from app import app + +if __name__ == "__main__": + app.secret_key = 'secret' + app.run() From a271efca6e7175286b486d6cd59471c3d0c81bda Mon Sep 17 00:00:00 2001 From: Andros Fenollosa Date: Sat, 8 Oct 2016 22:50:20 +0200 Subject: [PATCH 2/2] Fix rollback --- src/app.py | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/src/app.py b/src/app.py index e6d588b..278091a 100644 --- a/src/app.py +++ b/src/app.py @@ -7,6 +7,7 @@ from database import db, User, Note app = Flask(__name__) app.secret_key = 'secret' + def login_required(f): # Decoration: check login in session @wraps(f) @@ -26,7 +27,9 @@ def index(data=None): @app.route('/login', methods=['POST']) def login(): data = dict() - if request.form['action'] and request.form['email'] and request.form['password']: + if (request.form['action'] and + request.form['email'] and + request.form['password']): data['email'] = request.form['email'] data['password'] = request.form['password'] if request.form['action'] == 'signup': @@ -38,7 +41,10 @@ def login(): # Create my_user = User(data['email'], data['password']) db.session.add(my_user) - db.session.commit() + try: + db.session.commit() + except: + db.session.rollback() else: data['error'] = 'register' @@ -104,7 +110,8 @@ def search(): return dashboard(Note.query.filter( or_(Note.title.like('%' + q + '%'), Note.text.like('%' + q + '%') - )).filter_by(user_id=session['user_id']).order_by(Note.id.desc()).all()) + )).filter_by(user_id=session['user_id']).order_by( + Note.id.desc()).all()) @app.route('/new') @@ -120,7 +127,10 @@ def save_note(): 'text'], session['user_id']) # Create db.session.add(myNote) - db.session.commit() + try: + db.session.commit() + except: + db.session.rollback() return redirect(url_for('dashboard')) @@ -143,7 +153,10 @@ def edit_note(data=None): my_note = Note.query.filter_by(id=request.form['id']).first() my_note.title = request.form['title'] my_note.text = request.form['text'] - db.session.commit() + try: + db.session.commit() + except: + db.session.rollback() return redirect(url_for('dashboard')) @@ -167,6 +180,9 @@ def delete_note(): # Delete my_note = Note.query.filter_by(id=id).first() db.session.delete(my_note) - db.session.commit() + try: + db.session.commit() + except: + db.session.rollback() return redirect(url_for('dashboard', id=id))