示例#1
0
    def get_context_data(self, **kwargs):
        context = super(PersonList, self).get_context_data(**kwargs)

        context['recent_jobs'] = get_recent_jobs(2)
        context['recent_repos'] = get_recent_repos(3)

        return context
示例#2
0
    def get_context_data(self, **kwargs):
        context = super(OrganizationDetail, self).get_context_data(**kwargs)

        context['recent_jobs'] = get_recent_jobs(2)
        context['recent_repos'] = get_recent_repos(3)

        return context
示例#3
0
    def get_context_data(self, **kwargs):
        context = super(ArticleList, self).get_context_data(**kwargs)
        self.get_standard_context(context)

        context['recent_jobs'] = get_recent_jobs(2)
        context['recent_repos'] = get_recent_repos(3)

        return context
示例#4
0
    def get_context_data(self, **kwargs):
        context = super(HomepageView, self).get_context_data(**kwargs)

        context['promo_article'] = self.get_promo_article()
        context['recent_jobs'] = get_recent_jobs(3)
        context['random_guides'] = get_random_guides(3)

        return context
示例#5
0
    def get_context_data(self, **kwargs):
        context = super(CommunityList, self).get_context_data(**kwargs)

        # this page randomly selects a few Person and Organization
        # records to display based on recent Article and Code posts
        recent_articles = Article.live_objects.order_by('-pubdate')[:20]
        recent_codes = Code.live_objects.order_by('-created')[:20]

        # we only need the Person record pks here, setting NO_CACHE because
        # django-cache-machine does not work with .values() or .values_list()
        article_author_ids = recent_articles.values_list('authors', flat=True)
        article_author_ids.timeout = NO_CACHE
        #code_people_ids = recent_codes.values_list('people', flat=True)
        #code_people_ids.timeout = NO_CACHE

        # get 3 random unique Person records
        people_ids = list(article_author_ids)  # + list(code_people_ids)
        people_ids = list(set([x for x in people_ids if x is not None]))
        people_ids = random.sample(people_ids, 3)
        people = Person.objects.filter(id__in=people_ids)
        context['people'] = people

        # only need the Organization pks
        article_organization_ids = recent_articles.values_list('organizations',
                                                               flat=True)
        article_organization_ids.timeout = NO_CACHE
        article_code_ids = recent_codes.values_list('organizations', flat=True)
        article_code_ids.timeout = NO_CACHE

        # get 3 random unique Organization records
        organization_ids = list(article_organization_ids) + list(
            article_code_ids)
        organization_ids = list(
            set([x for x in organization_ids if x is not None]))
        organization_ids = random.sample(organization_ids, 3)
        organizations = Organization.objects.filter(id__in=organization_ids)
        context['organizations'] = organizations

        context['recent_jobs'] = get_recent_jobs(2)
        context['recent_repos'] = get_recent_repos(3)

        return context