Skip to content

Commit

Permalink
Merge pull request #2406 from GerardPaligot/fix_2392
Browse files Browse the repository at this point in the history
List last topics of a member.
  • Loading branch information
SpaceFox committed Mar 7, 2015
2 parents f8a9216 + 5cbf14c commit b8012fa
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
11 changes: 9 additions & 2 deletions zds/forum/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,16 @@ class TopicManager(models.Manager):
Custom topic manager.
"""

def last_topics_of_a_member(self, author):
def last_topics_of_a_member(self, author, user):
"""
Gets last topics of a member but exclude all topics not accessible
for the request user.
:param author: Author of topics.
:param user: Request user.
:return: List of topics.
"""
return self.filter(author=author) \
.exclude(Q(forum__group__isnull=False) & ~Q(forum__group__in=author.groups.all())) \
.exclude(Q(forum__group__isnull=False) & ~Q(forum__group__in=user.groups.all())) \
.prefetch_related("author") \
.order_by("-pubdate") \
.all()[:settings.ZDS_APP['forum']['home_number']]
2 changes: 1 addition & 1 deletion zds/member/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def get_context_data(self, **kwargs):
usr = context['usr']
profile = usr.profile
context['profile'] = profile
context['topics'] = Topic.objects.last_topics_of_a_member(usr)
context['topics'] = Topic.objects.last_topics_of_a_member(usr, self.request.user)
context['articles'] = Article.objects.last_articles_of_a_member_loaded(usr)
context['tutorials'] = Tutorial.objects.last_tutorials_of_a_member_loaded(usr)
context['old_tutos'] = Profile.objects.all_old_tutos_from_site_du_zero(profile)
Expand Down

0 comments on commit b8012fa

Please sign in to comment.