diff --git a/tildes/tildes/models/user/user.py b/tildes/tildes/models/user/user.py index 9a1c22d..a49a965 100644 --- a/tildes/tildes/models/user/user.py +++ b/tildes/tildes/models/user/user.py @@ -320,6 +320,11 @@ class User(DatabaseModel): return principals + @property + def is_real_user(self) -> bool: + """Return whether this is a "real" user (not a special-purpose internal one).""" + return self.user_id > 0 + @property def is_admin(self) -> bool: """Return whether the user has admin permissions.""" diff --git a/tildes/tildes/templates/bookmarks.jinja2 b/tildes/tildes/templates/bookmarks.jinja2 index fafb361..24f552c 100644 --- a/tildes/tildes/templates/bookmarks.jinja2 +++ b/tildes/tildes/templates/bookmarks.jinja2 @@ -1,7 +1,7 @@ {% extends 'base_user_menu.jinja2' %} {% from 'macros/comments.jinja2' import render_single_comment with context %} -{% from 'macros/links.jinja2' import group_linked, username_linked %} +{% from 'macros/links.jinja2' import group_linked %} {% from 'macros/topics.jinja2' import render_topic_for_listing with context %} {% block title %}Bookmarks{% endblock %} diff --git a/tildes/tildes/templates/macros/comments.jinja2 b/tildes/tildes/templates/macros/comments.jinja2 index 19a1bfc..8ae7531 100644 --- a/tildes/tildes/templates/macros/comments.jinja2 +++ b/tildes/tildes/templates/macros/comments.jinja2 @@ -4,7 +4,7 @@ {% from 'buttons.jinja2' import post_action_toggle_button with context %} {% from 'datetime.jinja2' import adaptive_date_responsive %} {% from 'forms.jinja2' import markdown_textarea %} -{% from 'links.jinja2' import username_linked %} +{% from 'links.jinja2' import link_to_user %} {% from 'utils.jinja2' import pluralize %} {% macro render_single_comment(comment) %} @@ -53,7 +53,7 @@ {% endif %} {% if request.has_permission('view', comment) %} - {{ username_linked(comment.user.username) }} + {{ link_to_user(comment.user) }} {% if request.has_permission('view_author', comment.topic) and comment.topic.user == comment.user %} @@ -119,7 +119,7 @@ {{ weight }}: {% for label in comment.labels if label.name == label_name %} - {{ username_linked(label.user.username) }} ({{ label.weight }}{{ ' "%s"' % label.reason if label.reason else '' }}) + {{ link_to_user(label.user) }} ({{ label.weight }}{{ ' "%s"' % label.reason if label.reason else '' }}) {% endfor %} diff --git a/tildes/tildes/templates/macros/links.jinja2 b/tildes/tildes/templates/macros/links.jinja2 index fdbd725..710dfa9 100644 --- a/tildes/tildes/templates/macros/links.jinja2 +++ b/tildes/tildes/templates/macros/links.jinja2 @@ -1,11 +1,11 @@ {# Copyright (c) 2018 Tildes contributors #} {# SPDX-License-Identifier: AGPL-3.0-or-later #} -{% macro username_linked(username) -%} - {% if username != "unknown user" %} - {{ username }} +{% macro link_to_user(user) -%} + {% if user.is_real_user %} + {{ user.username }} {% else %} - {{ username }} + {{ user.username }} {% endif %} {%- endmacro %} diff --git a/tildes/tildes/templates/macros/messages.jinja2 b/tildes/tildes/templates/macros/messages.jinja2 index 2896e1d..ab47535 100644 --- a/tildes/tildes/templates/macros/messages.jinja2 +++ b/tildes/tildes/templates/macros/messages.jinja2 @@ -2,7 +2,7 @@ {# SPDX-License-Identifier: AGPL-3.0-or-later #} {% from 'macros/datetime.jinja2' import adaptive_date_responsive %} -{% from 'macros/links.jinja2' import username_linked %} +{% from 'macros/links.jinja2' import link_to_user %} {% macro render_message(message) %} {% if message.sender == request.user %} @@ -12,7 +12,7 @@ {% endif %}
- {{ username_linked(message.sender.username) }} + {{ link_to_user(message.sender) }} {{ adaptive_date_responsive(message.created_time) }}
diff --git a/tildes/tildes/templates/macros/topics.jinja2 b/tildes/tildes/templates/macros/topics.jinja2 index 7e6e67f..f950315 100644 --- a/tildes/tildes/templates/macros/topics.jinja2 +++ b/tildes/tildes/templates/macros/topics.jinja2 @@ -2,7 +2,7 @@ {# SPDX-License-Identifier: AGPL-3.0-or-later #} {% from 'macros/datetime.jinja2' import adaptive_date_responsive %} -{% from 'macros/links.jinja2' import group_linked, username_linked %} +{% from 'macros/links.jinja2' import group_linked, link_to_user %} {% from 'utils.jinja2' import pluralize %} {% macro render_topic_for_listing(topic, show_group=False, rank=None) %} @@ -90,7 +90,7 @@
{{ username_linked(topic.user.username) }} + aria-label="Posted by">{{ link_to_user(topic.user) }} {% else %} aria-label="Link source"> {% if topic.is_link_type %} diff --git a/tildes/tildes/templates/messages.jinja2 b/tildes/tildes/templates/messages.jinja2 index f969de7..575e318 100644 --- a/tildes/tildes/templates/messages.jinja2 +++ b/tildes/tildes/templates/messages.jinja2 @@ -4,7 +4,7 @@ {% extends 'base_user_menu.jinja2' %} {% from 'macros/datetime.jinja2' import adaptive_date_responsive %} -{% from 'macros/links.jinja2' import username_linked %} +{% from 'macros/links.jinja2' import link_to_user %} {% block title %}Message Inbox{% endblock %} @@ -30,7 +30,7 @@ {{ conversation.subject }} - {{ username_linked(conversation.other_user(request.user).username) }} + {{ link_to_user(conversation.other_user(request.user)) }} {{ adaptive_date_responsive(conversation.last_activity_time) }} {{ conversation.num_replies + 1 }} diff --git a/tildes/tildes/templates/notifications_unread.jinja2 b/tildes/tildes/templates/notifications_unread.jinja2 index 4c1dd33..bdb5f0b 100644 --- a/tildes/tildes/templates/notifications_unread.jinja2 +++ b/tildes/tildes/templates/notifications_unread.jinja2 @@ -4,7 +4,7 @@ {% extends 'base_user_menu.jinja2' %} {% from 'macros/comments.jinja2' import comment_label_options_template, comment_reply_template, render_single_comment with context %} -{% from 'macros/links.jinja2' import group_linked, username_linked %} +{% from 'macros/links.jinja2' import group_linked %} {% block title %}Unread notifications{% endblock %} diff --git a/tildes/tildes/templates/topic.jinja2 b/tildes/tildes/templates/topic.jinja2 index b1251fa..c093ef1 100644 --- a/tildes/tildes/templates/topic.jinja2 +++ b/tildes/tildes/templates/topic.jinja2 @@ -8,7 +8,7 @@ {% from 'macros/datetime.jinja2' import adaptive_date_responsive, time_ago %} {% from 'macros/forms.jinja2' import markdown_textarea %} {% from 'macros/groups.jinja2' import group_segmented_link %} -{% from 'macros/links.jinja2' import group_linked, username_linked %} +{% from 'macros/links.jinja2' import group_linked, link_to_user %} {% from 'macros/topics.jinja2' import topic_voting with context %} {% from 'macros/utils.jinja2' import pluralize %} @@ -37,7 +37,7 @@

{{ topic.title }}