From 85087c9f56e54ab817541d3cec77a835b28450ad Mon Sep 17 00:00:00 2001 From: km0 Date: Wed, 12 Jun 2024 01:29:32 +0200 Subject: [PATCH] renovation label and small fixes in templates. linked list by default in view pages (sooo to be fixed) --- exquisite_branch/display.py | 50 +++++++++---------- exquisite_branch/draw.py | 22 ++++++-- exquisite_branch/templates/base_mako.html | 4 +- .../templates/display_linked_mako.html | 2 +- exquisite_branch/templates/display_mako.html | 13 ++--- exquisite_branch/templates/home.html | 15 ++++++ 6 files changed, 65 insertions(+), 41 deletions(-) diff --git a/exquisite_branch/display.py b/exquisite_branch/display.py index 3559c05..1def320 100644 --- a/exquisite_branch/display.py +++ b/exquisite_branch/display.py @@ -1,47 +1,45 @@ -from flask import (Blueprint, flash, g, redirect, - request, session, url_for) +from flask import (Blueprint) from flask_mako import render_template - from exquisite_branch.db import get_db bp = Blueprint('display', __name__, url_prefix='/display') -@bp.route('/') -def display(): - db = get_db() +# @bp.route('/') +# def display(): +# db = get_db() - branches = db.execute( - "SELECT content, branch, parent, username FROM branches" - ).fetchall() +# branches = db.execute( +# "SELECT content, branch, parent, username FROM branches" +# ).fetchall() - streams = [] - for branch in branches[::-1]: - if branch not in flatten(streams): - stream = [branch] - parent = branch['parent'] - while parent != 'NEW': - current = next( - (x for x in branches if x['branch'] == parent), None) - parent = current['parent'] - stream.append(current) +# streams = [] +# for branch in branches[::-1]: +# if branch not in flatten(streams): +# stream = [branch] +# parent = branch['parent'] +# while parent != 'NEW': +# current = next( +# (x for x in branches if x['branch'] == parent), None) +# parent = current['parent'] +# stream.append(current) - streams.append(stream[::-1]) +# streams.append(stream[::-1]) - return render_template('display_mako.html', branches=branches, streams=streams) +# return render_template('display_mako.html', branches=branches, streams=streams) -def flatten(t): - return [item for sublist in t for item in sublist] +# def flatten(t): +# return [item for sublist in t for item in sublist] -@bp.route('/linked') -def linked(): +@bp.route('/') +def display(): db = get_db() branches = db.execute( "SELECT content, branch, parent, username FROM branches" ).fetchall() - return render_template('display_linked_mako.html', branches=branches) \ No newline at end of file + return render_template('display_linked_mako.html', branches=branches) diff --git a/exquisite_branch/draw.py b/exquisite_branch/draw.py index c8adfa1..b855670 100644 --- a/exquisite_branch/draw.py +++ b/exquisite_branch/draw.py @@ -4,7 +4,20 @@ from flask import (Blueprint, flash, g, redirect, from exquisite_branch.db import get_db from werkzeug.exceptions import abort -from shortuuid import uuid +import shortuuid +import uuid + + +def get_uuid(d=7): + '''return a short uuid (default 7 chars)''' + u = uuid.uuid4() + s = shortuuid.encode(u) + return s[:d] + + + + + bp = Blueprint('draw', __name__, url_prefix='/draw') @@ -31,7 +44,8 @@ def draw(parent=None): print(url_for('share.share', branch=f"{branch}")) return redirect(url_for('share.share', branch=branch)) - branch = uuid() + branch = get_uuid() + previous = db.execute( "SELECT content, branch, parent FROM branches" @@ -48,7 +62,7 @@ def draw(parent=None): @bp.route('/last', methods=('GET', 'POST')) def last(): - branch = uuid() + branch = get_uuid() db = get_db() previous = db.execute( 'SELECT * FROM branches ORDER BY id DESC LIMIT 1' @@ -74,7 +88,7 @@ def last(): @bp.route('/', methods=('GET', 'POST')) def new(): db = get_db() - branch = uuid() + branch = get_uuid() parent = 'NEW' if request.method == 'POST': diff --git a/exquisite_branch/templates/base_mako.html b/exquisite_branch/templates/base_mako.html index d158eae..1ae9a20 100644 --- a/exquisite_branch/templates/base_mako.html +++ b/exquisite_branch/templates/base_mako.html @@ -13,8 +13,8 @@ ${self.body()} diff --git a/exquisite_branch/templates/display_linked_mako.html b/exquisite_branch/templates/display_linked_mako.html index d9c0563..5590c29 100644 --- a/exquisite_branch/templates/display_linked_mako.html +++ b/exquisite_branch/templates/display_linked_mako.html @@ -43,4 +43,4 @@ % endfor - \ No newline at end of file + diff --git a/exquisite_branch/templates/display_mako.html b/exquisite_branch/templates/display_mako.html index e40b892..d12eeb0 100644 --- a/exquisite_branch/templates/display_mako.html +++ b/exquisite_branch/templates/display_mako.html @@ -1,21 +1,18 @@ - - - - <%inherit file="base_mako.html" /> <%block name="head"> - + <% from random import random %> -<% offset = 1 / (len(streams) - 1)%> +<% offset = 1 / (len(streams) + 1)%> + % for stream in streams:
<% transform = f'rotate({offset * loop.index}turn) translateX(100%) ' %> - % for branch in stream: + % for branch in stream: <% transform = transform + ' rotate(' + str((random() * 2 - 1) * 0.02) + 'turn) translateX(100%)'%>
${branch['content']}
% endfor
-% endfor \ No newline at end of file +% endfor diff --git a/exquisite_branch/templates/home.html b/exquisite_branch/templates/home.html index 9b4bbd7..6ea101a 100644 --- a/exquisite_branch/templates/home.html +++ b/exquisite_branch/templates/home.html @@ -8,6 +8,20 @@ + +
@@ -17,6 +31,7 @@ >

really exquisite indeed

+ RENOVATION IN PROGRESS!
Start new