Merge branch 'demo'
This commit is contained in:
commit
2835da52ee
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,2 +1,3 @@
|
|||||||
src/ENV
|
src/ENV
|
||||||
src/database.sqlite
|
log.err
|
||||||
|
log.info
|
||||||
|
34
src/app.py
34
src/app.py
@ -5,6 +5,7 @@ from markdown import markdown
|
|||||||
from database import db, User, Note
|
from database import db, User, Note
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
app.secret_key = 'secret'
|
||||||
|
|
||||||
|
|
||||||
def login_required(f):
|
def login_required(f):
|
||||||
@ -26,7 +27,9 @@ def index(data=None):
|
|||||||
@app.route('/login', methods=['POST'])
|
@app.route('/login', methods=['POST'])
|
||||||
def login():
|
def login():
|
||||||
data = dict()
|
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['email'] = request.form['email']
|
||||||
data['password'] = request.form['password']
|
data['password'] = request.form['password']
|
||||||
if request.form['action'] == 'signup':
|
if request.form['action'] == 'signup':
|
||||||
@ -38,7 +41,10 @@ def login():
|
|||||||
# Create
|
# Create
|
||||||
my_user = User(data['email'], data['password'])
|
my_user = User(data['email'], data['password'])
|
||||||
db.session.add(my_user)
|
db.session.add(my_user)
|
||||||
db.session.commit()
|
try:
|
||||||
|
db.session.commit()
|
||||||
|
except:
|
||||||
|
db.session.rollback()
|
||||||
else:
|
else:
|
||||||
data['error'] = 'register'
|
data['error'] = 'register'
|
||||||
|
|
||||||
@ -104,7 +110,8 @@ def search():
|
|||||||
|
|
||||||
return dashboard(Note.query.filter(
|
return dashboard(Note.query.filter(
|
||||||
or_(Note.title.like('%' + q + '%'), Note.text.like('%' + q + '%')
|
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')
|
@app.route('/new')
|
||||||
@ -120,7 +127,10 @@ def save_note():
|
|||||||
'text'], session['user_id'])
|
'text'], session['user_id'])
|
||||||
# Create
|
# Create
|
||||||
db.session.add(myNote)
|
db.session.add(myNote)
|
||||||
db.session.commit()
|
try:
|
||||||
|
db.session.commit()
|
||||||
|
except:
|
||||||
|
db.session.rollback()
|
||||||
|
|
||||||
return redirect(url_for('dashboard'))
|
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 = Note.query.filter_by(id=request.form['id']).first()
|
||||||
my_note.title = request.form['title']
|
my_note.title = request.form['title']
|
||||||
my_note.text = request.form['text']
|
my_note.text = request.form['text']
|
||||||
db.session.commit()
|
try:
|
||||||
|
db.session.commit()
|
||||||
|
except:
|
||||||
|
db.session.rollback()
|
||||||
|
|
||||||
return redirect(url_for('dashboard'))
|
return redirect(url_for('dashboard'))
|
||||||
|
|
||||||
@ -167,12 +180,9 @@ def delete_note():
|
|||||||
# Delete
|
# Delete
|
||||||
my_note = Note.query.filter_by(id=id).first()
|
my_note = Note.query.filter_by(id=id).first()
|
||||||
db.session.delete(my_note)
|
db.session.delete(my_note)
|
||||||
db.session.commit()
|
try:
|
||||||
|
db.session.commit()
|
||||||
|
except:
|
||||||
|
db.session.rollback()
|
||||||
|
|
||||||
return redirect(url_for('dashboard', id=id))
|
return redirect(url_for('dashboard', id=id))
|
||||||
|
|
||||||
# App
|
|
||||||
if __name__ == "__main__":
|
|
||||||
app.secret_key = 'secret'
|
|
||||||
app.debug = True
|
|
||||||
app.run()
|
|
||||||
|
BIN
src/database.sqlite
Normal file
BIN
src/database.sqlite
Normal file
Binary file not shown.
@ -18,5 +18,25 @@
|
|||||||
{% endblock %}
|
{% endblock %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<footer>
|
||||||
|
<p> </p>
|
||||||
|
<p class="text-center">
|
||||||
|
Author: Andros Fenollosa <a href="https://programadorwebvalencia.com">https://programadorwebvalencia.com</a>
|
||||||
|
</p>
|
||||||
|
<p class="text-center">
|
||||||
|
Source: <a href="http://github.com/tanrax/flask-note">http://github.com/tanrax/flask-note</a>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
</footer>
|
||||||
|
<script>
|
||||||
|
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
|
||||||
|
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
|
||||||
|
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
|
||||||
|
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
|
||||||
|
|
||||||
|
ga('create', 'UA-46470654-2', 'auto');
|
||||||
|
ga('send', 'pageview');
|
||||||
|
|
||||||
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
5
src/wsgi.py
Normal file
5
src/wsgi.py
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
from app import app
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
app.secret_key = 'secret'
|
||||||
|
app.run()
|
Loading…
Reference in New Issue
Block a user