Beispiel #1
0
def document_objects_for_keyword_in_range(first_index, keyword):
    #unescapes and splits the query into keywords
    keywords = list(set((urllib.unquote_plus(keyword)).split(" ")))
    query_set = EmptyQuerySet()
    # Retrieves the set of documents corresponding to each keyword
    for key in keywords:
        word = get_or_none(Word, text=key)
        if word is not None:
            query_set = query_set | word.document_set.all()
        # Orders the set, removes duplicates, and returns a list of the resultant documents
    document_objects = list(query_set.order_by("-pagerank").distinct()[
                            first_index * RESULTS_PER_PAGE: (first_index + 1) * RESULTS_PER_PAGE])
    return document_objects
Beispiel #2
0
def document_objects_for_keyword_in_range(first_index, keyword):
    #unescapes and splits the query into keywords
    keywords = list(set((urllib.unquote_plus(keyword)).split(" ")))
    query_set = EmptyQuerySet()
    # Retrieves the set of documents corresponding to each keyword
    for key in keywords:
        word = get_or_none(Word, text=key)
        if word is not None:
            query_set = query_set | word.document_set.all()
        # Orders the set, removes duplicates, and returns a list of the resultant documents
    document_objects = list(
        query_set.order_by("-pagerank").distinct()
        [first_index * RESULTS_PER_PAGE:(first_index + 1) * RESULTS_PER_PAGE])
    return document_objects
Beispiel #3
0
    def render(self, context):
        try:
            object = template.resolve_variable(self.object, context)
        except template.VariableDoesNotExist:
            return ''

        # extract all news
        # if obect is a Person, extract news related to all current and past charges
        if isinstance(object, Person):
            news = EmptyQuerySet()
            for c in object.all_institution_charges:
                news |= c.related_news
        elif isinstance(object, basestring):
            if object == 'politicians_all':
                news = EmptyQuerySet()
                for c in InstitutionCharge.objects.all():
                    news |= c.related_news
            if object == 'politicians_council':
                news = EmptyQuerySet()
                for c in municipality.council.charges:
                    news |= c.related_news
            if object == 'politicians_gov':
                news = EmptyQuerySet()
                for c in municipality.gov.charges:
                    news |= c.related_news
        else:
            news = object.related_news

        # filter only news of a given type (INST or COMM) (if given)
        if self.news_type:
            news = news.filter(news_type=self.news_type)

        # sort news by news_date, descending order


#        context[self.context_var] = sorted(news, key=lambda n: n.news_date or datetime.date(datetime.MINYEAR,1,1), reverse=True)[0:15]
        context[self.context_var] = news.order_by("-created")[0:15]

        return ''