Esempio n. 1
0
    def _load(self):
        if self._iterator is not None:
            return

        from piecrust.data.filters import PaginationFilter
        from piecrust.dataproviders.pageiterator import (
            PageIterator, HardCodedFilterIterator)

        self._iterator = PageIterator(
            self._source,
            current_page=self._page)

        if self._pgn_filter is not None:
            pag_fil = PaginationFilter()
            pag_fil.addClause(self._pgn_filter.root_clause)
            self._iterator._simpleNonSortedWrap(
                HardCodedFilterIterator, pag_fil)

        offset = (self._sub_num - 1) * self.items_per_page
        limit = self.items_per_page
        self._iterator.slice(offset, limit)

        if self._is_content_source:
            self._iterator._iter_event += self._onIteration

        self._iterator._lockIterator()
Esempio n. 2
0
    def prepareRenderContext(self, ctx):
        ctx.pagination_source = self.inner_source

        route_params = ctx.page.source_metadata['route_params']
        year = route_params.get('year')
        if year is None:
            raise Exception(
                "Can't find the archive year in the route metadata")
        if type(year) is not int:
            raise Exception(
                "The route for generator '%s' should specify an integer "
                "parameter for 'year'." % self.name)

        flt = PaginationFilter()
        flt.addClause(IsFromYearFilterClause(year))
        ctx.pagination_filter = flt

        ctx.custom_data['year'] = year

        flt2 = PaginationFilter()
        flt2.addClause(IsFromYearFilterClause(year))
        it = PageIterator(self.inner_source)
        it._simpleNonSortedWrap(HardCodedFilterIterator, flt2)
        it._wrapAsSort(DateSortIterator, reverse=False)
        ctx.custom_data['archives'] = it

        ctx.custom_data['monthly_archives'] = _MonthlyArchiveData(
            self.inner_source, year)
Esempio n. 3
0
    def prepareRenderContext(self, ctx):
        ctx.pagination_source = self.inner_source

        route_params = ctx.page.source_metadata['route_params']
        year = route_params.get('year')
        if year is None:
            raise Exception(
                "Can't find the archive year in the route metadata")
        if type(year) is not int:
            raise Exception(
                "The route for generator '%s' should specify an integer "
                "parameter for 'year'." % self.name)

        flt = PaginationFilter()
        flt.addClause(IsFromYearFilterClause(year))
        ctx.pagination_filter = flt

        ctx.custom_data['year'] = year

        flt2 = PaginationFilter()
        flt2.addClause(IsFromYearFilterClause(year))
        it = PageIterator(self.inner_source)
        it._simpleNonSortedWrap(HardCodedFilterIterator, flt2)
        it._wrapAsSort(DateSortIterator, reverse=False)
        ctx.custom_data['archives'] = it

        ctx.custom_data['monthly_archives'] = _MonthlyArchiveData(
            self.inner_source, year)
Esempio n. 4
0
 def _setTaxonomyFilter(self, ctx, term_value, is_combination):
     # Set up the filter that will check the pages' terms.
     flt = PaginationFilter()
     flt.addClause(
         HasTaxonomyTermsFilterClause(self.taxonomy, self.slugifier.mode,
                                      term_value, is_combination))
     ctx.pagination_filter = flt
Esempio n. 5
0
    def _getPaginationFilter(self):
        f = PaginationFilter(value_accessor=page_value_accessor)

        if self._pgn_filter is not None:
            f.addClause(self._pgn_filter.root_clause)

        if isinstance(self._source, IPaginationSource):
            sf = self._source.getPaginationFilter(self._parent_page)
            if sf is not None:
                f.addClause(sf.root_clause)

        return f
Esempio n. 6
0
    def setTaxonomyFilter(self, term_value, *, needs_slugifier=False):
        if not self.page.route.is_taxonomy_route:
            raise Exception("The page for this context is not tied to a "
                            "taxonomy route: %s" % self.uri)

        slugifier = None
        if needs_slugifier:
            slugifier = self.page.route.slugifyTaxonomyTerm
        taxonomy = self.app.getTaxonomy(self.page.route.taxonomy_name)

        flt = PaginationFilter(value_accessor=page_value_accessor)
        flt.addClause(HasTaxonomyTermsFilterClause(
                taxonomy, term_value, slugifier))
        self.pagination_filter = flt

        is_combination = isinstance(term_value, tuple)
        self.custom_data = {
                taxonomy.term_name: term_value,
                'is_multiple_%s' % taxonomy.term_name: is_combination}
Esempio n. 7
0
    def setTaxonomyFilter(self, term_value, *, needs_slugifier=False):
        if not self.page.route.is_taxonomy_route:
            raise Exception("The page for this context is not tied to a "
                            "taxonomy route: %s" % self.uri)

        slugifier = None
        if needs_slugifier:
            slugifier = self.page.route.slugifyTaxonomyTerm
        taxonomy = self.app.getTaxonomy(self.page.route.taxonomy_name)

        flt = PaginationFilter(value_accessor=page_value_accessor)
        flt.addClause(
            HasTaxonomyTermsFilterClause(taxonomy, term_value, slugifier))
        self.pagination_filter = flt

        is_combination = isinstance(term_value, tuple)
        self.custom_data = {
            taxonomy.term_name: term_value,
            'is_multiple_%s' % taxonomy.term_name: is_combination
        }
Esempio n. 8
0
    def prepareRenderContext(self, ctx):
        ctx.pagination_source = self.source

        year = ctx.page.route_metadata.get('year')
        if year is None:
            raise Exception(
                    "Can't find the archive year in the route metadata")
        if type(year) is not int:
            raise Exception(
                    "The route for generator '%s' should specify an integer "
                    "parameter for 'year'." % self.name)

        flt = PaginationFilter()
        flt.addClause(IsFromYearFilterClause(year))
        ctx.pagination_filter = flt

        ctx.custom_data['year'] = year

        flt2 = PaginationFilter()
        flt2.addClause(IsFromYearFilterClause(year))
        it = PageIterator(self.source, pagination_filter=flt2,
                          sorter=_date_sorter)
        ctx.custom_data['archives'] = it
Esempio n. 9
0
    def _load(self):
        if self._iterator is not None:
            return

        from piecrust.data.filters import PaginationFilter
        from piecrust.dataproviders.pageiterator import (
            PageIterator, HardCodedFilterIterator)

        self._iterator = PageIterator(self._source, current_page=self._page)

        if self._pgn_filter is not None:
            pag_fil = PaginationFilter()
            pag_fil.addClause(self._pgn_filter.root_clause)
            self._iterator._simpleNonSortedWrap(HardCodedFilterIterator,
                                                pag_fil)

        offset = (self._sub_num - 1) * self.items_per_page
        limit = self.items_per_page
        self._iterator.slice(offset, limit)

        if self._is_content_source:
            self._iterator._iter_event += self._onIteration

        self._iterator._lockIterator()
Esempio n. 10
0
    def setTaxonomyFilter(self, taxonomy, term_value):
        is_combination = isinstance(term_value, tuple)
        flt = PaginationFilter(value_accessor=page_value_accessor)
        if taxonomy.is_multiple:
            if is_combination:
                abc = AndBooleanClause()
                for t in term_value:
                    abc.addClause(HasFilterClause(taxonomy.setting_name, t))
                flt.addClause(abc)
            else:
                flt.addClause(
                        HasFilterClause(taxonomy.setting_name, term_value))
        else:
            flt.addClause(IsFilterClause(taxonomy.setting_name, term_value))
        self.pagination_filter = flt

        self.custom_data = {
                taxonomy.term_name: term_value,
                'is_multiple_%s' % taxonomy.term_name: is_combination}
Esempio n. 11
0
    def setTaxonomyFilter(self, taxonomy, term_value):
        is_combination = isinstance(term_value, tuple)
        flt = PaginationFilter(value_accessor=page_value_accessor)
        if taxonomy.is_multiple:
            if is_combination:
                abc = AndBooleanClause()
                for t in term_value:
                    abc.addClause(HasFilterClause(taxonomy.setting_name, t))
                flt.addClause(abc)
            else:
                flt.addClause(
                    HasFilterClause(taxonomy.setting_name, term_value))
        else:
            flt.addClause(IsFilterClause(taxonomy.setting_name, term_value))
        self.pagination_filter = flt

        self.custom_data = {
            taxonomy.term_name: term_value,
            'is_multiple_%s' % taxonomy.term_name: is_combination
        }
Esempio n. 12
0
 def _setTaxonomyFilter(self, ctx, term_value, is_combination):
     flt = PaginationFilter(value_accessor=page_value_accessor)
     flt.addClause(HasTaxonomyTermsFilterClause(
             self.taxonomy, self.slugify_mode, term_value, is_combination))
     ctx.pagination_filter = flt