src/pyams_content/component/paragraph/keynumber.py
changeset 555 8e8a14452567
parent 527 5dd1aa8bedd9
child 558 d9c6b1d7fefa
equal deleted inserted replaced
554:120ce09ade94 555:8e8a14452567
    31 
    31 
    32 # import packages
    32 # import packages
    33 from pyams_catalog.utils import index_object
    33 from pyams_catalog.utils import index_object
    34 from pyams_content.component.paragraph import BaseParagraph, BaseParagraphFactory, BaseParagraphContentChecker
    34 from pyams_content.component.paragraph import BaseParagraph, BaseParagraphFactory, BaseParagraphContentChecker
    35 from pyams_content.features.checker import BaseContentChecker
    35 from pyams_content.features.checker import BaseContentChecker
    36 from pyams_content.features.renderer import RenderedContentMixin, IContentRenderer
    36 from pyams_content.features.renderer import RenderersVocabulary
    37 from pyams_utils.adapter import adapter_config, ContextAdapter
    37 from pyams_utils.adapter import adapter_config, ContextAdapter
       
    38 from pyams_utils.factory import factory_config
    38 from pyams_utils.registry import get_current_registry, get_utility, utility_config
    39 from pyams_utils.registry import get_current_registry, get_utility, utility_config
    39 from pyams_utils.request import check_request
    40 from pyams_utils.request import check_request
    40 from pyams_utils.traversing import get_parent
    41 from pyams_utils.traversing import get_parent
    41 from pyams_utils.vocabulary import vocabulary_config
    42 from pyams_utils.vocabulary import vocabulary_config
    42 from pyramid.events import subscriber
    43 from pyramid.events import subscriber
    44 from zope.container.ordered import OrderedContainer
    45 from zope.container.ordered import OrderedContainer
    45 from zope.interface import implementer
    46 from zope.interface import implementer
    46 from zope.lifecycleevent import ObjectCreatedEvent, ObjectModifiedEvent
    47 from zope.lifecycleevent import ObjectCreatedEvent, ObjectModifiedEvent
    47 from zope.location import locate
    48 from zope.location import locate
    48 from zope.schema.fieldproperty import FieldProperty
    49 from zope.schema.fieldproperty import FieldProperty
    49 from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm
       
    50 
    50 
    51 from pyams_content import _
    51 from pyams_content import _
    52 
    52 
    53 
    53 
    54 #
    54 #
   204                 output.append(checker.get_check_output(request))
   204                 output.append(checker.get_check_output(request))
   205         return output
   205         return output
   206 
   206 
   207 
   207 
   208 @implementer(IKeyNumberParagraph)
   208 @implementer(IKeyNumberParagraph)
   209 class KeyNumberParagraph(RenderedContentMixin, BaseParagraph):
   209 @factory_config(provided=IKeyNumberParagraph)
       
   210 class KeyNumberParagraph(BaseParagraph):
   210     """Key numbers paragraph"""
   211     """Key numbers paragraph"""
   211 
   212 
   212     icon_class = 'fa-list-ol'
   213     icon_class = 'fa-list-ol'
   213     icon_hint = _("Key numbers")
   214     icon_hint = _("Key numbers")
   214 
   215 
   254                     output.append(translate(MISSING_LANG_VALUE).format(field=field_title, lang=lang))
   255                     output.append(translate(MISSING_LANG_VALUE).format(field=field_title, lang=lang))
   255         return output
   256         return output
   256 
   257 
   257 
   258 
   258 @vocabulary_config(name=KEYNUMBER_PARAGRAPH_RENDERERS)
   259 @vocabulary_config(name=KEYNUMBER_PARAGRAPH_RENDERERS)
   259 class KeyNumberParagraphRendererVocabulary(SimpleVocabulary):
   260 class KeyNumberParagraphRendererVocabulary(RenderersVocabulary):
   260     """Key numbers paragraph renderers vocabulary"""
   261     """Key numbers paragraph renderers vocabulary"""
   261 
   262 
   262     def __init__(self, context=None):
   263     content_interface = IKeyNumberParagraph
   263         request = check_request()
       
   264         translate = request.localizer.translate
       
   265         registry = request.registry
       
   266         if not IKeyNumberParagraph.providedBy(context):
       
   267             context = KeyNumberParagraph()
       
   268         terms = [SimpleTerm(name, title=translate(adapter.label))
       
   269                  for name, adapter in sorted(registry.getAdapters((context, request), IContentRenderer),
       
   270                                              key=lambda x: x[1].weight)]
       
   271         super(KeyNumberParagraphRendererVocabulary, self).__init__(terms)