-
Notifications
You must be signed in to change notification settings - Fork 128
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add view partials for repeated content on post or topic writer #221
base: main
Are you sure you want to change the base?
Conversation
b06f81a
to
60e0cb1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for submitting this, I think it's fair to have a partial for this use case! Though this PR might need more a bit work in order to be merged (see my comments below).
By: {{ poster_username }} | ||
{% endblocktrans %} | ||
{% endif %} | ||
{% include "partials/posted_by.html" with poster=node.last_post.poster username=poster_username %} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
{{ poster_username }}
doesn't exist in the context. Shouldn't it be {{ node.last_post.username }}
instead? Otherwise a blank string will be displayed for anonymous users. This question also applies to all the where the posted_by.html
partial was inserted. 😉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for you feedback, and sorry about that, it is now fixed !
{% 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 %} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This block is not i18n-friendly: the "By:" string is inserted as a prefix whereas in the previous version of the code this was fully handled as a proper translation with variable substitutions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for you feedback, I rewrote the partial and didn't cut any translation.
{% if creation_date %} | ||
{% blocktrans trimmed%} | ||
on {{ creation_date }} | ||
{% endblocktrans %} | ||
{% endif %} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment!
afcae03
to
006824a
Compare
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 a partials to simplify the overload.
006824a
to
d35c029
Compare
By: {{ poster_username }} on {{ creation_date }} | ||
{% endblocktrans %} | ||
{% endif %} | ||
{% include "partials/posted_by.html" with poster=topic.poster creation_date=topic.created username=topic.first_post.username %} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will result in a new SQL query for each topic because the topic.first_post
is done systematically now.
@@ -0,0 +1,33 @@ | |||
{% load forum_member_tags %} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we could probably improve how this partial works so that it - kindof - keep working like things were working previously.
For example why not:
- have a partial that either works from a single
post
variable ortopic
variable (depending on whether you want to display the poster info for the post or the topic itself) - this would allow to avoid passingposter
,username
andcreation_date
systematically in each partial use (which would be less error prone in my opinion) - then in order to control whether the creation date has to be displayed, you could use an extra
show_creation_date
variable (True / False) no_trans
would be replaced by something more explicit likeshow_by_prefix
username_highlighted
would be replaced byhighlight_username
(True / False) to improve consistency
What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, definitely, I think it's way simpler this way. I'll work around it and suggest it as a fix.
thank you for you feedback
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've commited with a fixup, I had forgotten to add a file with the search in the previous commit which was another case.
I don't know what to think of this new version. I had to make more cases to be able to read username as it is not specified anymore.
Tell me please what you think of it.
{% if is_search %} | ||
{% if item.poster %} | ||
{% url 'forum_member:profile' item.poster as poster_url %} | ||
{% blocktrans trimmed with username=item.poster_name creation_date=item.created %} | ||
By: <a href="{{ poster_url }}">{{ username }}</a> on {{ creation_date }} | ||
{% endblocktrans %} | ||
{% else %} | ||
{% blocktrans trimmed with poster_username=item.poster_name creation_date=item.created %} | ||
By: {{ poster_username }} on {{ creation_date }} | ||
{% endblocktrans %} | ||
{% endif %} | ||
{% else %} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The fact that we need to pass is_search=True
in order to render this partial templates makes me think that it's probably equivalent to simply let the initial search template untouched. Otherwise would it be possible to make this partial template generic enough so that we don't have to use this is_search
variable? If the partial is generic enough, it shouldn't make any assumption regarding the context in which it is used. 🤷♂️
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi I had a second look at it, IMO, we should pass through as we did before (before the fixup), the username, the creation date and poster now that we have 3 cases : topics, posts and search, this way the partial will be generic.
Before I go for it, I prefer to have your feedback.
Thank you
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can try! Though I think the resulting partial should be as simple as possible and not contain too much logic.
Purpose
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 would like to make it easier.
Proposal
We introduce a partial that deals with the different usages.
It can be call with different options to take in charge the different cases of the project :
To ease the overload, we've added a block when we could. Two files only call once the new partial so we introduce a block written_by around it.
This way if we just want to change this in the template, we won't have to overload the whole file, just this block.
It's probably a case that will happen. For instance, in our personal use case, we will need to send an extra parameter to the partial.