From fb2a5e9d5626c75e92c11a2a28b1333842b0a185 Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Wed, 9 Nov 2022 19:41:16 -0800 Subject: [PATCH] Use user ids for author search instead of usernames. --- README.md | 1 - etiquette/searchhelpers.py | 13 ++++++------- frontends/etiquette_flask/templates/user.html | 5 ++++- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 3028c2f..c28a9c0 100644 --- a/README.md +++ b/README.md @@ -178,7 +178,6 @@ Here is a brief overview of the project to help you learn your way around: - Make the wording between "new", "create", "add"; and "remove", "delete" more consistent. - User account system, permission levels, private pages. -- Ability to access user photos by user's ID, not just username. - Replace columns like area, ratio, bitrate by using expression indices or views (`width * height` etc). - Add a `Photo.merge` to combine duplicate entries. - Generate thumbnails for vector files without falling victim to bombs. diff --git a/etiquette/searchhelpers.py b/etiquette/searchhelpers.py index 436c26d..405d4e2 100644 --- a/etiquette/searchhelpers.py +++ b/etiquette/searchhelpers.py @@ -122,12 +122,10 @@ def minmax(key, value, minimums, maximums, warning_bag=None): def normalize_author(authors, photodb, warning_bag=None): ''' Either: - - A string, where the usernames are separated by commas - - An iterable containing - - Usernames as strings - - User objects + - A string, where the user IDs are separated by commas + - An iterable containing IDs or User objects - Returns: A set of user IDs. + Returns: A set of User objects. ''' if authors is None: authors = [] @@ -140,11 +138,12 @@ def normalize_author(authors, photodb, warning_bag=None): if isinstance(requested_author, objects.User): if requested_author.photodb == photodb: users.add(requested_author) + continue else: - requested_author = requested_author.username + requested_author = requested_author.id try: - user = photodb.get_user(username=requested_author) + user = photodb.get_user_by_id(requested_author) except exceptions.NoSuchUser as exc: if warning_bag: warning_bag.add(exc) diff --git a/frontends/etiquette_flask/templates/user.html b/frontends/etiquette_flask/templates/user.html index a72fab6..16df03e 100644 --- a/frontends/etiquette_flask/templates/user.html +++ b/frontends/etiquette_flask/templates/user.html @@ -31,6 +31,9 @@

{{user.display_name}}

+ {% if user.display_name != user.username %} +

Username: {{user.username}}

+ {% endif %}

ID: {{user.id}}

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

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

Photos by {{user.display_name}}

+

Photos by {{user.display_name}}

{% for photo in photos %} {{cards.create_photo_card(photo)}} {% endfor %}