Returns a queryset of the published discussions.
170215
def discussions(self):
        
        return comments.get_model().objects.for_model(
            self).filter(is_public=True, is_removed=False)
895238
def get_unread_topics(self, topics, user):
        
        unread_topics = []

        # A user which is not authenticated will never see a topic as unread.
        # If there are no topics to consider, we stop here.
        if not user.is_authenticated or topics is None or not len(topics):
            return unread_topics

        # A topic can be unread if a track for itself exists with a mark time that
        # is less important than its update date.
        topic_ids = [topic.id for topic in topics]
        topic_tracks = TopicReadTrack.objects.filter(topic__in=topic_ids, user=user)
        tracked_topics = dict(topic_tracks.values_list('topic__pk', 'mark_time'))

        if tracked_topics:
            for topic in topics:
                topic_last_modification_date = topic.last_post_on or topic.created
                if (
                    topic.id in tracked_topics.keys() and
                    topic_last_modification_date > tracked_topics[topic.id]
                ):
                    unread_topics.append(topic)

        # A topic can be unread if a track for its associated forum exists with
        # a mark time that is less important than its creation or update date.
        forum_ids = [topic.forum_id for topic in topics]
        forum_tracks = ForumReadTrack.objects.filter(forum_id__in=forum_ids, user=user)
        tracked_forums = dict(forum_tracks.values_list('forum__pk', 'mark_time'))

        if tracked_forums:
            for topic in topics:
                topic_last_modification_date = topic.last_post_on or topic.created
                if (
                    (topic.forum_id in tracked_forums.keys() and topic.id not in tracked_topics) and
                    topic_last_modification_date > tracked_forums[topic.forum_id]
                ):
                    unread_topics.append(topic)

        # A topic can be unread if no tracks exists for it
        for topic in topics:
            if topic.forum_id not in tracked_forums and topic.id not in tracked_topics:
                unread_topics.append(topic)

        return list(set(unread_topics))
19874
def filter_published(self, queryset):
        """"""
        if settings.PAGE_USE_SITE_ID:
            queryset = queryset.filter(sites=global_settings.SITE_ID)

        queryset = queryset.filter(status=self.model.PUBLISHED)

        if settings.PAGE_SHOW_START_DATE:
            queryset = queryset.filter(publication_date__lte=get_now())

        if settings.PAGE_SHOW_END_DATE:
            queryset = queryset.filter(
                Q(publication_end_date__gt=get_now()) |
                Q(publication_end_date__isnull=True)
            )

        return queryset
1038119
def get_context_data(self, **kwargs):
        
        context = super(IndexView, self).get_context_data(**kwargs)
        visiblity_content_tree = context['forums']

        # Computes some global values.
        context['total_posts_count'] = sum(n.posts_count for n in visiblity_content_tree.top_nodes)
        context['total_topics_count'] = sum(
            n.topics_count for n in visiblity_content_tree.top_nodes
        )

        return context
1318468
def list(self, request, *args, **kwargs):
        """"""
        search_kwargs = {"published": False}

        query_params = get_query_params(self.request)

        for field_name in ("status"):
            if field_name in query_params:
                search_kwargs[field_name] = query_params.get(field_name)

        if "search" in query_params:
            search_kwargs["query"] = query_params.get("search")

        # active/closed are semantics of the Poll model
        # active is analagous to 'published' in Content
        # closed is in relation to the end_date of a Poll
        if "active" in query_params:
            del search_kwargs["published"]
            search_kwargs["active"] = True

        if "closed" in query_params:
            del search_kwargs["published"]
            search_kwargs["closed"] = True

        queryset = self.model.search_objects.search(**search_kwargs)

        page = self.paginate_queryset(queryset)
        if page is not None:
            serializer = self.get_serializer(page, many=True)
            return self.get_paginated_response(serializer.data)

        serializer = self.get_serializer(queryset, many=True)
        return Response(serializer.data)
792905
def topics(self):
        
        return set(node.tag for node in self.root.iter() if node.attrib)
331250
def index_queryset(self, using=None):
        """"""

        kwargs = {"active": True}

        # if permissions are enabled then we want only public pages
        # https://github.com/leonardo-modules/leonardo-module-pagepermissions
        if hasattr(Page(), 'permissions'):
            kwargs['permissions__isnull'] = True

        # https://github.com/leonardo-modules/leonardo-page-search
        if hasattr(Page(), 'search_exclude'):
            kwargs['search_exclude'] = False

        return self.get_model().objects.filter(**kwargs)
433030
def get_issue_comments(self):
        
        return github.PaginatedList.PaginatedList(
            github.IssueComment.IssueComment,
            self._requester,
            self.issue_url + "/comments",
            None
        )
1234417
def get_queryset(self):
        '''
        
        '''
        request = self.request
        return (Languages.for_site(request.site)
                         .languages.filter().order_by('pk'))
584872
def get_published_list(
        self, search='', start=0, limit=0, order_by='', order_by_dir='ASC'
    ):
        
        return self.get_list(
            search=search,
            start=start,
            limit=limit,
            order_by=order_by,
            order_by_dir=order_by_dir,
            published_only=True
        )
464296
def get_queryset(self, request):
        ''' '''
        qs = super(SubmissionFileAdmin, self).get_queryset(request)
        if request.user.is_superuser:
            return qs
        else:
            return qs.filter(Q(submissions__assignment__course__tutors__pk=request.user.pk) | Q(submissions__assignment__course__owner=request.user)).distinct()
203334
def get_queryset(self):
        
        self.category = get_category_or_404(self.kwargs['path'])
        return self.category.entries_published()
1046217
def list_topic(self, k, Nwords=10):
        

        return [(self.vocabulary[w], p) for w, p
                in self.phi.features[k].top(Nwords)]
468355
def get_queryset(self, request):
        
        # TODO Can we remove this hack?
        self.request = request

        # Obtain the full queryset defined on the registered model.
        qs = self.model.objects

        # Determine if a specific language should be used and filter by it if
        # required.
        try:
            qs_language = self.get_queryset_language(request)
            if qs_language:
                qs = qs.language(qs_language)
        except AttributeError:  # this isn't translatable
            pass

        # Use all draft object versions in the admin.
        qs = self.publishing_admin_filter_for_drafts(qs)

        # If ordering has been specified in the admin definition order by it.
        ordering = getattr(self, 'ordering', None) or ()
        if ordering:
            qs = qs.order_by(*ordering)

        # Return the filtered queryset.
        return qs
1249613
def get_queryset(self):
        
        # retrieve all devices which are published and accessible to current user
        # and use joins to retrieve related fields
        queryset = super(DeviceList, self).get_queryset()#.select_related('layer', 'status', 'user')

        # retrieve value of querystring parameter "search"
        search = self.request.query_params.get('search', None)

        if search is not None:
            search_query = (
                Q(name__icontains=search) |
                Q(description__icontains=search)
            )
            # add instructions for search to queryset
            queryset = queryset.filter(search_query)

        return queryset
245103
def get_comments(self):
        
        return github.PaginatedList.PaginatedList(
            github.GistComment.GistComment,
            self._requester,
            self.url + "/comments",
            None
        )
550519
def get_context_data(self, **kwargs):
        
        context = super().get_context_data(**kwargs)

        # Computes the number of topics added by the considered member
        context['topics_count'] = (
            Topic.objects.filter(approved=True, poster=self.object.user).count()
        )

        # Fetches the recent posts added by the considered user
        forums = self.request.forum_permission_handler.get_readable_forums(
            Forum.objects.all(), self.request.user,
        )
        recent_posts = (
            Post.approved_objects
            .select_related('topic', 'topic__forum')
            .filter(topic__forum__in=forums, poster=self.object.user)
            .order_by('-created')
        )
        context['recent_posts'] = recent_posts[:machina_settings.PROFILE_RECENT_POSTS_NUMBER]

        return context