src/pyams_content/component/paragraph/milestone.py
changeset 1353 5940373ec65c
parent 1240 921ff38f1aae
--- a/src/pyams_content/component/paragraph/milestone.py	Wed Sep 25 09:52:05 2019 +0200
+++ b/src/pyams_content/component/paragraph/milestone.py	Wed Sep 25 15:11:13 2019 +0200
@@ -10,38 +10,44 @@
 # FOR A PARTICULAR PURPOSE.
 #
 
-__docformat__ = 'restructuredtext'
-
 from persistent import Persistent
 from pyramid.events import subscriber
 from zope.container.contained import Contained
 from zope.container.ordered import OrderedContainer
 from zope.interface import implementer
 from zope.lifecycleevent import ObjectModifiedEvent
-from zope.lifecycleevent.interfaces import IObjectAddedEvent, IObjectModifiedEvent, IObjectRemovedEvent
+from zope.lifecycleevent.interfaces import IObjectAddedEvent, IObjectModifiedEvent, \
+    IObjectRemovedEvent
 from zope.location import locate
 from zope.location.interfaces import ISublocations
 from zope.schema.fieldproperty import FieldProperty
 from zope.traversing.interfaces import ITraversable
 
 from pyams_catalog.utils import index_object
-from pyams_content.component.paragraph import BaseParagraph, BaseParagraphContentChecker, BaseParagraphFactory
-from pyams_content.component.paragraph.interfaces import IParagraphContainer, IParagraphContainerTarget, \
-    IParagraphFactory
-from pyams_content.component.paragraph.interfaces.milestone import IMilestone, IMilestoneContainer, \
-    IMilestoneContainerTarget, IMilestoneParagraph, MILESTONE_CONTAINER_KEY, MILESTONE_PARAGRAPH_NAME, \
-    MILESTONE_PARAGRAPH_RENDERERS, MILESTONE_PARAGRAPH_TYPE
+from pyams_content.component.paragraph import BaseParagraph, BaseParagraphContentChecker, \
+    BaseParagraphFactory
+from pyams_content.component.paragraph.interfaces import IParagraphContainer, \
+    IParagraphContainerTarget, IParagraphFactory
+from pyams_content.component.paragraph.interfaces.milestone import IMilestone, \
+    IMilestoneContainer, IMilestoneContainerTarget, IMilestoneParagraph, MILESTONE_CONTAINER_KEY, \
+    MILESTONE_PARAGRAPH_NAME, MILESTONE_PARAGRAPH_RENDERERS, MILESTONE_PARAGRAPH_TYPE
 from pyams_content.features.checker import BaseContentChecker
-from pyams_content.features.checker.interfaces import ERROR_VALUE, IContentChecker, MISSING_LANG_VALUE, MISSING_VALUE
+from pyams_content.features.checker.interfaces import ERROR_VALUE, IContentChecker, \
+    MISSING_LANG_VALUE, MISSING_VALUE
 from pyams_content.features.renderer import RenderersVocabulary
+from pyams_content.reference.pictograms import IPictogramTable
 from pyams_form.interfaces.form import IFormContextPermissionChecker
 from pyams_i18n.interfaces import II18n, II18nManager, INegotiator
 from pyams_utils.adapter import ContextAdapter, adapter_config, get_annotation_adapter
 from pyams_utils.factory import factory_config
-from pyams_utils.registry import get_current_registry, get_utility, utility_config
+from pyams_utils.registry import get_current_registry, get_utility, utility_config, query_utility
 from pyams_utils.request import check_request
 from pyams_utils.traversing import get_parent
 from pyams_utils.vocabulary import vocabulary_config
+from pyams_utils.zodb import volatile_property
+
+
+__docformat__ = 'restructuredtext'
 
 from pyams_content import _
 
@@ -57,9 +63,26 @@
     visible = FieldProperty(IMilestone['visible'])
     title = FieldProperty(IMilestone['title'])
     label = FieldProperty(IMilestone['label'])
+    _pictogram_name = FieldProperty(IMilestone['pictogram_name'])
     anchor = FieldProperty(IMilestone['anchor'])
 
     @property
+    def pictogram_name(self):
+        return self._pictogram_name
+
+    @pictogram_name.setter
+    def pictogram_name(self, value):
+        if value != self._pictogram_name:
+            self._pictogram_name = value
+            del self.pictogram
+
+    @volatile_property
+    def pictogram(self):
+        table = query_utility(IPictogramTable)
+        if table is not None:
+            return table.get(self._pictogram_name)
+
+    @property
     def target(self):
         container = get_parent(self, IParagraphContainer)
         if container is not None: