Skip to content

Commit

Permalink
hide_forum_activity doit aussi s'appliquer à l'entête du profil
Browse files Browse the repository at this point in the history
  • Loading branch information
Migwel committed May 26, 2023
1 parent 445eb9d commit f6fa77a
Showing 1 changed file with 18 additions and 15 deletions.
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 @@ -173,11 +175,12 @@ def get_context_data(self, **kwargs):
.count()
)
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 @@ -190,7 +193,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

0 comments on commit f6fa77a

Please sign in to comment.