Browse Source

Handle "internal" users better in templates

Renames the username_linked macro to link_to_user and takes a User
object instead of a username, so that we can handle more than just the
"unknown user", including the new generic "Tildes" user.
merge-requests/85/head
Deimos 5 years ago
parent
commit
ec26072636
  1. 5
      tildes/tildes/models/user/user.py
  2. 2
      tildes/tildes/templates/bookmarks.jinja2
  3. 6
      tildes/tildes/templates/macros/comments.jinja2
  4. 8
      tildes/tildes/templates/macros/links.jinja2
  5. 4
      tildes/tildes/templates/macros/messages.jinja2
  6. 4
      tildes/tildes/templates/macros/topics.jinja2
  7. 4
      tildes/tildes/templates/messages.jinja2
  8. 2
      tildes/tildes/templates/notifications_unread.jinja2
  9. 6
      tildes/tildes/templates/topic.jinja2
  10. 2
      tildes/tildes/templates/user.jinja2

5
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."""

2
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 %}

6
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 %}
<span class="comment-user-info">
@ -119,7 +119,7 @@
<span class="comment-label-count">
{{ 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 %}
</span>
</li>

8
tildes/tildes/templates/macros/links.jinja2

@ -1,11 +1,11 @@
{# Copyright (c) 2018 Tildes contributors <code@tildes.net> #}
{# SPDX-License-Identifier: AGPL-3.0-or-later #}
{% macro username_linked(username) -%}
{% if username != "unknown user" %}
<a href="/user/{{ username }}" class="link-user">{{ username }}</a>
{% macro link_to_user(user) -%}
{% if user.is_real_user %}
<a href="/user/{{ user.username }}" class="link-user">{{ user.username }}</a>
{% else %}
{{ username }}
{{ user.username }}
{% endif %}
{%- endmacro %}

4
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 %}
<header>
{{ username_linked(message.sender.username) }}
{{ link_to_user(message.sender) }}
{{ adaptive_date_responsive(message.created_time) }}
</header>

4
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 @@
<div class="topic-info-source"
{% if topic.is_user_treated_as_source %}
aria-label="Posted by">{{ username_linked(topic.user.username) }}
aria-label="Posted by">{{ link_to_user(topic.user) }}
{% else %}
aria-label="Link source">
{% if topic.is_link_type %}

4
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 @@
<td class="message-list-subject">
<a href="{{ request.route_url('message_conversation', conversation_id36=conversation.conversation_id36) }}">{{ conversation.subject }}</a>
</td>
<td>{{ username_linked(conversation.other_user(request.user).username) }}</td>
<td>{{ link_to_user(conversation.other_user(request.user)) }}</td>
<td class="text-right">{{ adaptive_date_responsive(conversation.last_activity_time) }}</td>
<td class="text-right">{{ conversation.num_replies + 1 }}</td>
</tr>

2
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 %}

6
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 @@
<h1>{{ topic.title }}</h1>
<div class="topic-full-byline">Posted {{ adaptive_date_responsive(topic.created_time) }} by
{% if request.has_permission('view_author', topic) %}
{{ username_linked(topic.user.username) }}
{{ link_to_user(topic.user) }}
{% else %}
unknown user
{% endif %}
@ -288,7 +288,7 @@
{% if entry.user == topic.user and not request.has_permission('view_author', topic) %}
Unknown user
{% else %}
{{ username_linked(entry.user) }}
{{ link_to_user(entry.user) }}
{% endif %}
{{ entry }}
<span class="topic-log-entry-time">({{ time_ago(entry.event_time, abbreviate=True) }})</span>

2
tildes/tildes/templates/user.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 %}
{% from 'macros/topics.jinja2' import render_topic_for_listing with context %}
{% block title %}User: {{ user.username }}{% endblock %}

Loading…
Cancel
Save