danirus / django-comments-xtd

A pluggable Django comments application with thread support, follow-up notifications, mail confirmation, like/dislike flags, moderation, a ReactJS plugin and Bootstrap 5.3.
https://django-comments-xtd.readthedocs.io
BSD 2-Clause "Simplified" License
594 stars 158 forks source link

item.comment.name ignores the COMMENTS_XTD_API_USER_REPR setting #187

Closed jimkring closed 4 years ago

jimkring commented 4 years ago

I'm using the setting to sets the function to use when getting the user's display name.

COMMENTS_XTD_API_USER_REPR = lambda u: u.get_full_name()

I noticed an oddity:

{{ item.comment.name }} will render a user's email address (since I'm using AbstractEmailUser class) regardless of what I set the value of COMMENTS_XTD_API_USER_REPR. However, {{ item.comment.name }} will correctly render as my user's full name if (and only if) I define a get_full_name() function in my user class, and it seems to do this, regardless of what I have set COMMENTS_XTD_API_USER_REPR as.

My guess is that the rendering of {{ item.comment.name }} is using some hard-coded function like get_full_name() instead of using the one defined by the COMMENTS_XTD_API_USER_REPR setting.

Steps to reproduce:

1) Set COMMENTS_XTD_API_USER_REPR = lambda u: u.get_full_name2() (and implement the get_full_name2() method in the user class.

2) Note that {{ item.comment.name }} renders as the user's email address.

3) Now, implement an additional get_full_name() in the user class (without changing the COMMENTS_XTD_API_USER_REPR setting -- leave that pointing at get_full_name2()) and notice that {{ item.comment.name }} renders as the user's full name.

4) As an added bonus, remove the COMMENTS_XTD_API_USER_REPR setting and note that {{ item.comment.name }} still renders as the user's full name, since we have a get_full_name() method in the user class.

This is what leads me to believe that the rendering of {{ item.comment.name }} is ignoring the COMMENTS_XTD_API_USER_REPR setting.

danirus commented 4 years ago

The COMMENTS_XTD_API_USER_REPR setting is used only related with comment's like/dislike flags.

But I think your guess about get_full_name is in the right track. When you do {{ item.comment.name }} you are accessing the getter _get_name from django-comments, see the code between lines 91 and 130. It's not related with django-comments-xtd. But I think that code will give you the clue.

jimkring commented 4 years ago

OK, thanks for that info @danirus

jimkring commented 4 years ago

@danirus I see what you're saying about that, now that I've looked at some of the code. I guess maybe I need to read through the docs/code for django-comments more to better understand how this part works. Thanks again!