Mercurial > piecrust2
comparison piecrust/taxonomies.py @ 317:6c5de6edacf7
internal: Be more forgiving about building `Taxonomy` objects. Add `setting_name`.
The setting name of a taxonomy is whatever name is used to assign terms of that
taxonomy to a page. If the taxonomy is "multiple", this is the name of the
taxonomy. If not, it's the term name (a singular name).
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Sat, 28 Mar 2015 14:17:50 -0700 |
parents | f130365568ff |
children | e7b865f8f335 |
comparison
equal
deleted
inserted
replaced
316:eb958151c8dc | 317:6c5de6edacf7 |
---|---|
3 | 3 |
4 class Taxonomy(object): | 4 class Taxonomy(object): |
5 def __init__(self, app, name, config): | 5 def __init__(self, app, name, config): |
6 self.app = app | 6 self.app = app |
7 self.name = name | 7 self.name = name |
8 self.term_name = config['term'] | 8 self.term_name = config.get('term', name) |
9 self.is_multiple = config['multiple'] | 9 self.is_multiple = config.get('multiple', False) |
10 self.page_ref = config['page'] | 10 self.page_ref = config.get('page') |
11 self._source_page_refs = {} | 11 self._source_page_refs = {} |
12 | |
13 @property | |
14 def setting_name(self): | |
15 if self.is_multiple: | |
16 return self.name | |
17 return self.term_name | |
12 | 18 |
13 def resolvePagePath(self, source_name): | 19 def resolvePagePath(self, source_name): |
14 pr = self.getPageRef(source_name) | 20 pr = self.getPageRef(source_name) |
15 try: | 21 try: |
16 return pr.path | 22 return pr.path |