diff piecrust/routing.py @ 515:16e705c58cae

internal: Improve handling of taxonomy term slugification. This paves the way to bring slugification options like transliteration to PieCrust. This change mostly makes sure we use one-way slugification, which means, for serving/previewing, we need to slugify each page's terms to compare to the stuff captured from the URL. It also simplifies things a bit in the code.
author Ludovic Chabant <ludovic@chabant.com>
date Sun, 26 Jul 2015 23:16:15 -0700
parents 64e1cd71b30b
children bab91fcef741
line wrap: on
line diff
--- a/piecrust/routing.py	Sun Jul 26 23:05:04 2015 -0700
+++ b/piecrust/routing.py	Sun Jul 26 23:16:15 2015 -0700
@@ -42,6 +42,7 @@
 
         self.source_name = cfg['source']
         self.taxonomy_name = cfg.get('taxonomy')
+        self.taxonomy_term_sep = cfg.get('term_separator', '/')
 
         self.pretty_urls = app.config.get('site/pretty_urls')
         self.trailing_slash = app.config.get('site/trailing_slash')
@@ -191,19 +192,26 @@
 
         return uri
 
+    def getTaxonomyTerms(self, route_metadata):
+        if not self.is_taxonomy_route:
+            raise Exception("This route isn't a taxonomy route.")
+
+        tax = self.app.getTaxonomy(self.taxonomy_name)
+        all_values = route_metadata.get(tax.term_name)
+        if all_values is None:
+            raise Exception("'%s' values couldn't be found in route metadata" %
+                            tax.term_name)
+
+        if self.taxonomy_term_sep in all_values:
+            return tuple(all_values.split(self.taxonomy_term_sep))
+        return all_values
+
     def slugifyTaxonomyTerm(self, term):
         #TODO: add options for transliterating and combining terms.
         if isinstance(term, tuple):
             return '/'.join(term)
         return term
 
-    def unslugifyTaxonomyTerm(self, term):
-        #TODO: same as above.
-        split_terms = term.split('/')
-        if len(split_terms) == 1:
-            return term
-        return tuple(split_terms)
-
     def _uriFormatRepl(self, m):
         name = m.group('name')
         #TODO: fix this hard-coded shit