Skip to content

Commit

Permalink
Add view partials for repeated content on post or topic writer
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
carofun committed Feb 9, 2021
1 parent 68a7a39 commit 60e0cb1
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 100 deletions.
22 changes: 2 additions & 20 deletions machina/templates/machina/forum/forum_list.html
Expand Up @@ -72,16 +72,7 @@ <h3 class="m-0 card-title h5 text-dark">{% trans "Forums" %}</h3>
<div class="py-2 col-md-1 d-none d-md-block text-center forum-count">{{ node.posts_count }}</div>
<div class="py-2 col-md-2 col-sm-3 d-none d-sm-block forum-last-post">
{% 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: <a href="{{ poster_url }}">{{ username }}</a>
{% 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 %}
&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>
<br />
<small>{{ node.last_post.created }}</small>
Expand Down Expand Up @@ -145,16 +136,7 @@ <h3 class="m-0 card-title h5 text-dark">{% trans "Forums" %}</h3>
<div class="py-2 col-md-1 d-none d-md-block text-center forum-count">{{ node.posts_count }}</div>
<div class="py-2 col-md-2 col-sm-3 d-none d-sm-block forum-last-post">
{% 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: <a href="{{ poster_url }}">{{ username }}</a>
{% 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 %}
&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>
<br />
<small>{{ node.last_post.created }}</small>
Expand Down
15 changes: 4 additions & 11 deletions machina/templates/machina/forum_conversation/post_create.html
Expand Up @@ -46,16 +46,7 @@ <h4 class="subject">{{ post.subject }}</h4>
<p><small class="text-muted">
{% spaceless %}
<i class="fa fa-clock-o"></i>&nbsp;
{% 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: <a href="{{ poster_url }}">{{ username }}</a> 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 %}
</small></p>
<div class="post-content">
Expand All @@ -64,7 +55,9 @@ <h4 class="subject">{{ post.subject }}</h4>
{% include "forum_conversation/forum_attachments/attachments_detail.html" %}
</div>
<div class="col-md-2 post-sidebar">
<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>
<div class="username">
{% include "partials/posted_by.html" with poster=post.poster username=post.username username_highlighted=True display_label_by=False %}
</div>
</div>
</div>
{% endfor %}
Expand Down
17 changes: 5 additions & 12 deletions machina/templates/machina/forum_conversation/topic_detail.html
Expand Up @@ -45,21 +45,14 @@ <h4 class="m-0 subject">
</h4>
{% endspaceless %}
<p>
{% block written_by %}
<small class="text-muted">
{% spaceless %}
<i class="fas fa-clock"></i>&nbsp;
{% 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: <a href="{{ poster_url }}">{{ username }}</a> 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 %}
</small>
{% endblock %}
</p>
<div class="post-content">
{{ post.content.rendered }}
Expand All @@ -73,7 +66,7 @@ <h4 class="m-0 subject">
{% if post.updates_count %}
<div class="mt-4 edit-info">
<small class="text-muted">
<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 %}
<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 %}
</small>
{% if post.update_reason %}
<br />
Expand All @@ -91,7 +84,7 @@ <h4 class="m-0 subject">
{% include "partials/avatar.html" with profile=post.poster.forum_profile show_placeholder=True %}
</a>
</div>
<div class="username"><a href="{% url 'forum_member:profile' post.poster_id %}"><b>{{ post.poster|forum_member_display_name }}</b></a></div>
<div class="username">{% include "partials/profile_link.html" with poster=post.poster username_highlighted=True %}</div>
<div class="posts-count text-muted"><b>{% trans "Posts:" %}</b>&nbsp;{{ post.poster.forum_profile.posts_count }}</div>
{% else %}
<div class="username"><b>{{ post.username }}</b></div>
Expand Down
22 changes: 2 additions & 20 deletions machina/templates/machina/forum_conversation/topic_list.html
Expand Up @@ -29,16 +29,7 @@
<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 %}
<div>
<div class="topic-created">
{% 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: <a href="{{ poster_url }}">{{ username }}</a> 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 %}
</div>
</div>
</td>
Expand All @@ -49,16 +40,7 @@
<div class="py-2 col-md-1 d-none d-md-block text-center topic-count">{{ topic.views_count }}</div>
<div class="py-2 col-md-2 col-sm-3 d-none d-sm-block topic-last-post">
{% 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: <a href="{{ poster_url }}">{{ username }}</a>
{% 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 %}
&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>
<br />
<small>{{ last_post.created }}</small>
Expand Down
7 changes: 2 additions & 5 deletions machina/templates/machina/forum_member/user_posts_list.html
Expand Up @@ -46,10 +46,7 @@ <h4 class="subject">
<small class="text-muted">
{% spaceless %}
<i class="fas fa-clock"></i>&nbsp;
{% 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: <a href="{{ poster_url }}">{{ username }}</a> on {{ creation_date }}
{% endblocktrans %}
{% include "partials/profile_link.html" with poster=post.poster creation_date=post.created %}
{% endspaceless %}
</small>
</p>
Expand All @@ -63,7 +60,7 @@ <h4 class="subject">
{% include "partials/avatar.html" with profile=post.poster placeholder=False %}
</a>
</div>
<div class="username"><a href="{% url 'forum_member:profile' post.poster_id %}"><b>{{ post.poster|forum_member_display_name }}</b></a></div>
<div class="username">{% include "partials/profile_link.html" with poster=post.poster username_highlighted=True %}</div>
<div class="posts-count text-muted"><b>{% trans "Posts:" %}</b>&nbsp;{{ post.poster.forum_profile.posts_count }}</div>
</div>
</div>
Expand Down
Expand Up @@ -81,16 +81,7 @@ <h4 class="subject">{{ post.subject }}</h4>
<small class="text-muted">
{% spaceless %}
<i class="fas fa-clock"></i>&nbsp;
{% 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: <a href="{{ poster_url }}">{{ username }}</a> 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 %}
</small>
</p>
Expand All @@ -113,7 +104,7 @@ <h4 class="subject">{{ post.subject }}</h4>
</a>
</div>
{% endif %}
<div class="username"><a href="{% url 'forum_member:profile' post.poster_id %}"><b>{{ post.poster|forum_member_display_name }}</b></a></div>
<div class="username">{% include "partials/profile_link.html" with poster=post.poster username_highlighted=True %}</div>
<div class="posts-count text-muted"><b>{% trans "Posts:" %}</b>&nbsp;{{ post.poster.forum_profile.posts_count }}</div>
{% else %}
<div class="username"><b>{{ post.username }}</b></div>
Expand All @@ -140,16 +131,7 @@ <h4 class="subject">{{ post.subject }}</h4>
<p><small class="text-muted">
{% spaceless %}
<i class="fas fa-clock"></i>&nbsp;
{% 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: <a href="{{ poster_url }}">{{ username }}</a> 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 %}
</small></p>
<div class="post-content">
Expand All @@ -158,7 +140,7 @@ <h4 class="subject">{{ post.subject }}</h4>
{% include "forum_conversation/forum_attachments/attachments_detail.html" %}
</div>
<div class="col-md-2 post-sidebar">
<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>
<div class="username">{% include "partials/posted_by.html" with poster=post.poster username=post.username username_highlighted=True display_label_by=False %}</div>
</div>
</div>
{% endfor %}
Expand Down
Expand Up @@ -46,16 +46,9 @@ <h3 class="m-0 card-title h5">{% trans "Moderation queue" %}</h3>
<a href="{% url 'forum_moderation:queued_post' post.pk %}" class="post-name-link">{{ post.subject }}</a>
<div>
<div class="post-created">
{% 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: <a href="{{ poster_url }}">{{ username }}</a> 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 %}
</div>
</div>
</td>
Expand Down
16 changes: 16 additions & 0 deletions 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 %}<b>{% endif %}{{ username }}{% if username_highlighted %}</b>{%endif%}
{% endif %}

{% if creation_date %}
{% blocktrans trimmed%}
on {{ creation_date }}
{% endblocktrans %}
{% endif %}
10 changes: 10 additions & 0 deletions 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 %}
<a href="{{profil_url }}" title="title">
{% if username_highlighted %}<b>{%endif%}{{ username }}{% if username_highlighted %}</b>{%endif%}
</a>
{% endwith %}
{% endif %}

0 comments on commit 60e0cb1

Please sign in to comment.