From 84bf9b90dec692f1196dbd53890b0d2b007037dc Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Sat, 9 Jan 2021 11:27:29 -0800 Subject: [PATCH] Add panels for user's created photos, albums, tags, bookmarks. --- .../etiquette_flask/backend/jinja_filters.py | 5 ++ frontends/etiquette_flask/templates/user.html | 53 ++++++++++++++++--- 2 files changed, 50 insertions(+), 8 deletions(-) diff --git a/frontends/etiquette_flask/backend/jinja_filters.py b/frontends/etiquette_flask/backend/jinja_filters.py index 2f3830c..a58f800 100644 --- a/frontends/etiquette_flask/backend/jinja_filters.py +++ b/frontends/etiquette_flask/backend/jinja_filters.py @@ -1,4 +1,5 @@ import datetime +import itertools import jinja2.filters import voussoirkit.bytestring @@ -45,6 +46,10 @@ def file_link(photo, short=False): basename = jinja2.filters.do_urlencode(photo.basename) return f'/file/{photo.id}/{basename}' +@filter_function +def islice(gen, start, stop): + return itertools.islice(gen, start, stop) + @filter_function def timestamp_to_8601(timestamp): return datetime.datetime.utcfromtimestamp(timestamp).isoformat(' ') + ' UTC' diff --git a/frontends/etiquette_flask/templates/user.html b/frontends/etiquette_flask/templates/user.html index ad58222..59744dd 100644 --- a/frontends/etiquette_flask/templates/user.html +++ b/frontends/etiquette_flask/templates/user.html @@ -1,12 +1,17 @@ + {% import "album_card.html" as album_card %} + {% import "bookmark_card.html" as bookmark_card %} + {% import "photo_card.html" as photo_card %} + {% import "tag_card.html" as tag_card %} {% import "header.html" as header %} {{user.display_name}} + {% if theme %}{% endif %} @@ -30,20 +35,52 @@ h2, h3 {{header.make_header(session=session)}}
-
+

{{user.display_name}}

ID: {{user.id}}

User since {{user.created|timestamp_to_naturaldate}}.

-
+ + {% set photos = user.get_photos(direction='desc')|islice(0, 15)|list %} + {% if photos %} +

Photos by {{user.display_name}}

- + {% for photo in photos %} + {{photo_card.create_photo_card(photo)}} + {% endfor %}
+ {% endif %} + + {% set tags = user.get_tags(direction='desc')|islice(0, 100)|list %} + {% if tags %} +
+

Tags by {{user.display_name}}

+ {% for tag in tags %} + {{tag_card.create_tag_card(tag, with_alt_description=True)}} + {% endfor %} +
+ {% endif %} + + {% set albums = user.get_albums()|islice(0, 20)|list %} + {% if albums %} +
+

Albums by {{user.display_name}}

+ {% for album in albums %} + {{album_card.create_album_card(album)}} + {% endfor %} +
+ {% endif %} + + {% set bookmarks = user.get_bookmarks()|islice(0, 50)|list %} + {% if bookmarks %} +
+

Bookmarks by {{user.display_name}}

+ {% for bookmark in bookmarks %} + {{bookmark_card.create_bookmark_card(bookmark)}} + {% endfor %} +
+ {% endif %} +