changeset 125:d216dd8e63da

pics3: implement thumbs page
author paulo
date Sat, 01 May 2021 01:59:08 -0700
parents 9b57b90aea31
children a00f9d3beb9b
files pics3/pics_flask_app.py
diffstat 1 files changed, 41 insertions(+), 14 deletions(-) [+]
line diff
     1.1 --- a/pics3/pics_flask_app.py	Thu Mar 25 00:33:42 2021 -0700
     1.2 +++ b/pics3/pics_flask_app.py	Sat May 01 01:59:08 2021 -0700
     1.3 @@ -87,6 +87,17 @@
     1.4    body.text(" ")
     1.5  
     1.6  
     1.7 +def _go_thumbnail_links_to_thumbs_html_body(body, d, t, a_args={}, img_args={}):
     1.8 +  thumb_img_url = GCS_BUCKET.get_blob(t).public_url
     1.9 +  thumbs_url_args = {"from": os.path.basename(t), "_anchor": "selected"}
    1.10 +  thumbs_url = flask.url_for("thumbs", d=d, **thumbs_url_args)
    1.11 +  
    1.12 +  a = body.a(href=thumbs_url, **a_args)
    1.13 +  a.img(src=thumb_img_url, **img_args)
    1.14 +
    1.15 +  body.text(" ")
    1.16 +
    1.17 +
    1.18  @app.route("/")
    1.19  def index():
    1.20    n = 5 # number of thumbnails to display per dir
    1.21 @@ -94,22 +105,18 @@
    1.22    (root, header, body) = _get_standard_html_doc("Pictures")
    1.23    header.script('', type="text/javascript", src=flask.url_for("static", filename="lazyload.js"))
    1.24  
    1.25 -  #body.pre(str(list(GCS_CLIENT.list_blobs(GCS_BUCKET))))
    1.26 -
    1.27    pics_dirs = []
    1.28    pics_dirs_index_blob = GCS_BUCKET.get_blob("pics/index.tsv")
    1.29    if pics_dirs_index_blob:
    1.30      pics_dirs_index_strlist = pics_dirs_index_blob.download_as_text().splitlines()
    1.31      pics_dirs_index_reader = csv.reader(pics_dirs_index_strlist, PICSDIALECT)
    1.32 -    pics_dirs = sorted(pics_dirs_index_reader, key=lambda x: x[0])
    1.33 +    pics_dirs = sorted(pics_dirs_index_reader, key=lambda x: x[0], reverse=True)
    1.34  
    1.35    for (dts, d) in pics_dirs:
    1.36      dt = _parse_dt(dts)
    1.37 -    body.h2(d)
    1.38 +    body.h2.a(d, href=flask.url_for("thumbs", d=d))
    1.39      body.h3(_format_dt(dt))
    1.40  
    1.41 -    #body.pre(str(list(_get_images(d))))
    1.42 -
    1.43      imgs = _get_images(d)
    1.44      imgs_idx = [(i, img) for (i, img) in enumerate(imgs)]
    1.45      
    1.46 @@ -166,18 +173,38 @@
    1.47        (t, b) = img_c
    1.48        a_args = {}
    1.49        img_args = {}
    1.50 -       # FIXME
    1.51 -      #if b == img:
    1.52 -      #  a_args = {"id": "up"}
    1.53 -      #  img_args = {"klass": "sel"}
    1.54 -      #  b = f"{d}?from={img}#selected"
    1.55 -      if False:
    1.56 -        pass
    1.57 +      if os.path.basename(b) == img:
    1.58 +        a_args = {"id": "up"}
    1.59 +        img_args = {"klass": "sel"}
    1.60 +        b = None
    1.61        elif i == v + 1:
    1.62          a_args = {"id": "next"}
    1.63        elif i == v - 1:
    1.64          a_args = {"id": "prev"}
    1.65      
    1.66 -      _go_thumbnail_links_to_browse_imgs_html_body(p, d, t, b, a_args, img_args)
    1.67 +      if b is None:
    1.68 +        _go_thumbnail_links_to_thumbs_html_body(p, d, t, a_args, img_args)
    1.69 +      else:
    1.70 +        _go_thumbnail_links_to_browse_imgs_html_body(p, d, t, b, a_args, img_args)
    1.71  
    1.72    return str(root).encode("utf-8")
    1.73 +
    1.74 +
    1.75 +@app.route("/<d>")
    1.76 +def thumbs(d):
    1.77 +  args = flask.request.args
    1.78 +  print(f"args = {args}")
    1.79 +
    1.80 +  from_img = args.get("from")
    1.81 +
    1.82 +  imgs = list(_get_images(d))
    1.83 +  (root, header, body) = _get_standard_html_doc(d)
    1.84 +
    1.85 +  p = body.p
    1.86 +  for (t, b) in imgs:
    1.87 +    img_args = {}
    1.88 +    if os.path.basename(b) == from_img:
    1.89 +      img_args={"klass": "sel2", "id":"selected"}
    1.90 +    _go_thumbnail_links_to_browse_imgs_html_body(p, d, t, b, img_args=img_args)
    1.91 +
    1.92 +  return str(root).encode("utf-8")