예제 #1
0
 def mk_paginator(self, results, page, **kwargs):
     workspace = self.mk_workspace()
     patch_count = patch.object(SM, 'count', return_value=len(results))
     patch_count.start()
     self.addCleanup(patch_count.stop)
     results = SM(Category, in_=[workspace.working_dir])
     return Paginator(results, page, **kwargs)
예제 #2
0
    def search(self):

        query = self.request.GET.get('q')
        p = int(self.request.GET.get('p', 0))

        empty_defaults = self.context(
            paginator=[],
            query=query,
            p=p,
        )

        # handle query exception
        if not query:
            return empty_defaults

        all_results = self.all_pages.query(content__query_string=query).filter(
            language=self.language)

        # no results found
        if all_results.count() == 0:
            return empty_defaults

        paginator = Paginator(all_results, p)

        # requested page number is out of range
        total_pages = paginator.total_pages()
        # sets the floor to 0
        p = p if p >= 0 else 0
        # sets the roof to `total_pages -1`
        p = p if p < total_pages else total_pages - 1
        paginator = Paginator(all_results, p)

        relevant_categories = self.all_categories.query().filter(
            language=self.language)

        return self.context(
            relevant_categories=relevant_categories,
            paginator=paginator,
            query=query,
            p=p,
        )
예제 #3
0
    def search(self):

        query = self.request.GET.get('q')
        p = int(self.request.GET.get('p', 0))

        empty_defaults = self.context(
            paginator=[],
            query=query,
            p=p,
        )

        # handle query exception
        if not query:
            return empty_defaults

        all_results = self.all_pages.query(
            content__query_string=query).filter(language=self.language)

        # no results found
        if all_results.count() == 0:
            return empty_defaults

        paginator = Paginator(all_results, p)

        # requested page number is out of range
        total_pages = paginator.total_pages()
        # sets the floor to 0
        p = p if p >= 0 else 0
        # sets the roof to `total_pages -1`
        p = p if p < total_pages else total_pages - 1
        paginator = Paginator(all_results, p)

        relevant_categories = self.all_categories.query().filter(
            language=self.language)

        return self.context(
            relevant_categories=relevant_categories,
            paginator=paginator,
            query=query,
            p=p,
        )
예제 #4
0
def paginate_filter(results, page, results_per_page=10, slider_value=5):
    return Paginator(results, page, results_per_page, slider_value)
예제 #5
0
 def mk_paginator(self, results, page, **kwargs):
     return Paginator(results, page, **kwargs)