Exemplo n.º 1
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
Exemplo n.º 2
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()
Exemplo n.º 3
0
    def __iter__(self):
        if self._fil is None:
            self._fil = PaginationFilter()
            self._fil.addClausesFromConfig(self.fil_conf)

        for i in self.it:
            if self._fil.pageMatches(i):
                yield i
Exemplo n.º 4
0
    def __iter__(self):
        if self._fil is None:
            self._fil = PaginationFilter(value_accessor=self.setting_accessor)
            self._fil.addClausesFromConfig(self.fil_conf)

        for i in self.it:
            if self._fil.pageMatches(i):
                yield i
Exemplo n.º 5
0
 def getPaginationFilter(self, page):
     conf = (page.config.get('items_filters') or
             self.config.get('items_filters'))
     if conf == 'none' or conf == 'nil' or conf == '':
         conf = None
     if conf is not None:
         f = PaginationFilter(value_accessor=page_value_accessor)
         f.addClausesFromConfig(conf)
         return f
     return None
Exemplo n.º 6
0
 def getPaginationFilter(self, page):
     conf = (page.config.get('items_filters') or
             self.config.get('items_filters'))
     if conf == 'none' or conf == 'nil' or conf == '':
         conf = None
     if conf is not None:
         f = PaginationFilter(value_accessor=page_value_accessor)
         f.addClausesFromConfig(conf)
         return f
     return None
Exemplo n.º 7
0
class SettingFilterIterator:
    def __init__(self, it, fil_conf):
        self.it = it
        self.fil_conf = fil_conf
        self._fil = None

    def __iter__(self):
        if self._fil is None:
            self._fil = PaginationFilter()
            self._fil.addClausesFromConfig(self.fil_conf)

        for i in self.it:
            if self._fil.pageMatches(i):
                yield i
Exemplo n.º 8
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)
Exemplo n.º 9
0
class SettingFilterIterator(object):
    def __init__(self, it, fil_conf, setting_accessor=None):
        self.it = it
        self.fil_conf = fil_conf
        self._fil = None
        self.setting_accessor = setting_accessor

    def __iter__(self):
        if self._fil is None:
            self._fil = PaginationFilter(value_accessor=self.setting_accessor)
            self._fil.addClausesFromConfig(self.fil_conf)

        for i in self.it:
            if self._fil.pageMatches(i):
                yield i
Exemplo n.º 10
0
class SettingFilterIterator(object):
    def __init__(self, it, fil_conf, setting_accessor=None):
        self.it = it
        self.fil_conf = fil_conf
        self._fil = None
        self.setting_accessor = setting_accessor

    def __iter__(self):
        if self._fil is None:
            self._fil = PaginationFilter(value_accessor=self.setting_accessor)
            self._fil.addClausesFromConfig(self.fil_conf)

        for i in self.it:
            if self._fil.pageMatches(i):
                yield i
Exemplo n.º 11
0
    def __init__(self, source, *,
                 current_page=None,
                 pagination_filter=None, sorter=None,
                 offset=0, limit=-1, locked=False):
        self._source = source
        self._current_page = current_page
        self._locked = False
        self._pages = source
        self._pagesData = None
        self._pagination_slicer = None
        self._has_sorter = False
        self._next_page = None
        self._prev_page = None
        self._iter_event = Event()

        if isinstance(source, IPaginationSource):
            src_it = source.getSourceIterator()
            if src_it is not None:
                self._pages = src_it

        # If we're currently baking, apply the default baker filter
        # to exclude things like draft posts.
        if (isinstance(source, PageSource) and
                source.app.config.get('baker/is_baking')):
            setting_name = source.app.config.get('baker/no_bake_setting',
                                                 'draft')
            accessor = self._getSettingAccessor()
            draft_filter = PaginationFilter(accessor)
            draft_filter.root_clause = NotClause()
            draft_filter.root_clause.addClause(
                    IsFilterClause(setting_name, True))
            self._simpleNonSortedWrap(
                    PaginationFilterIterator, draft_filter)

        # Apply any filter first, before we start sorting or slicing.
        if pagination_filter is not None:
            self._simpleNonSortedWrap(PaginationFilterIterator,
                                      pagination_filter)

        if sorter is not None:
            self._simpleNonSortedWrap(GenericSortIterator, sorter)
            self._has_sorter = True

        if offset > 0 or limit > 0:
            self.slice(offset, limit)

        self._locked = locked
Exemplo n.º 12
0
    def __iter__(self):
        if self._fil is None:
            self._fil = PaginationFilter(value_accessor=self.setting_accessor)
            self._fil.addClausesFromConfig(self.fil_conf)

        for i in self.it:
            if self._fil.pageMatches(i):
                yield i
Exemplo n.º 13
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}
Exemplo n.º 14
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
        }
Exemplo n.º 15
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)
Exemplo n.º 16
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()
Exemplo n.º 17
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
Exemplo n.º 18
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
        }
Exemplo n.º 19
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}
Exemplo n.º 20
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
Exemplo n.º 21
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