|
|
|
@ -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('/<parent>', methods=('GET', 'POST'))
|
|
|
|
|
def write(parent=None):
|
|
|
|
|
@bp.route('/<tree>/<parent>', 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)
|
|
|
|
|