renovation label and small fixes in templates. linked list by default in view pages (sooo to be fixed)

main
km0 5 months ago
parent d9483f63b2
commit 85087c9f56

@ -1,47 +1,45 @@
from flask import (Blueprint, flash, g, redirect, from flask import (Blueprint)
request, session, url_for)
from flask_mako import render_template from flask_mako import render_template
from exquisite_branch.db import get_db from exquisite_branch.db import get_db
bp = Blueprint('display', __name__, url_prefix='/display') bp = Blueprint('display', __name__, url_prefix='/display')
@bp.route('/') # @bp.route('/')
def display(): # def display():
db = get_db() # db = get_db()
branches = db.execute( # branches = db.execute(
"SELECT content, branch, parent, username FROM branches" # "SELECT content, branch, parent, username FROM branches"
).fetchall() # ).fetchall()
streams = [] # streams = []
for branch in branches[::-1]: # for branch in branches[::-1]:
if branch not in flatten(streams): # if branch not in flatten(streams):
stream = [branch] # stream = [branch]
parent = branch['parent'] # parent = branch['parent']
while parent != 'NEW': # while parent != 'NEW':
current = next( # current = next(
(x for x in branches if x['branch'] == parent), None) # (x for x in branches if x['branch'] == parent), None)
parent = current['parent'] # parent = current['parent']
stream.append(current) # 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): # def flatten(t):
return [item for sublist in t for item in sublist] # return [item for sublist in t for item in sublist]
@bp.route('/linked') @bp.route('/')
def linked(): def display():
db = get_db() db = get_db()
branches = db.execute( branches = db.execute(
"SELECT content, branch, parent, username FROM branches" "SELECT content, branch, parent, username FROM branches"
).fetchall() ).fetchall()
return render_template('display_linked_mako.html', branches=branches) return render_template('display_linked_mako.html', branches=branches)

@ -4,7 +4,20 @@ from flask import (Blueprint, flash, g, redirect,
from exquisite_branch.db import get_db from exquisite_branch.db import get_db
from werkzeug.exceptions import abort 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') bp = Blueprint('draw', __name__, url_prefix='/draw')
@ -31,7 +44,8 @@ def draw(parent=None):
print(url_for('share.share', branch=f"{branch}")) print(url_for('share.share', branch=f"{branch}"))
return redirect(url_for('share.share', branch=branch)) return redirect(url_for('share.share', branch=branch))
branch = uuid() branch = get_uuid()
previous = db.execute( previous = db.execute(
"SELECT content, branch, parent FROM branches" "SELECT content, branch, parent FROM branches"
@ -48,7 +62,7 @@ def draw(parent=None):
@bp.route('/last', methods=('GET', 'POST')) @bp.route('/last', methods=('GET', 'POST'))
def last(): def last():
branch = uuid() branch = get_uuid()
db = get_db() db = get_db()
previous = db.execute( previous = db.execute(
'SELECT * FROM branches ORDER BY id DESC LIMIT 1' 'SELECT * FROM branches ORDER BY id DESC LIMIT 1'
@ -74,7 +88,7 @@ def last():
@bp.route('/', methods=('GET', 'POST')) @bp.route('/', methods=('GET', 'POST'))
def new(): def new():
db = get_db() db = get_db()
branch = uuid() branch = get_uuid()
parent = 'NEW' parent = 'NEW'
if request.method == 'POST': if request.method == 'POST':

@ -13,8 +13,8 @@
<body> <body>
<nav> <nav>
<%block name='nav' > <%block name='nav' >
<a href="{{url_for('home.home')}}">Home</a> <a href="${url_for('home.home')}">Home</a>
<a href="{{url_for('display.display')}}">Results</a> <a href="${url_for('display.display')}">Results</a>
</%block> </%block>
</nav> </nav>
${self.body()} ${self.body()}

@ -43,4 +43,4 @@
% endfor % endfor
</div> </div>
</main> </main>

@ -1,21 +1,18 @@
<%inherit file="base_mako.html" /> <%inherit file="base_mako.html" />
<%block name="head"> <%block name="head">
<link rel="stylesheet" href="${url_for('static', filename='css/display_mako.css')}"> <link rel="stylesheet" href="${url_for('static', filename='css/display_mako.css')}">
</%block> </%block>
<% from random import random %> <% from random import random %>
<% offset = 1 / (len(streams) - 1)%> <% offset = 1 / (len(streams) + 1)%>
% for stream in streams: % for stream in streams:
<div class="stream"> <div class="stream">
<% transform = f'rotate({offset * loop.index}turn) translateX(100%) ' %> <% 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%)'%> <% transform = transform + ' rotate(' + str((random() * 2 - 1) * 0.02) + 'turn) translateX(100%)'%>
<div class="svg-container" style="transform: ${transform}">${branch['content']}</div> <div class="svg-container" style="transform: ${transform}">${branch['content']}</div>
% endfor % endfor
</div> </div>
% endfor % endfor

@ -8,6 +8,20 @@
<link rel="stylesheet" href="{{url_for('static', filename='css/variables.css')}}" /> <link rel="stylesheet" href="{{url_for('static', filename='css/variables.css')}}" />
<link rel="stylesheet" href="{{url_for('static', filename='css/global.css')}}" /> <link rel="stylesheet" href="{{url_for('static', filename='css/global.css')}}" />
<link rel="stylesheet" href="{{url_for('static', filename='css/home.css')}}" /> <link rel="stylesheet" href="{{url_for('static', filename='css/home.css')}}" />
<style>
.renovation
{
background-color: yellow;
display: inline-block;
transform: translateY(-90px) rotate(10deg);
padding: 8px;
font-size: 0.88rem;
font-family: 'Brush Script MT', cursive;
}
</style>
</head> </head>
<body> <body>
<header class="title"> <header class="title">
@ -17,6 +31,7 @@
></object> ></object>
<h1>really exquisite indeed</h1> <h1>really exquisite indeed</h1>
<span class='renovation'>RENOVATION IN PROGRESS!</span>
</header> </header>
<main> <main>
<a href="{{url_for('draw.new')}}">Start new</a> <br /> <a href="{{url_for('draw.new')}}">Start new</a> <br />

Loading…
Cancel
Save