src/pyams_content/component/gallery/renderer.py
changeset 426 ad309e5090bd
parent 425 a3147e47cd39
child 427 45d98c5efc7e
equal deleted inserted replaced
425:a3147e47cd39 426:ad309e5090bd
     1 #
       
     2 # Copyright (c) 2008-2015 Thierry Florac <tflorac AT ulthar.net>
       
     3 # All Rights Reserved.
       
     4 #
       
     5 # This software is subject to the provisions of the Zope Public License,
       
     6 # Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
       
     7 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
       
     8 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
       
     9 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
       
    10 # FOR A PARTICULAR PURPOSE.
       
    11 #
       
    12 
       
    13 __docformat__ = 'restructuredtext'
       
    14 
       
    15 
       
    16 # import standard library
       
    17 
       
    18 # import interfaces
       
    19 from pyams_content.component.gallery.interfaces import IBaseGallery
       
    20 from pyams_content.features.renderer.interfaces import IContentRenderer
       
    21 
       
    22 # import packages
       
    23 from pyams_content.component.gallery import Gallery
       
    24 from pyams_utils.request import check_request
       
    25 from pyams_utils.vocabulary import vocabulary_config
       
    26 from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm
       
    27 
       
    28 
       
    29 @vocabulary_config(name='PyAMS gallery renderers')
       
    30 class GalleryRendererVocabulary(SimpleVocabulary):
       
    31     """Gallery renderer utilities vocabulary"""
       
    32 
       
    33     def __init__(self, context=None):
       
    34         request = check_request()
       
    35         translate = request.localizer.translate
       
    36         registry = request.registry
       
    37         if not IBaseGallery.providedBy(context):
       
    38             context = Gallery()
       
    39         terms = [SimpleTerm(name, title=translate(adapter.label))
       
    40                  for name, adapter in sorted(registry.getAdapters((context, request), IContentRenderer),
       
    41                                              key=lambda x: x[1].weight)]
       
    42         super(GalleryRendererVocabulary, self).__init__(terms)