From 60e0cb118b5821858ea2c0c9920381f562474095 Mon Sep 17 00:00:00 2001 From: carofun Date: Mon, 8 Feb 2021 18:21:15 +0100 Subject: [PATCH] Add view partials for repeated content on post or topic writer If we want to override the way the last writer of a post or a topic is shown, the project forces us to repeat our modification in multiple templates. We introduce two different partials to simplify the overload. --- .../templates/machina/forum/forum_list.html | 22 ++-------------- .../forum_conversation/post_create.html | 15 +++-------- .../forum_conversation/topic_detail.html | 17 ++++-------- .../forum_conversation/topic_list.html | 22 ++-------------- .../machina/forum_member/user_posts_list.html | 7 ++--- .../moderation_queue/detail.html | 26 +++---------------- .../moderation_queue/list.html | 13 +++------- .../templates/machina/partials/posted_by.html | 16 ++++++++++++ .../machina/partials/profile_link.html | 10 +++++++ 9 files changed, 48 insertions(+), 100 deletions(-) create mode 100644 machina/templates/machina/partials/posted_by.html create mode 100644 machina/templates/machina/partials/profile_link.html diff --git a/machina/templates/machina/forum/forum_list.html b/machina/templates/machina/forum/forum_list.html index ac00f087d..4828a0583 100644 --- a/machina/templates/machina/forum/forum_list.html +++ b/machina/templates/machina/forum/forum_list.html @@ -72,16 +72,7 @@

{% trans "Forums" %}

{{ node.posts_count }}
{% if node.last_post %} - {% if node.last_post.poster %} - {% url 'forum_member:profile' node.last_post.poster_id as poster_url %} - {% blocktrans trimmed with poster_url=poster_url username=node.last_post.poster|forum_member_display_name %} - By: {{ username }} - {% endblocktrans %} - {% else %} - {% blocktrans trimmed with poster_username=node.last_post.username %} - By: {{ poster_username }} - {% endblocktrans %} - {% endif %} + {% include "partials/posted_by.html" with poster=node.last_post.poster username=poster_username %}  
{{ node.last_post.created }} @@ -145,16 +136,7 @@

{% trans "Forums" %}

{{ node.posts_count }}
{% if node.last_post %} - {% if node.last_post.poster_id %} - {% url 'forum_member:profile' node.last_post.poster_id as poster_url %} - {% blocktrans trimmed with poster_url=poster_url username=node.last_post.poster|forum_member_display_name %} - By: {{ username }} - {% endblocktrans %} - {% else %} - {% blocktrans trimmed with poster_username=node.last_post.username %} - By: {{ poster_username }} - {% endblocktrans %} - {% endif %} + {% include "partials/posted_by.html" with poster=node.last_post.poster username=poster_username %}  
{{ node.last_post.created }} diff --git a/machina/templates/machina/forum_conversation/post_create.html b/machina/templates/machina/forum_conversation/post_create.html index ce9aeac07..5be8f149c 100644 --- a/machina/templates/machina/forum_conversation/post_create.html +++ b/machina/templates/machina/forum_conversation/post_create.html @@ -46,16 +46,7 @@

{{ post.subject }}

{% spaceless %}   - {% if post.poster %} - {% url 'forum_member:profile' post.poster_id as poster_url %} - {% blocktrans trimmed with poster_url=poster_url username=post.poster|forum_member_display_name creation_date=post.created %} - By: {{ username }} on {{ creation_date }} - {% endblocktrans %} - {% else %} - {% blocktrans trimmed with poster_username=post.username creation_date=post.created %} - By: {{ poster_username }} on {{ creation_date }} - {% endblocktrans %} - {% endif %} + {% include "partials/posted_by.html" with poster=post.poster creation_date=post.created username=poster_username %} {% endspaceless %}

@@ -64,7 +55,9 @@

{{ post.subject }}

{% include "forum_conversation/forum_attachments/attachments_detail.html" %}
{% endfor %} diff --git a/machina/templates/machina/forum_conversation/topic_detail.html b/machina/templates/machina/forum_conversation/topic_detail.html index d1b5875de..6718136cb 100644 --- a/machina/templates/machina/forum_conversation/topic_detail.html +++ b/machina/templates/machina/forum_conversation/topic_detail.html @@ -45,21 +45,14 @@

{% endspaceless %}

+ {% block written_by %} {% spaceless %}   - {% if post.poster %} - {% url 'forum_member:profile' post.poster_id as poster_url %} - {% blocktrans trimmed with poster_url=poster_url username=post.poster|forum_member_display_name creation_date=post.created %} - By: {{ username }} on {{ creation_date }} - {% endblocktrans %} - {% else %} - {% blocktrans trimmed with poster_username=post.username creation_date=post.created %} - By: {{ poster_username }} on {{ creation_date }} - {% endblocktrans %} - {% endif %} + {% include "partials/posted_by.html" with poster=post.poster creation_date=post.created username=poster_username %} {% endspaceless %} + {% endblock %}

{{ post.content.rendered }} @@ -73,7 +66,7 @@

{% if post.updates_count %}
-  {% if post.updated_by %}{% trans "Last edited by:" %} {{ post.updated_by|forum_member_display_name }} {% else %}{% trans "Updated" %} {% endif %}{% trans "on" %} {{ post.updated }}, {% blocktrans count counter=post.updates_count %}edited {{counter }} time in total.{% plural %}edited {{counter }} times in total.{% endblocktrans %} +  {% if post.updated_by %}{% trans "Last edited by:" %} {% include "partials/profile_link.html" with poster=post.updated_by %} {% else %}{% trans "Updated" %} {% endif %}{% trans "on" %} {{ post.updated }}, {% blocktrans count counter=post.updates_count %}edited {{counter }} time in total.{% plural %}edited {{counter }} times in total.{% endblocktrans %} {% if post.update_reason %}
@@ -91,7 +84,7 @@

{% include "partials/avatar.html" with profile=post.poster.forum_profile show_placeholder=True %}

- +
{% include "partials/profile_link.html" with poster=post.poster username_highlighted=True %}
{% trans "Posts:" %} {{ post.poster.forum_profile.posts_count }}
{% else %}
{{ post.username }}
diff --git a/machina/templates/machina/forum_conversation/topic_list.html b/machina/templates/machina/forum_conversation/topic_list.html index f8c0305fd..913b4fca0 100644 --- a/machina/templates/machina/forum_conversation/topic_list.html +++ b/machina/templates/machina/forum_conversation/topic_list.html @@ -29,16 +29,7 @@ {{ topic.subject }}{% if topic.is_locked %} {% endif %}
- {% if topic.poster %} - {% url 'forum_member:profile' topic.poster_id as poster_url %} - {% blocktrans trimmed with poster_url=poster_url username=topic.poster|forum_member_display_name creation_date=topic.created %} - By: {{ username }} on {{ creation_date }} - {% endblocktrans %} - {% else %} - {% blocktrans trimmed with poster_username=topic.first_post.username creation_date=topic.created %} - By: {{ poster_username }} on {{ creation_date }} - {% endblocktrans %} - {% endif %} + {% include "partials/posted_by.html" with poster=topic.poster creation_date=topic.created username=poster_username %}
@@ -49,16 +40,7 @@
{{ topic.views_count }}
{% with last_post=topic.last_post %} - {% if last_post.poster %} - {% url 'forum_member:profile' last_post.poster_id as poster_url %} - {% blocktrans trimmed with poster_url=poster_url username=last_post.poster|forum_member_display_name %} - By: {{ username }} - {% endblocktrans %} - {% else %} - {% blocktrans trimmed with poster_username=last_post.username %} - By: {{ poster_username }} - {% endblocktrans %} - {% endif %} + {% include "partials/posted_by.html" with poster=last_post.poster username=poster_username %}  
{{ last_post.created }} diff --git a/machina/templates/machina/forum_member/user_posts_list.html b/machina/templates/machina/forum_member/user_posts_list.html index b7631a47b..d660f49ad 100644 --- a/machina/templates/machina/forum_member/user_posts_list.html +++ b/machina/templates/machina/forum_member/user_posts_list.html @@ -46,10 +46,7 @@

{% spaceless %}   - {% url 'forum_member:profile' post.poster_id as poster_url %} - {% blocktrans trimmed with poster_url=poster_url username=post.poster|forum_member_display_name creation_date=post.created %} - By: {{ username }} on {{ creation_date }} - {% endblocktrans %} + {% include "partials/profile_link.html" with poster=post.poster creation_date=post.created %} {% endspaceless %}

@@ -63,7 +60,7 @@

{% include "partials/avatar.html" with profile=post.poster placeholder=False %}

- +
{% include "partials/profile_link.html" with poster=post.poster username_highlighted=True %}
{% trans "Posts:" %} {{ post.poster.forum_profile.posts_count }}

diff --git a/machina/templates/machina/forum_moderation/moderation_queue/detail.html b/machina/templates/machina/forum_moderation/moderation_queue/detail.html index 11131b2aa..d72d70e1e 100644 --- a/machina/templates/machina/forum_moderation/moderation_queue/detail.html +++ b/machina/templates/machina/forum_moderation/moderation_queue/detail.html @@ -81,16 +81,7 @@

{{ post.subject }}

{% spaceless %}   - {% if post.poster %} - {% url 'forum_member:profile' post.poster_id as poster_url %} - {% blocktrans trimmed with poster_url=poster_url username=post.poster|forum_member_display_name creation_date=post.created %} - By: {{ username }} on {{ creation_date }} - {% endblocktrans %} - {% else %} - {% blocktrans trimmed with poster_username=post.username creation_date=post.created %} - By: {{ poster_username }} on {{ creation_date }} - {% endblocktrans %} - {% endif %} + {% include "partials/posted_by.html" with poster=post.poster creation_date=post.created username=poster_username %} {% endspaceless %}

@@ -113,7 +104,7 @@

{{ post.subject }}

{% endif %} -
{{ post.poster|forum_member_display_name }}
+
{% include "partials/profile_link.html" with poster=post.poster username_highlighted=True %}
{% trans "Posts:" %} {{ post.poster.forum_profile.posts_count }}
{% else %}
{{ post.username }}
@@ -140,16 +131,7 @@

{{ post.subject }}

{% spaceless %}   - {% if post.poster %} - {% url 'forum_member:profile' post.poster_id as poster_url %} - {% blocktrans trimmed with poster_url=poster_url username=post.poster|forum_member_display_name creation_date=post.created %} - By: {{ username }} on {{ creation_date }} - {% endblocktrans %} - {% else %} - {% blocktrans trimmed with poster_username=post.username creation_date=post.created %} - By: {{ poster_username }} on {{ creation_date }} - {% endblocktrans %} - {% endif %} + {% include "partials/posted_by.html" with poster=post.poster creation_date=post.created username=poster_username %} {% endspaceless %}

@@ -158,7 +140,7 @@

{{ post.subject }}

{% include "forum_conversation/forum_attachments/attachments_detail.html" %}
-
{% if post.poster %}{{ post.poster|forum_member_display_name }}{% else %}{{ post.username }}{% endif %}
+
{% include "partials/posted_by.html" with poster=post.poster username=post.username username_highlighted=True display_label_by=False %}
{% endfor %} diff --git a/machina/templates/machina/forum_moderation/moderation_queue/list.html b/machina/templates/machina/forum_moderation/moderation_queue/list.html index 687700fb6..79c7f1333 100644 --- a/machina/templates/machina/forum_moderation/moderation_queue/list.html +++ b/machina/templates/machina/forum_moderation/moderation_queue/list.html @@ -46,16 +46,9 @@

{% trans "Moderation queue" %}

{{ post.subject }}
- {% if post.poster %} - {% url 'forum_member:profile' post.poster_id as poster_url %} - {% blocktrans trimmed with poster_url=poster_url username=post.poster|forum_member_display_name creation_date=post.created %} - By: {{ username }} on {{ creation_date }} - {% endblocktrans %} - {% else %} - {% blocktrans trimmed with poster_username=post.username creation_date=post.created %} - By: {{ poster_username }} on {{ creation_date }} - {% endblocktrans %} - {% endif %} + {% block written_by %} + {% include "partials/posted_by.html" with poster=post.poster creation_date=post.created username=poster_username %} + {% endblock %}
diff --git a/machina/templates/machina/partials/posted_by.html b/machina/templates/machina/partials/posted_by.html new file mode 100644 index 000000000..38a3e321b --- /dev/null +++ b/machina/templates/machina/partials/posted_by.html @@ -0,0 +1,16 @@ +{% load i18n %} + +{% if display_label_by == None or display_label_by %} + {% trans "By:" %} +{% endif %} +{% if poster %} + {% include "partials/profile_link.html" %} +{% else %} + {% if username_highlighted %}{% endif %}{{ username }}{% if username_highlighted %}{%endif%} +{% endif %} + +{% if creation_date %} + {% blocktrans trimmed%} + on {{ creation_date }} + {% endblocktrans %} +{% endif %} diff --git a/machina/templates/machina/partials/profile_link.html b/machina/templates/machina/partials/profile_link.html new file mode 100644 index 000000000..6b66642c4 --- /dev/null +++ b/machina/templates/machina/partials/profile_link.html @@ -0,0 +1,10 @@ +{% load forum_member_tags %} + +{% if poster %} + {% url 'forum_member:profile' poster.id as profil_url %} + {% with username=poster|forum_member_display_name %} + + {% if username_highlighted %}{%endif%}{{ username }}{% if username_highlighted %}{%endif%} + + {% endwith %} +{% endif %}