Generalized RodelbahnboxTemplateDict and renamed it to WinterrodelnTemplateDict.
authorphilipp <philipp@7aebc617-e5e2-0310-91dc-80fb5f6d2477>
Mon, 17 Mar 2014 20:15:41 +0000 (20:15 +0000)
committerphilipp <philipp@7aebc617-e5e2-0310-91dc-80fb5f6d2477>
Mon, 17 Mar 2014 20:15:41 +0000 (20:15 +0000)
git-svn-id: http://www.winterrodeln.org/svn/wrpylib/trunk@1931 7aebc617-e5e2-0310-91dc-80fb5f6d2477

wrpylib/wrmwmarkup.py

index 27d82e37c7d88285cfcfb7d44477246c6eff3753..127298ec183eda640438526573edc66b6edc2e4e 100644 (file)
@@ -95,24 +95,27 @@ class RodelbahnboxDictConverter(formencode.Validator):
         return r
 
 
-class RodelbahnboxTemplateDict(formencode.Validator):
-    """Private helper class for RodelbahnboxValidator"""
+class WinterrodelnTemplateDict(formencode.Validator):
+    """Private helper class for RodelbahnboxValidator or GasthausboxValidator"""
+    def __init__(self, template_title):
+        self.template_title = template_title
+
     def to_python(self, value, state):
         title, anonym_params, named_params = value
-        if title != u'Rodelbahnbox':
-            raise Invalud('Template title has to be "Rodelbahnbox".', value, state)
+        if title != self.template_title:
+            raise Invalud(u'Template title has to be "{}".'.format(self.template_title), value, state)
         if len(anonym_params) > 0:
-            raise Invalid('No anonymous parameters are allowed in "Rodelbahnbox".', value, state)
+            raise Invalid(u'No anonymous parameters are allowed in "{}".'.format(self.template_title), value, state)
         return named_params
 
     def from_python(self, value, state):
-        return u'Rodelbahnbox', [], value
+        return self.template_title, [], value
 
 
 class RodelbahnboxValidator(wrpylib.wrvalidators.RodelbahnboxDictValidator):
     def __init__(self):
         wrpylib.wrvalidators.RodelbahnboxDictValidator.__init__(self)
-        self.pre_validators=[wrpylib.mwmarkup.TemplateValidator(as_table=True, as_table_keylen=20), RodelbahnboxTemplateDict()]
+        self.pre_validators=[wrpylib.mwmarkup.TemplateValidator(as_table=True, as_table_keylen=20), WinterrodelnTemplateDict(u'Rodelbahnbox')]
         self.chained_validators = [RodelbahnboxDictConverter()]