# HG changeset patch # User paulo # Date 1619859548 25200 # Node ID d216dd8e63da1d87561145493f6cda908c7882a2 # Parent 9b57b90aea31afee7fe2d2027815ff41a2333d80 pics3: implement thumbs page diff -r 9b57b90aea31 -r d216dd8e63da pics3/pics_flask_app.py --- a/pics3/pics_flask_app.py Thu Mar 25 00:33:42 2021 -0700 +++ b/pics3/pics_flask_app.py Sat May 01 01:59:08 2021 -0700 @@ -87,6 +87,17 @@ body.text(" ") +def _go_thumbnail_links_to_thumbs_html_body(body, d, t, a_args={}, img_args={}): + thumb_img_url = GCS_BUCKET.get_blob(t).public_url + thumbs_url_args = {"from": os.path.basename(t), "_anchor": "selected"} + thumbs_url = flask.url_for("thumbs", d=d, **thumbs_url_args) + + a = body.a(href=thumbs_url, **a_args) + a.img(src=thumb_img_url, **img_args) + + body.text(" ") + + @app.route("/") def index(): n = 5 # number of thumbnails to display per dir @@ -94,22 +105,18 @@ (root, header, body) = _get_standard_html_doc("Pictures") header.script('', type="text/javascript", src=flask.url_for("static", filename="lazyload.js")) - #body.pre(str(list(GCS_CLIENT.list_blobs(GCS_BUCKET)))) - pics_dirs = [] pics_dirs_index_blob = GCS_BUCKET.get_blob("pics/index.tsv") if pics_dirs_index_blob: pics_dirs_index_strlist = pics_dirs_index_blob.download_as_text().splitlines() pics_dirs_index_reader = csv.reader(pics_dirs_index_strlist, PICSDIALECT) - pics_dirs = sorted(pics_dirs_index_reader, key=lambda x: x[0]) + pics_dirs = sorted(pics_dirs_index_reader, key=lambda x: x[0], reverse=True) for (dts, d) in pics_dirs: dt = _parse_dt(dts) - body.h2(d) + body.h2.a(d, href=flask.url_for("thumbs", d=d)) body.h3(_format_dt(dt)) - #body.pre(str(list(_get_images(d)))) - imgs = _get_images(d) imgs_idx = [(i, img) for (i, img) in enumerate(imgs)] @@ -166,18 +173,38 @@ (t, b) = img_c a_args = {} img_args = {} - # FIXME - #if b == img: - # a_args = {"id": "up"} - # img_args = {"klass": "sel"} - # b = f"{d}?from={img}#selected" - if False: - pass + if os.path.basename(b) == img: + a_args = {"id": "up"} + img_args = {"klass": "sel"} + b = None elif i == v + 1: a_args = {"id": "next"} elif i == v - 1: a_args = {"id": "prev"} - _go_thumbnail_links_to_browse_imgs_html_body(p, d, t, b, a_args, img_args) + if b is None: + _go_thumbnail_links_to_thumbs_html_body(p, d, t, a_args, img_args) + else: + _go_thumbnail_links_to_browse_imgs_html_body(p, d, t, b, a_args, img_args) return str(root).encode("utf-8") + + +@app.route("/") +def thumbs(d): + args = flask.request.args + print(f"args = {args}") + + from_img = args.get("from") + + imgs = list(_get_images(d)) + (root, header, body) = _get_standard_html_doc(d) + + p = body.p + for (t, b) in imgs: + img_args = {} + if os.path.basename(b) == from_img: + img_args={"klass": "sel2", "id":"selected"} + _go_thumbnail_links_to_browse_imgs_html_body(p, d, t, b, img_args=img_args) + + return str(root).encode("utf-8")