def top_comments(user): comments = QuestComment.by_author(user).filter(star_count__gt=0, visibility=Visibility.PUBLIC) comments = comments.order_by('-star_count') comments = comments[:8] if len(comments) < 4: return None return comments
def top_comments(user): comments = QuestComment.by_author(user).filter( star_count__gt=0, visibility=Visibility.PUBLIC) comments = comments.order_by('-star_count') comments = comments[:8] if len(comments) < 4: return None return comments
def user_comments(request, username, since_id=None, before_id=None): user = get_object_or_404(User, username=username) comments = QuestComment.by_author(user) paginator = Paginator(comments, knobs.COMMENTS_PER_PAGE, since_id=since_id, before_id=before_id) comments = paginator.items comments = CachedCall.multicall([cmt.details for cmt in comments]) comments = filter_frozen_comments(comments) return {'comments': comments, 'pagination': paginator}
def user_comments(request, username, page='top'): user = get_object_or_404(User, username=username) comments = QuestComment.by_author(user) if request.user.id != user.id: comments = comments.exclude(visibility=Visibility.CURATED) comments = comments[:knobs.COMMENTS_PER_PAGE] comments = CachedCall.queryset_details(comments) return { 'comments': comments, }
def user_comments(request, username, since_id=None, before_id=None): user = get_object_or_404(User, username=username) comments = QuestComment.by_author(user) paginator = Paginator(comments, knobs.COMMENTS_PER_PAGE, since_id=since_id, before_id=before_id) comments = paginator.items comments = CachedCall.multicall([cmt.details for cmt in comments]) comments = filter_frozen_comments(comments) return {'comments': comments, 'pagination': paginator}
def _profile(request, user, template='profiles/profile.html'): comments = QuestComment.by_author(user) top_comments = models.top_comments(user) if top_comments is None: comments = CachedCall.queryset_details(comments) else: comments, top_comments = CachedCall.many_queryset_details(comments, top_comments) follow_counts = following_models.counts(user) return r2r_jinja(template, { 'target_user': user, 'comments': comments, 'top_comments': top_comments, 'follower_count': follow_counts['followers'], 'following_count': follow_counts['following'], }, request)
def _profile(request, user, template='profiles/profile.html'): comments = QuestComment.by_author(user) top_comments = models.top_comments(user) if top_comments is None: comments = CachedCall.queryset_details(comments) else: comments, top_comments = CachedCall.many_queryset_details( comments, top_comments) follow_counts = following_models.counts(user) return r2r_jinja( template, { 'target_user': user, 'comments': comments, 'top_comments': top_comments, 'follower_count': follow_counts['followers'], 'following_count': follow_counts['following'], }, request)
def completed_by_user_count(self, user): """ The number of quests a user has completed. """ return QuestComment.by_author(user).values('parent_comment_id').distinct().count()