Use vocabulary to display milestone anchor
authorThierry Florac <thierry.florac@onf.fr>
Wed, 04 Apr 2018 14:43:09 +0200
changeset 514 27a1c8d531b9
parent 513 c65e71af9288
child 515 a1d5eb955e54
Use vocabulary to display milestone anchor
src/pyams_content/component/paragraph/zmi/milestone.py
--- a/src/pyams_content/component/paragraph/zmi/milestone.py	Wed Apr 04 14:41:57 2018 +0200
+++ b/src/pyams_content/component/paragraph/zmi/milestone.py	Wed Apr 04 14:43:09 2018 +0200
@@ -59,6 +59,7 @@
 from z3c.form import field, button
 from z3c.table.column import GetAttrColumn
 from zope.interface import implementer, Interface
+from zope.schema.vocabulary import getVocabularyRegistry
 
 from pyams_content import _
 
@@ -318,16 +319,23 @@
     _header = _("Anchor")
     weight = 30
 
+    defaultValue = ' '.join(('-',) * 8)
+
     def getValue(self, obj):
         if not obj.anchor:
-            return '--'
+            return self.defaultValue
         target = get_parent(self.context, IParagraphContainerTarget)
         if target is None:
-            return '--'
-        paragraph= IParagraphContainer(target).get(obj.anchor)
-        if paragraph is None:
-            return '--'
-        return II18n(paragraph).query_attribute('title', request=self.request) or '--'
+            return self.defaultValue
+        try:
+            vocabulary = getVocabularyRegistry().get(obj, 'PyAMS content paragraphs')
+        except LookupError:
+            paragraph = IParagraphContainer(target).get(obj.anchor)
+            if paragraph is None:
+                return self.defaultValue
+            return II18n(paragraph).query_attribute('title', request=self.request) or self.defaultValue
+        else:
+            return vocabulary.getTermByToken(obj.anchor).title
 
 
 @adapter_config(name='trash', context=(IMilestoneContainerTarget, IPyAMSLayer, MilestonesTable), provides=IColumn)