Skip to content

Commit b06f81a

Browse files
committed
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.
1 parent 68a7a39 commit b06f81a

File tree

9 files changed

+48
-100
lines changed

9 files changed

+48
-100
lines changed

machina/templates/machina/forum/forum_list.html

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -72,16 +72,7 @@ <h3 class="m-0 card-title h5 text-dark">{% trans "Forums" %}</h3>
7272
<div class="py-2 col-md-1 d-none d-md-block text-center forum-count">{{ node.posts_count }}</div>
7373
<div class="py-2 col-md-2 col-sm-3 d-none d-sm-block forum-last-post">
7474
{% if node.last_post %}
75-
{% if node.last_post.poster %}
76-
{% url 'forum_member:profile' node.last_post.poster_id as poster_url %}
77-
{% blocktrans trimmed with poster_url=poster_url username=node.last_post.poster|forum_member_display_name %}
78-
By: <a href="{{ poster_url }}">{{ username }}</a>
79-
{% endblocktrans %}
80-
{% else %}
81-
{% blocktrans trimmed with poster_username=node.last_post.username %}
82-
By: {{ poster_username }}
83-
{% endblocktrans %}
84-
{% endif %}
75+
{% include "partials/posted_by.html" with poster=node.last_post.poster username=poster_username %}
8576
&nbsp;<a href="{% url 'forum_conversation:topic' node.obj.slug node.obj.pk node.last_post.topic.slug node.last_post.topic.pk %}?post={{ node.last_post.pk }}#{{ node.last_post.pk }}"><i class="fas fa-arrow-circle-right "></i></a>
8677
<br />
8778
<small>{{ node.last_post.created }}</small>
@@ -145,16 +136,7 @@ <h3 class="m-0 card-title h5 text-dark">{% trans "Forums" %}</h3>
145136
<div class="py-2 col-md-1 d-none d-md-block text-center forum-count">{{ node.posts_count }}</div>
146137
<div class="py-2 col-md-2 col-sm-3 d-none d-sm-block forum-last-post">
147138
{% if node.last_post %}
148-
{% if node.last_post.poster_id %}
149-
{% url 'forum_member:profile' node.last_post.poster_id as poster_url %}
150-
{% blocktrans trimmed with poster_url=poster_url username=node.last_post.poster|forum_member_display_name %}
151-
By: <a href="{{ poster_url }}">{{ username }}</a>
152-
{% endblocktrans %}
153-
{% else %}
154-
{% blocktrans trimmed with poster_username=node.last_post.username %}
155-
By: {{ poster_username }}
156-
{% endblocktrans %}
157-
{% endif %}
139+
{% include "partials/posted_by.html" with poster=node.last_post.poster username=poster_username %}
158140
&nbsp;<a href="{% url 'forum_conversation:topic' node.obj.slug node.obj.pk node.last_post.topic.slug node.last_post.topic.pk %}?post={{ node.last_post.pk }}#{{ node.last_post.pk }}"><i class="fas fa-arrow-circle-right "></i></a>
159141
<br />
160142
<small>{{ node.last_post.created }}</small>

machina/templates/machina/forum_conversation/post_create.html

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,7 @@ <h4 class="subject">{{ post.subject }}</h4>
4646
<p><small class="text-muted">
4747
{% spaceless %}
4848
<i class="fa fa-clock-o"></i>&nbsp;
49-
{% if post.poster %}
50-
{% url 'forum_member:profile' post.poster_id as poster_url %}
51-
{% blocktrans trimmed with poster_url=poster_url username=post.poster|forum_member_display_name creation_date=post.created %}
52-
By: <a href="{{ poster_url }}">{{ username }}</a> on {{ creation_date }}
53-
{% endblocktrans %}
54-
{% else %}
55-
{% blocktrans trimmed with poster_username=post.username creation_date=post.created %}
56-
By: {{ poster_username }} on {{ creation_date }}
57-
{% endblocktrans %}
58-
{% endif %}
49+
{% include "partials/posted_by.html" with poster=post.poster creation_date=post.created username=poster_username %}
5950
{% endspaceless %}
6051
</small></p>
6152
<div class="post-content">
@@ -64,7 +55,9 @@ <h4 class="subject">{{ post.subject }}</h4>
6455
{% include "forum_conversation/forum_attachments/attachments_detail.html" %}
6556
</div>
6657
<div class="col-md-2 post-sidebar">
67-
<div class="username">{% if post.poster %}<a href="{% url 'forum_member:profile' post.poster_id %}"><b>{{ post.poster|forum_member_display_name }}</b></a>{% else %}<b>{{ post.username }}</b>{% endif %}</div>
58+
<div class="username">
59+
{% include "partials/posted_by.html" with poster=post.poster username=post.username username_highlighted=True display_label_by=False %}
60+
</div>
6861
</div>
6962
</div>
7063
{% endfor %}

machina/templates/machina/forum_conversation/topic_detail.html

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,21 +45,14 @@ <h4 class="m-0 subject">
4545
</h4>
4646
{% endspaceless %}
4747
<p>
48+
{% block written_by %}
4849
<small class="text-muted">
4950
{% spaceless %}
5051
<i class="fas fa-clock"></i>&nbsp;
51-
{% if post.poster %}
52-
{% url 'forum_member:profile' post.poster_id as poster_url %}
53-
{% blocktrans trimmed with poster_url=poster_url username=post.poster|forum_member_display_name creation_date=post.created %}
54-
By: <a href="{{ poster_url }}">{{ username }}</a> on {{ creation_date }}
55-
{% endblocktrans %}
56-
{% else %}
57-
{% blocktrans trimmed with poster_username=post.username creation_date=post.created %}
58-
By: {{ poster_username }} on {{ creation_date }}
59-
{% endblocktrans %}
60-
{% endif %}
52+
{% include "partials/posted_by.html" with poster=post.poster creation_date=post.created username=poster_username %}
6153
{% endspaceless %}
6254
</small>
55+
{% endblock %}
6356
</p>
6457
<div class="post-content">
6558
{{ post.content.rendered }}
@@ -73,7 +66,7 @@ <h4 class="m-0 subject">
7366
{% if post.updates_count %}
7467
<div class="mt-4 edit-info">
7568
<small class="text-muted">
76-
<i class="fas fa-edit"></i>&nbsp;{% if post.updated_by %}{% trans "Last edited by:" %}&nbsp;<a href="{% url 'forum_member:profile' post.updated_by_id %}">{{ post.updated_by|forum_member_display_name }}</a>&nbsp;{% else %}{% trans "Updated" %}&nbsp;{% endif %}{% trans "on" %}&nbsp;{{ post.updated }}, {% blocktrans count counter=post.updates_count %}edited {{counter }} time in total.{% plural %}edited {{counter }} times in total.{% endblocktrans %}
69+
<i class="fas fa-edit"></i>&nbsp;{% if post.updated_by %}{% trans "Last edited by:" %}&nbsp;{% include "partials/profile_link.html" with poster=post.updated_by %}&nbsp;{% else %}{% trans "Updated" %}&nbsp;{% endif %}{% trans "on" %}&nbsp;{{ post.updated }}, {% blocktrans count counter=post.updates_count %}edited {{counter }} time in total.{% plural %}edited {{counter }} times in total.{% endblocktrans %}
7770
</small>
7871
{% if post.update_reason %}
7972
<br />
@@ -91,7 +84,7 @@ <h4 class="m-0 subject">
9184
{% include "partials/avatar.html" with profile=post.poster.forum_profile show_placeholder=True %}
9285
</a>
9386
</div>
94-
<div class="username"><a href="{% url 'forum_member:profile' post.poster_id %}"><b>{{ post.poster|forum_member_display_name }}</b></a></div>
87+
<div class="username">{% include "partials/profile_link.html" with poster=post.poster username_highlighted=True %}</div>
9588
<div class="posts-count text-muted"><b>{% trans "Posts:" %}</b>&nbsp;{{ post.poster.forum_profile.posts_count }}</div>
9689
{% else %}
9790
<div class="username"><b>{{ post.username }}</b></div>

machina/templates/machina/forum_conversation/topic_list.html

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,7 @@
2929
<a href="{% url 'forum_conversation:topic' topic.forum.slug topic.forum.pk topic.slug topic.pk %}" class="topic-name-link">{{ topic.subject }}</a>{% if topic.is_locked %}&nbsp;<i class="fas fa-times-circle locked-indicator" title="{% trans 'This topic is locked' %}"></i>{% endif %}
3030
<div>
3131
<div class="topic-created">
32-
{% if topic.poster %}
33-
{% url 'forum_member:profile' topic.poster_id as poster_url %}
34-
{% blocktrans trimmed with poster_url=poster_url username=topic.poster|forum_member_display_name creation_date=topic.created %}
35-
By: <a href="{{ poster_url }}">{{ username }}</a> on {{ creation_date }}
36-
{% endblocktrans %}
37-
{% else %}
38-
{% blocktrans trimmed with poster_username=topic.first_post.username creation_date=topic.created %}
39-
By: {{ poster_username }} on {{ creation_date }}
40-
{% endblocktrans %}
41-
{% endif %}
32+
{% include "partials/posted_by.html" with poster=topic.poster creation_date=topic.created username=poster_username %}
4233
</div>
4334
</div>
4435
</td>
@@ -49,16 +40,7 @@
4940
<div class="py-2 col-md-1 d-none d-md-block text-center topic-count">{{ topic.views_count }}</div>
5041
<div class="py-2 col-md-2 col-sm-3 d-none d-sm-block topic-last-post">
5142
{% with last_post=topic.last_post %}
52-
{% if last_post.poster %}
53-
{% url 'forum_member:profile' last_post.poster_id as poster_url %}
54-
{% blocktrans trimmed with poster_url=poster_url username=last_post.poster|forum_member_display_name %}
55-
By: <a href="{{ poster_url }}">{{ username }}</a>
56-
{% endblocktrans %}
57-
{% else %}
58-
{% blocktrans trimmed with poster_username=last_post.username %}
59-
By: {{ poster_username }}
60-
{% endblocktrans %}
61-
{% endif %}
43+
{% include "partials/posted_by.html" with poster=last_post.poster username=poster_username %}
6244
&nbsp;<a href="{% url 'forum_conversation:topic' topic.forum.slug topic.forum.pk topic.slug topic.pk %}?post={{ last_post.pk }}#{{ last_post.pk }}"><i class="fas fa-arrow-circle-right "></i></a>
6345
<br />
6446
<small>{{ last_post.created }}</small>

machina/templates/machina/forum_member/user_posts_list.html

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,7 @@ <h4 class="subject">
4646
<small class="text-muted">
4747
{% spaceless %}
4848
<i class="fas fa-clock"></i>&nbsp;
49-
{% url 'forum_member:profile' post.poster_id as poster_url %}
50-
{% blocktrans trimmed with poster_url=poster_url username=post.poster|forum_member_display_name creation_date=post.created %}
51-
By: <a href="{{ poster_url }}">{{ username }}</a> on {{ creation_date }}
52-
{% endblocktrans %}
49+
{% include "partials/profile_link.html" with poster=post.poster creation_date=post.created %}
5350
{% endspaceless %}
5451
</small>
5552
</p>
@@ -63,7 +60,7 @@ <h4 class="subject">
6360
{% include "partials/avatar.html" with profile=post.poster placeholder=False %}
6461
</a>
6562
</div>
66-
<div class="username"><a href="{% url 'forum_member:profile' post.poster_id %}"><b>{{ post.poster|forum_member_display_name }}</b></a></div>
63+
<div class="username">{% include "partials/profile_link.html" with poster=post.poster username_highlighted=True %}</div>
6764
<div class="posts-count text-muted"><b>{% trans "Posts:" %}</b>&nbsp;{{ post.poster.forum_profile.posts_count }}</div>
6865
</div>
6966
</div>

machina/templates/machina/forum_moderation/moderation_queue/detail.html

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -81,16 +81,7 @@ <h4 class="subject">{{ post.subject }}</h4>
8181
<small class="text-muted">
8282
{% spaceless %}
8383
<i class="fas fa-clock"></i>&nbsp;
84-
{% if post.poster %}
85-
{% url 'forum_member:profile' post.poster_id as poster_url %}
86-
{% blocktrans trimmed with poster_url=poster_url username=post.poster|forum_member_display_name creation_date=post.created %}
87-
By: <a href="{{ poster_url }}">{{ username }}</a> on {{ creation_date }}
88-
{% endblocktrans %}
89-
{% else %}
90-
{% blocktrans trimmed with poster_username=post.username creation_date=post.created %}
91-
By: {{ poster_username }} on {{ creation_date }}
92-
{% endblocktrans %}
93-
{% endif %}
84+
{% include "partials/posted_by.html" with poster=post.poster creation_date=post.created username=poster_username %}
9485
{% endspaceless %}
9586
</small>
9687
</p>
@@ -113,7 +104,7 @@ <h4 class="subject">{{ post.subject }}</h4>
113104
</a>
114105
</div>
115106
{% endif %}
116-
<div class="username"><a href="{% url 'forum_member:profile' post.poster_id %}"><b>{{ post.poster|forum_member_display_name }}</b></a></div>
107+
<div class="username">{% include "partials/profile_link.html" with poster=post.poster username_highlighted=True %}</div>
117108
<div class="posts-count text-muted"><b>{% trans "Posts:" %}</b>&nbsp;{{ post.poster.forum_profile.posts_count }}</div>
118109
{% else %}
119110
<div class="username"><b>{{ post.username }}</b></div>
@@ -140,16 +131,7 @@ <h4 class="subject">{{ post.subject }}</h4>
140131
<p><small class="text-muted">
141132
{% spaceless %}
142133
<i class="fas fa-clock"></i>&nbsp;
143-
{% if post.poster %}
144-
{% url 'forum_member:profile' post.poster_id as poster_url %}
145-
{% blocktrans trimmed with poster_url=poster_url username=post.poster|forum_member_display_name creation_date=post.created %}
146-
By: <a href="{{ poster_url }}">{{ username }}</a> on {{ creation_date }}
147-
{% endblocktrans %}
148-
{% else %}
149-
{% blocktrans trimmed with poster_username=post.username creation_date=post.created %}
150-
By: {{ poster_username }} on {{ creation_date }}
151-
{% endblocktrans %}
152-
{% endif %}
134+
{% include "partials/posted_by.html" with poster=post.poster creation_date=post.created username=poster_username %}
153135
{% endspaceless %}
154136
</small></p>
155137
<div class="post-content">
@@ -158,7 +140,7 @@ <h4 class="subject">{{ post.subject }}</h4>
158140
{% include "forum_conversation/forum_attachments/attachments_detail.html" %}
159141
</div>
160142
<div class="col-md-2 post-sidebar">
161-
<div class="username">{% if post.poster %}<a href="{% url 'forum_member:profile' post.poster_id %}"><b>{{ post.poster|forum_member_display_name }}</b></a>{% else %}<b>{{ post.username }}</b>{% endif %}</div>
143+
<div class="username">{% include "partials/posted_by.html" with poster=post.poster username=post.username username_highlighted=True display_label_by=False %}</div>
162144
</div>
163145
</div>
164146
{% endfor %}

machina/templates/machina/forum_moderation/moderation_queue/list.html

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,9 @@ <h3 class="m-0 card-title h5">{% trans "Moderation queue" %}</h3>
4646
<a href="{% url 'forum_moderation:queued_post' post.pk %}" class="post-name-link">{{ post.subject }}</a>
4747
<div>
4848
<div class="post-created">
49-
{% if post.poster %}
50-
{% url 'forum_member:profile' post.poster_id as poster_url %}
51-
{% blocktrans trimmed with poster_url=poster_url username=post.poster|forum_member_display_name creation_date=post.created %}
52-
By: <a href="{{ poster_url }}">{{ username }}</a> on {{ creation_date }}
53-
{% endblocktrans %}
54-
{% else %}
55-
{% blocktrans trimmed with poster_username=post.username creation_date=post.created %}
56-
By: {{ poster_username }} on {{ creation_date }}
57-
{% endblocktrans %}
58-
{% endif %}
49+
{% block written_by %}
50+
{% include "partials/posted_by.html" with poster=post.poster creation_date=post.created username=poster_username %}
51+
{% endblock %}
5952
</div>
6053
</div>
6154
</td>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{% load i18n %}
2+
3+
{% if display_label_by is not defined or display_label_by %}
4+
{% trans "By:" %}
5+
{% endif %}
6+
{% if poster %}
7+
{% include "partials/profile_link.html" %}
8+
{% else %}
9+
{% if username_highlighted %}<b>{% endif %}{{ username }}{% if username_highlighted %}</b>{%endif%}
10+
{% endif %}
11+
12+
{% if creation_date %}
13+
{% blocktrans trimmed%}
14+
on {{ creation_date }}
15+
{% endblocktrans %}
16+
{% endif %}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{% load forum_member_tags %}
2+
3+
{% if poster %}
4+
{% url 'forum_member:profile' poster.id as profil_url %}
5+
{% with username=poster|forum_member_display_name %}
6+
<a href="{{profil_url }}" title="title">
7+
{% if username_highlighted %}<b>{%endif%}{{ username }}{% if username_highlighted %}</b>{%endif%}
8+
</a>
9+
{% endwith %}
10+
{% endif %}

0 commit comments

Comments
 (0)