Skip to content
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

hide_forum_activity doit aussi s'appliquer à l'entête du profil #6504

Merged
merged 2 commits into from
May 27, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 18 additions & 15 deletions zds/member/views/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,15 @@ def get_object(self, queryset=None):
# sent through emarkdown parser).
return get_object_or_404(User, username=unquote(self.kwargs["user_name"]))

def get_summaries(self, profile):
def get_summaries(self, profile, hide_forum_activity):
"""
Returns a summary of this profile's activity, as a list of list of tuples.
Each first-level list item is an activity category (e.g. contents, forums, etc.)
Each second-level list item is a stat in this activity category.
Each tuple is (link url, count, displayed name of the item), where the link url can be None if it's not a link.

:param profile: The profile.
:param hide_forum_activity: if true, don't populate the values related to forum activity
:return: The summary data.
"""
summaries = []
Expand Down Expand Up @@ -105,17 +106,18 @@ def get_summaries(self, profile):
summaries.append(summary)

summary = []
if count_post > 0:
summary.append(
(
reverse_lazy("forum:post-find", args=(profile.user.pk,)),
count_post,
__("message{}").format(pluralize_fr(count_post)),
if not hide_forum_activity:
if count_post > 0:
summary.append(
(
reverse_lazy("forum:post-find", args=(profile.user.pk,)),
count_post,
__("message{}").format(pluralize_fr(count_post)),
)
)
)
else:
summary.append((None, 0, __("Aucun message")))
if count_topic > 0:
else:
summary.append((None, 0, __("Aucun message")))
if not hide_forum_activity and count_topic > 0:
summary.append(
(
reverse_lazy("forum:topic-find", args=(profile.user.pk,)),
Expand All @@ -135,8 +137,8 @@ def get_summaries(self, profile):
),
)
)

summaries.append(summary)
if summary:
summaries.append(summary)

return summaries

Expand Down Expand Up @@ -178,11 +180,12 @@ def get_context_data(self, **kwargs):
and not self.request.user.has_perm("member.change_profile")
)
context["content_reactions_count"] = ContentReaction.objects.filter(author=usr).count()
context["hide_forum_activity"] = (
hide_forum_activity = (
profile.hide_forum_activity
and not self.request.user.has_perm("member.change_profile")
and not profile.user == self.request.user
)
context["hide_forum_activity"] = hide_forum_activity

if self.request.user.has_perm("member.change_profile"):
sanctions = list(Ban.objects.filter(user=usr).select_related("moderator"))
Expand All @@ -195,7 +198,7 @@ def get_context_data(self, **kwargs):
context["alerts"] = profile.alerts_on_this_profile.all().order_by("-pubdate")
context["has_unsolved_alerts"] = profile.alerts_on_this_profile.filter(solved=False).exists()

context["summaries"] = self.get_summaries(profile)
context["summaries"] = self.get_summaries(profile, hide_forum_activity)
return context


Expand Down