Use user ids for author search instead of usernames.

This commit is contained in:
voussoir 2022-11-09 19:41:16 -08:00
parent 9fb45403df
commit fb2a5e9d56
3 changed files with 10 additions and 9 deletions

View file

@ -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.

View file

@ -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)

View file

@ -31,6 +31,9 @@
<div id="content_body">
<div id="hierarchy_self" class="panel">
<h1 id="display_name">{{user.display_name}}</h1>
{% if user.display_name != user.username %}
<p>Username: {{user.username}}</p>
{% endif %}
<p>ID: <a href="/userid/{{user.id}}"><code>{{user.id}}</code></a></p>
<p>User since <span title="{{user.created|timestamp_to_8601}}">{{user.created|timestamp_to_naturaldate}}.</span></p>
</div>
@ -38,7 +41,7 @@
{% set photos = user.get_photos(direction='desc')|islice(0, 15)|list %}
{% if photos %}
<div id="hierarchy_photos" class="panel">
<h2><a href="/search?author={{user.username}}">Photos by <span class="dynamic_user_display_name">{{user.display_name}}</span></a></h2>
<h2><a href="/search?author={{user.id}}">Photos by <span class="dynamic_user_display_name">{{user.display_name}}</span></a></h2>
{% for photo in photos %}
{{cards.create_photo_card(photo)}}
{% endfor %}