|
|
|
@ -37,31 +37,32 @@ class PrefixMiddleware(object):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app = Flask(__name__)
|
|
|
|
|
app.config['SECRET KEY']='this should be a secret random string'
|
|
|
|
|
|
|
|
|
|
# register the middleware to prefix all the requests with our base_url
|
|
|
|
|
app.wsgi_app = PrefixMiddleware(app.wsgi_app, prefix='/soupboat/library')
|
|
|
|
|
app.wsgi_app=PrefixMiddleware(app.wsgi_app, prefix='/soupboat/library')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@app.route("/")
|
|
|
|
|
@ app.route("/")
|
|
|
|
|
def home():
|
|
|
|
|
conn = get_db_connection()
|
|
|
|
|
todos = conn.execute('SELECT c.id, c.content, cat.title \
|
|
|
|
|
conn=get_db_connection()
|
|
|
|
|
todos=conn.execute('SELECT c.id, c.content, cat.title \
|
|
|
|
|
FROM cards c JOIN categories cat \
|
|
|
|
|
ON c.category_id = cat.id ORDER BY cat.title').fetchall()
|
|
|
|
|
|
|
|
|
|
categories = {}
|
|
|
|
|
categories={}
|
|
|
|
|
|
|
|
|
|
# for each category and group of cards for each cat in groupby() grouper object
|
|
|
|
|
for k, g in groupby(todos, key=lambda t: t['title']):
|
|
|
|
|
cards = []
|
|
|
|
|
cards=[]
|
|
|
|
|
|
|
|
|
|
for card in g:
|
|
|
|
|
card = dict(card)
|
|
|
|
|
card=dict(card)
|
|
|
|
|
print('card is:', card)
|
|
|
|
|
cards.append(card)
|
|
|
|
|
# print(categories[k])
|
|
|
|
|
|
|
|
|
|
categories[k] = list(cards)
|
|
|
|
|
categories[k]=list(cards)
|
|
|
|
|
|
|
|
|
|
for cat, cards in categories.items(): # ♥ .items is a build in attribute of the dictionary(?)
|
|
|
|
|
print(cat)
|
|
|
|
@ -72,19 +73,19 @@ def home():
|
|
|
|
|
return render_template('home.html', categories=categories)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@app.route("/add/", methods=['GET', 'POST'])
|
|
|
|
|
@ app.route("/add/", methods=['GET', 'POST'])
|
|
|
|
|
def create():
|
|
|
|
|
conn = get_db_connection()
|
|
|
|
|
conn=get_db_connection()
|
|
|
|
|
|
|
|
|
|
if request.method == 'POST':
|
|
|
|
|
content = request.form['content']
|
|
|
|
|
cat_title = request.form['cat']
|
|
|
|
|
content=request.form['content']
|
|
|
|
|
cat_title=request.form['cat']
|
|
|
|
|
|
|
|
|
|
if not content:
|
|
|
|
|
flash('plz write a content!')
|
|
|
|
|
return redirect(url_for('home'))
|
|
|
|
|
|
|
|
|
|
cat_id = conn.execute('SELECT id FROM categories WHERE title = (?);',
|
|
|
|
|
cat_id=conn.execute('SELECT id FROM categories WHERE title = (?);',
|
|
|
|
|
(cat_title,)).fetchone()['id']
|
|
|
|
|
conn.execute('INSERT INTO cards (content, category_id) VALUES (?,?)',
|
|
|
|
|
(content, cat_id))
|
|
|
|
@ -92,31 +93,31 @@ def create():
|
|
|
|
|
conn.close()
|
|
|
|
|
return redirect(url_for('home'))
|
|
|
|
|
|
|
|
|
|
categories = conn.execute('SELECT title FROM categories;').fetchall()
|
|
|
|
|
categories=conn.execute('SELECT title FROM categories;').fetchall()
|
|
|
|
|
|
|
|
|
|
conn.close()
|
|
|
|
|
return render_template('create.html', categories=categories)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@app.route('/<int:id>/edit/', methods=('GET', 'POST'))
|
|
|
|
|
@ app.route('/<int:id>/edit/', methods=('GET', 'POST'))
|
|
|
|
|
def edit(id):
|
|
|
|
|
conn = get_db_connection()
|
|
|
|
|
conn=get_db_connection()
|
|
|
|
|
|
|
|
|
|
todo = conn.execute('SELECT c.id, c.category_id, c.content, cat.title \
|
|
|
|
|
todo=conn.execute('SELECT c.id, c.category_id, c.content, cat.title \
|
|
|
|
|
FROM cards c JOIN categories cat \
|
|
|
|
|
ON c.category_id = cat.id WHERE c.id = ?', (id,)).fetchone()
|
|
|
|
|
|
|
|
|
|
categories = conn.execute('SELECT title FROM categories;').fetchall()
|
|
|
|
|
categories=conn.execute('SELECT title FROM categories;').fetchall()
|
|
|
|
|
|
|
|
|
|
if request.method == 'POST':
|
|
|
|
|
content = request.form['content']
|
|
|
|
|
cat_title = request.form['cat']
|
|
|
|
|
content=request.form['content']
|
|
|
|
|
cat_title=request.form['cat']
|
|
|
|
|
|
|
|
|
|
if not content:
|
|
|
|
|
flash('plz insert any content!')
|
|
|
|
|
return redirect(url_for('home'))
|
|
|
|
|
|
|
|
|
|
cat_id = conn.execute('SELECT id FROM categories WHERE title = (?);',
|
|
|
|
|
cat_id=conn.execute('SELECT id FROM categories WHERE title = (?);',
|
|
|
|
|
(cat_title,)).fetchone()['id']
|
|
|
|
|
|
|
|
|
|
conn.execute('UPDATE cards SET content = ?, category_id = ? \
|
|
|
|
@ -129,9 +130,9 @@ def edit(id):
|
|
|
|
|
return render_template('edit.html', todo=todo, categories=categories)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@app.route('/<int:id>/delete/', methods=('POST',))
|
|
|
|
|
@ app.route('/<int:id>/delete/', methods=('POST',))
|
|
|
|
|
def delete(id):
|
|
|
|
|
conn = get_db_connection()
|
|
|
|
|
conn=get_db_connection()
|
|
|
|
|
conn.execute('DELETE FROM cards WHERE id = ?', (id,))
|
|
|
|
|
conn.commit()
|
|
|
|
|
conn.close()
|
|
|
|
|