Mercurial > piecrust2
comparison piecrust/rendering.py @ 324:65e6d72f3877
bake/serve: Fix how taxonomy index pages are setup and rendered.
* Properly use the taxonomy's setting name where appropriate.
* Delete duplicated (and sometimes incorrect) code in 2 places to setup
filtering on an index page and consolidate it on the `PageRenderingContext`.
* Add unit tests.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Sun, 29 Mar 2015 23:08:37 -0700 |
parents | 27d623a241c6 |
children | 422052d2e978 |
comparison
equal
deleted
inserted
replaced
323:412537e91e45 | 324:65e6d72f3877 |
---|---|
1 import re | 1 import re |
2 import os.path | 2 import os.path |
3 import logging | 3 import logging |
4 from piecrust.data.builder import (DataBuildingContext, build_page_data, | 4 from piecrust.data.builder import (DataBuildingContext, build_page_data, |
5 build_layout_data) | 5 build_layout_data) |
6 from piecrust.data.filters import ( | |
7 PaginationFilter, HasFilterClause, IsFilterClause, AndBooleanClause, | |
8 page_value_accessor) | |
6 from piecrust.sources.base import PageSource | 9 from piecrust.sources.base import PageSource |
7 from piecrust.templating.base import TemplateNotFoundError, TemplatingError | 10 from piecrust.templating.base import TemplateNotFoundError, TemplatingError |
8 from piecrust.uriutil import get_slug | 11 from piecrust.uriutil import get_slug |
9 | 12 |
10 | 13 |
81 | 84 |
82 def addUsedSource(self, source): | 85 def addUsedSource(self, source): |
83 if isinstance(source, PageSource): | 86 if isinstance(source, PageSource): |
84 self.used_source_names.add((source.name, self.current_pass)) | 87 self.used_source_names.add((source.name, self.current_pass)) |
85 | 88 |
89 def setTaxonomyFilter(self, taxonomy, term_value): | |
90 flt = PaginationFilter(value_accessor=page_value_accessor) | |
91 if taxonomy.is_multiple: | |
92 if isinstance(term_value, tuple): | |
93 abc = AndBooleanClause() | |
94 for t in term_value: | |
95 abc.addClause(HasFilterClause(taxonomy.setting_name, t)) | |
96 flt.addClause(abc) | |
97 else: | |
98 flt.addClause( | |
99 HasFilterClause(taxonomy.setting_name, term_value)) | |
100 else: | |
101 flt.addClause(IsFilterClause(taxonomy.setting_name, term_value)) | |
102 self.pagination_filter = flt | |
103 self.custom_data = { | |
104 taxonomy.term_name: term_value} | |
105 | |
86 | 106 |
87 def render_page(ctx): | 107 def render_page(ctx): |
88 eis = ctx.app.env.exec_info_stack | 108 eis = ctx.app.env.exec_info_stack |
89 eis.pushPage(ctx.page, ctx) | 109 eis.pushPage(ctx.page, ctx) |
90 try: | 110 try: |