コード例 #1
0
ファイル: taxonomy.py プロジェクト: zaxebo1/PieCrust2
 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
コード例 #2
0
ファイル: paginator.py プロジェクト: ludovicchabant/PieCrust2
    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()
コード例 #3
0
ファイル: pageiterator.py プロジェクト: zaxebo1/PieCrust2
    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
コード例 #4
0
ファイル: iterators.py プロジェクト: qman1989/PieCrust2
    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
コード例 #5
0
ファイル: mixins.py プロジェクト: kinow/PieCrust2
 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
コード例 #6
0
ファイル: mixins.py プロジェクト: germanschnyder/PieCrust2
 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
コード例 #7
0
ファイル: pageiterator.py プロジェクト: zaxebo1/PieCrust2
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
コード例 #8
0
ファイル: blogarchives.py プロジェクト: zaxebo1/PieCrust2
    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)
コード例 #9
0
ファイル: iterators.py プロジェクト: qman1989/PieCrust2
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
コード例 #10
0
ファイル: iterators.py プロジェクト: thhgcn/PieCrust2
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
コード例 #11
0
ファイル: iterators.py プロジェクト: germanschnyder/PieCrust2
    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
コード例 #12
0
ファイル: iterators.py プロジェクト: thhgcn/PieCrust2
    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
コード例 #13
0
ファイル: rendering.py プロジェクト: thhgcn/PieCrust2
    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}
コード例 #14
0
ファイル: rendering.py プロジェクト: kinow/PieCrust2
    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
        }
コード例 #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)
コード例 #16
0
ファイル: paginator.py プロジェクト: zaxebo1/PieCrust2
    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()
コード例 #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
コード例 #18
0
ファイル: rendering.py プロジェクト: qman1989/PieCrust2
    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
        }
コード例 #19
0
ファイル: rendering.py プロジェクト: qman1989/PieCrust2
    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}
コード例 #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
コード例 #21
0
ファイル: taxonomy.py プロジェクト: germanschnyder/PieCrust2
 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