|
|
@ -3,6 +3,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
from itertools import groupby # to handle complex iterations
|
|
|
|
from itertools import groupby # to handle complex iterations
|
|
|
|
import os
|
|
|
|
import os
|
|
|
|
|
|
|
|
from pydoc_data.topics import topics
|
|
|
|
|
|
|
|
|
|
|
|
import sqlite3
|
|
|
|
import sqlite3
|
|
|
|
from webbrowser import get
|
|
|
|
from webbrowser import get
|
|
|
@ -71,10 +72,6 @@ def home():
|
|
|
|
|
|
|
|
|
|
|
|
categories[k] = list(cards)
|
|
|
|
categories[k] = list(cards)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for cat, cards in categories.items(): # ♥ .items is a build in attribute of the dictionary(?)
|
|
|
|
for cat, cards in categories.items(): # ♥ .items is a build in attribute of the dictionary(?)
|
|
|
|
print(cat)
|
|
|
|
print(cat)
|
|
|
|
for card in cards:
|
|
|
|
for card in cards:
|
|
|
@ -93,9 +90,12 @@ def create():
|
|
|
|
if request.method == 'POST':
|
|
|
|
if request.method == 'POST':
|
|
|
|
content = request.form['content']
|
|
|
|
content = request.form['content']
|
|
|
|
category_name = request.form['cat']
|
|
|
|
category_name = request.form['cat']
|
|
|
|
|
|
|
|
# can this be a category? o be general?
|
|
|
|
|
|
|
|
topic_tag = request.form['topic_tag']
|
|
|
|
|
|
|
|
|
|
|
|
#create a new category:
|
|
|
|
# create a new category and topic:
|
|
|
|
new_category = request.form['new_category']
|
|
|
|
new_category = request.form['new_category']
|
|
|
|
|
|
|
|
new_topic = request.form['new_topic']
|
|
|
|
# if a new category_category_name is created add it to the table of categories
|
|
|
|
# if a new category_category_name is created add it to the table of categories
|
|
|
|
if category_name == 'New category' and new_category:
|
|
|
|
if category_name == 'New category' and new_category:
|
|
|
|
conn.execute('INSERT INTO categories (category_name) VALUES (?)',
|
|
|
|
conn.execute('INSERT INTO categories (category_name) VALUES (?)',
|
|
|
@ -104,6 +104,16 @@ def create():
|
|
|
|
# update category_name to refer to the newly added category
|
|
|
|
# update category_name to refer to the newly added category
|
|
|
|
category_name = new_category
|
|
|
|
category_name = new_category
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if topic_tag == 'New topic' and new_topic:
|
|
|
|
|
|
|
|
conn.execute('INSERT INTO topics (content) VALUES (?)',
|
|
|
|
|
|
|
|
(new_topic,))
|
|
|
|
|
|
|
|
conn.commit()
|
|
|
|
|
|
|
|
topic_tag = new_topic
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
topic_id = conn.execute('SELECT id FROM topics WHERE content = (?);',
|
|
|
|
|
|
|
|
(topic_tag,)).fetchone()['id']
|
|
|
|
|
|
|
|
conn.execute('INSERT INTO topic_cards (topic_id, card_id) VALUES (?,?)',
|
|
|
|
|
|
|
|
(topic_id, cat_id))
|
|
|
|
|
|
|
|
|
|
|
|
if not content:
|
|
|
|
if not content:
|
|
|
|
flash('plz write a content!')
|
|
|
|
flash('plz write a content!')
|
|
|
@ -111,16 +121,20 @@ def create():
|
|
|
|
|
|
|
|
|
|
|
|
cat_id = conn.execute('SELECT id FROM categories WHERE category_name = (?);',
|
|
|
|
cat_id = conn.execute('SELECT id FROM categories WHERE category_name = (?);',
|
|
|
|
(category_name,)).fetchone()['id']
|
|
|
|
(category_name,)).fetchone()['id']
|
|
|
|
|
|
|
|
|
|
|
|
conn.execute('INSERT INTO cards (content, category_id) VALUES (?,?)',
|
|
|
|
conn.execute('INSERT INTO cards (content, category_id) VALUES (?,?)',
|
|
|
|
(content, cat_id))
|
|
|
|
(content, cat_id))
|
|
|
|
|
|
|
|
|
|
|
|
conn.commit()
|
|
|
|
conn.commit()
|
|
|
|
conn.close()
|
|
|
|
conn.close()
|
|
|
|
return redirect(url_for('home'))
|
|
|
|
return redirect(url_for('home'))
|
|
|
|
|
|
|
|
|
|
|
|
categories=conn.execute('SELECT category_name FROM categories;').fetchall()
|
|
|
|
categories = conn.execute(
|
|
|
|
|
|
|
|
'SELECT category_name FROM categories;').fetchall()
|
|
|
|
|
|
|
|
topics = conn.execute('SELECT content FROM topics;').fetchall()
|
|
|
|
|
|
|
|
|
|
|
|
conn.close()
|
|
|
|
conn.close()
|
|
|
|
return render_template('create.html', categories=categories)
|
|
|
|
return render_template('create.html', categories=categories, topics=topics)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ app.route('/<int:id>/edit/', methods=('GET', 'POST'))
|
|
|
|
@ app.route('/<int:id>/edit/', methods=('GET', 'POST'))
|
|
|
@ -131,7 +145,8 @@ def edit(id):
|
|
|
|
FROM cards c JOIN categories cat \
|
|
|
|
FROM cards c JOIN categories cat \
|
|
|
|
ON c.category_id = cat.id WHERE c.id = ?', (id,)).fetchone()
|
|
|
|
ON c.category_id = cat.id WHERE c.id = ?', (id,)).fetchone()
|
|
|
|
|
|
|
|
|
|
|
|
categories=conn.execute('SELECT category_name FROM categories;').fetchall()
|
|
|
|
categories = conn.execute(
|
|
|
|
|
|
|
|
'SELECT category_name FROM categories;').fetchall()
|
|
|
|
|
|
|
|
|
|
|
|
if request.method == 'POST':
|
|
|
|
if request.method == 'POST':
|
|
|
|
content = request.form['content']
|
|
|
|
content = request.form['content']
|
|
|
|