diff --git a/exquisite_branch/display.py b/exquisite_branch/display.py index ada9b0a..b24a4e3 100644 --- a/exquisite_branch/display.py +++ b/exquisite_branch/display.py @@ -1,5 +1,5 @@ from flask import (Blueprint, flash, g, redirect, - request, session, url_for) + request, session, url_for, jsonify) from flask_mako import render_template from exquisite_branch.db import get_db @@ -8,8 +8,6 @@ from exquisite_branch.db import get_db bp = Blueprint('display', __name__, url_prefix='/display') - - # branches = db.execute( # "SELECT content, branch, parent, username FROM branches" # ).fetchall() @@ -35,11 +33,19 @@ bp = Blueprint('display', __name__, url_prefix='/display') @bp.route('/') -def display(): +def list(): + db = get_db() + trees = db.execute('SELECT * FROM trees').fetchall() + return render_template('list.html', trees=trees) + + +@bp.route('//') +def display(tree=None): db = get_db() branches = db.execute( - "SELECT content, branch, parent, username FROM branches" + "SELECT content, branch, parent, username FROM branches WHERE tree = ?", + (tree,) ).fetchall() - return render_template('display.html', branches=branches) + return render_template('display.html', tree=tree, branches=branches) diff --git a/exquisite_branch/schema.sql b/exquisite_branch/schema.sql index 65db0e5..6258b2a 100644 --- a/exquisite_branch/schema.sql +++ b/exquisite_branch/schema.sql @@ -1,9 +1,18 @@ DROP TABLE IF EXISTS branches; +DROP TABLE IF EXISTS trees; CREATE TABLE branches ( id INTEGER PRIMARY KEY AUTOINCREMENT, branch TEXT NOT NULL, content TEXT NOT NULL, parent TEXT NOT NULL, - username TEXT -); \ No newline at end of file + username TEXT, + tree TEXT NOT NULL, + FOREIGN KEY (tree) REFERENCES trees(slug) +); + +CREATE TABLE trees ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + name TEXT NOT NULL, + slug TEXT NOT NULL UNIQUE +); diff --git a/exquisite_branch/share.py b/exquisite_branch/share.py index d77b598..09ebc89 100644 --- a/exquisite_branch/share.py +++ b/exquisite_branch/share.py @@ -1,9 +1,9 @@ -from flask import (Blueprint, flash, g, redirect, - render_template, request, session, url_for) +from flask import (Blueprint, render_template) bp = Blueprint('share', __name__, url_prefix='/share') -@bp.route('//') -def share(branch=None): - return render_template('share.html', branch=branch) + +@bp.route('///') +def share(tree=None, branch=None): + return render_template('share.html', tree=tree, branch=branch) diff --git a/exquisite_branch/static/css/display.css b/exquisite_branch/static/css/display.css index 42a3af3..5794859 100644 --- a/exquisite_branch/static/css/display.css +++ b/exquisite_branch/static/css/display.css @@ -13,9 +13,11 @@ margin: 0; .container{ display: block; - padding: 64px; + padding: 32px; } + + .stream, .streams{ /* white-space: nowrap; */ diff --git a/exquisite_branch/static/css/global.css b/exquisite_branch/static/css/global.css index c0c4166..a99e676 100644 --- a/exquisite_branch/static/css/global.css +++ b/exquisite_branch/static/css/global.css @@ -27,3 +27,33 @@ nav { nav > * + * { margin-left: 1ch; } + +header, main { +margin: 32px; +} + +main form { +display: flex; +flex-direction: column; +gap: 16px; +max-width: 80ch; +align-items: flex-start; +} + +form textarea, +form input { + font-size: 1rem; + font-family: serif; + border: none; + padding: 0.5em; + +} +textarea:focus, +input:focus { + outline: dotted white; + } + +textarea { + width: 80ch; + height: 25ch; +} diff --git a/exquisite_branch/templates/base.html b/exquisite_branch/templates/base.html index 9b2958e..247592a 100644 --- a/exquisite_branch/templates/base.html +++ b/exquisite_branch/templates/base.html @@ -14,7 +14,7 @@ {%block contents %} {%endblock%} diff --git a/exquisite_branch/templates/base_mako.html b/exquisite_branch/templates/base_mako.html index 1ae9a20..0a706d8 100644 --- a/exquisite_branch/templates/base_mako.html +++ b/exquisite_branch/templates/base_mako.html @@ -14,7 +14,7 @@ ${self.body()} diff --git a/exquisite_branch/templates/display.html b/exquisite_branch/templates/display.html index d8a0dc9..2bb26b1 100644 --- a/exquisite_branch/templates/display.html +++ b/exquisite_branch/templates/display.html @@ -33,7 +33,7 @@ <% transform[branch['branch']] = f'{transform[branch["parent"]]} rotate({random() * 0.04 + steer}turn) translateX(100%)' %>
- + ${branch['content']} ${branch['username']} diff --git a/exquisite_branch/templates/home.html b/exquisite_branch/templates/home.html index 5ce87d6..ebe4ee6 100644 --- a/exquisite_branch/templates/home.html +++ b/exquisite_branch/templates/home.html @@ -20,7 +20,7 @@
Start new
Continue from last
- Display results + Display results
diff --git a/exquisite_branch/templates/list.html b/exquisite_branch/templates/list.html new file mode 100644 index 0000000..a498c90 --- /dev/null +++ b/exquisite_branch/templates/list.html @@ -0,0 +1,28 @@ +<%inherit file="base_mako.html" /> + + +<%block name="head"> + + + +
+

Exquisite Excerpts

+

Here is a list of all the writings trees

+
+ + +
+ +
+ diff --git a/exquisite_branch/templates/share.html b/exquisite_branch/templates/share.html index 1a74f9d..e224d23 100644 --- a/exquisite_branch/templates/share.html +++ b/exquisite_branch/templates/share.html @@ -5,15 +5,16 @@ {%endblock%} {%block nav %} Home -Results +Results + {% endblock %} {%block contents %} diff --git a/exquisite_branch/templates/write.html b/exquisite_branch/templates/write.html index 94823cc..9b6128b 100644 --- a/exquisite_branch/templates/write.html +++ b/exquisite_branch/templates/write.html @@ -5,7 +5,14 @@ {%endblock%} {%block nav%} Home -Results + + + +{% if tree is undefined %} +See all +{% else %} +See tree +{% endif %} {%endblock%} {%block contents%} @@ -13,15 +20,30 @@ - +

Write

+
+ + +
+ +
- - - + + {% if tree is undefined %} + +
+ {% endif %} + +
+ +
+ +
+
{%endblock%} diff --git a/exquisite_branch/write.py b/exquisite_branch/write.py index 30535f0..724d996 100644 --- a/exquisite_branch/write.py +++ b/exquisite_branch/write.py @@ -1,16 +1,16 @@ -from flask import (Blueprint, flash, g, redirect, - render_template, request, session, url_for) +from flask import (Blueprint, redirect, render_template, request, url_for) from exquisite_branch.db import get_db from werkzeug.exceptions import abort +from werkzeug.utils import secure_filename from shortuuid import uuid bp = Blueprint('write', __name__, url_prefix='/write') -@bp.route('/', methods=('GET', 'POST')) -def write(parent=None): +@bp.route('//', methods=('GET', 'POST')) +def write(tree=None, parent=None): db = get_db() if request.method == 'POST': @@ -24,30 +24,28 @@ def write(parent=None): username = data['username'] db.execute( - 'INSERT INTO branches (content, parent, branch, username) VALUES (?, ?, ?, ?)', - (content, parent, branch, username) + 'INSERT INTO branches (content, parent, branch, username, tree) VALUES (?, ?, ?, ?, ?)', + (content, parent, branch, username, tree) ) db.commit() - print(url_for('share.share', branch=f"{branch}")) - return redirect(url_for('share.share', branch=branch)) + print(url_for('share.share', tree=tree, branch=branch)) + return redirect(url_for('share.share', tree=tree, branch=branch)) branch = uuid() previous = db.execute( "SELECT content, branch, parent FROM branches" - " WHERE branch = ?", - (parent,) + " WHERE branch = ? AND tree = ?", + (parent, tree) ).fetchone() - if previous is None: abort(404, f"Previous with id {parent} doesn't exist") - return render_template('write.html', parent=parent, content=previous['content'], branch=branch) + return render_template('write.html', tree=tree, parent=parent, content=previous['content'], branch=branch) @bp.route('/last', methods=('GET', 'POST')) def last(): - branch = uuid() db = get_db() previous = db.execute( @@ -55,6 +53,7 @@ def last(): ).fetchone() parent = previous['branch'] + tree = previous['tree'] if request.method == 'POST': content = request.form['content'] @@ -62,13 +61,13 @@ def last(): username = request.form['username'] db.execute( - 'INSERT INTO branches (content, parent, branch, username) VALUES (?, ?, ?, ?)', - (content, parent, branch, username) + 'INSERT INTO branches (content, parent, branch, username, tree) VALUES (?, ?, ?, ?, ?)', + (content, parent, branch, username, tree) ) db.commit() - return redirect(url_for('share.share', branch=branch)) + return redirect(url_for('share.share', tree=tree, branch=branch)) - return render_template('write.html', parent=parent, content=previous['content'], branch=branch) + return render_template('write.html', tree=tree, parent=parent, content=previous['content'], branch=branch) @bp.route('/', methods=('GET', 'POST')) @@ -80,14 +79,24 @@ def new(): if request.method == 'POST': content = request.form['content'] branch = request.form['branch'] - username = request.form['username'] + tree_name = request.form['tree_name'] + + if tree_name == '': + return redirect(url_for('write.new')) + + tree = secure_filename(tree_name) + + db.execute( + 'INSERT INTO trees (name, slug) VALUES (?, ?)', + (tree_name, tree) + ) db.execute( - 'INSERT INTO branches (content, parent, branch, username) VALUES (?, ?, ?, ?)', - (content, parent, branch, username) + 'INSERT INTO branches (content, parent, branch, username, tree) VALUES (?, ?, ?, ?, ?)', + (content, parent, branch, username, tree) ) db.commit() - return redirect(url_for('share.share', branch=branch)) + return redirect(url_for('share.share', tree=tree, branch=branch)) return render_template('write.html', parent=parent, branch=branch)