src/source/howto-renderer.rst
branchdoc-dc
changeset 70 2e1ed76f3c7d
parent 69 92e33e6b9e92
child 72 3f403b9c4220
equal deleted inserted replaced
69:92e33e6b9e92 70:2e1ed76f3c7d
    41 '''''''''''''''''''''''''''''
    41 '''''''''''''''''''''''''''''
    42 
    42 
    43 In the previous point, we did not change the settings interface of the renderer.
    43 In the previous point, we did not change the settings interface of the renderer.
    44 However, we can define a new settings interface for the new renderer, for that we start by creating an interface
    44 However, we can define a new settings interface for the new renderer, for that we start by creating an interface
    45 
    45 
    46 a) Create interface
    46 a) Create setting interface
    47 """""""""""""""""""
    47 """""""""""""""""""""""""""
    48 
    48 
    49 
    49 
    50 .. code-block:: python
    50 .. code-block:: python
    51 
       
    52 
    51 
    53     class ICustomRendererSettings(Interface):
    52     class ICustomRendererSettings(Interface):
    54         """Custom renderer settings interface"""
    53         """Custom renderer settings interface"""
    55 
    54 
    56 
    55 
    66 
    65 
    67         can_display_photo = Attribute("Check if photo can be displayed")
    66         can_display_photo = Attribute("Check if photo can be displayed")
    68 
    67 
    69 
    68 
    70 
    69 
    71 b) Implement interface
    70 b) Create an implemantation of the interface
    72 """"""""""""""""""""""
    71 """"""""""""""""""""""""""""""""""""""""""""
    73 
    72 
    74 .. code-block:: python
    73 .. code-block:: python
    75 
    74 
    76 
    75 
    77     @implementer(ICustomRendererSettings)
    76     @implementer(ICustomRendererSettings)
    88                 return False
    87                 return False
    89             return self.display_photo
    88             return self.display_photo
    90 
    89 
    91 
    90 
    92 
    91 
    93 c) Create the adapter
    92 c) Create an adapter for the render setting interface
    94 """""""""""""""""""""
    93 """""""""""""""""""""""""""""""""""""""""""""""""""""
       
    94 
       
    95 With the wrapper :py:func:`@adapter_config()` we declare a new adapter.
    95 
    96 
    96 .. code-block:: python
    97 .. code-block:: python
    97 
    98 
    98     CUSTOM_RENDERER_SETTINGS_KEY = 'pyams_content.contact.renderer:custom'
    99     CUSTOM_RENDERER_SETTINGS_KEY = 'pyams_content.contact.renderer:custom'
    99 
   100 
   101     def custom_renderer_settings_factory(context):
   102     def custom_renderer_settings_factory(context):
   102         """Contact paragraph default renderer settings factory"""
   103         """Contact paragraph default renderer settings factory"""
   103         return get_annotation_adapter(context, CUSTOM_RENDERER_SETTINGS_KEY,
   104         return get_annotation_adapter(context, CUSTOM_RENDERER_SETTINGS_KEY,
   104                                       CustomRendererSettings)
   105                                       CustomRendererSettings)
   105 
   106 
       
   107 In this example the settings interface adapter is defined with `IContactParagraph` as context
       
   108 and provide `ICustomRendererSettings`.
   106 
   109 
   107 d) Add settings interface renderer
   110 d) Add settings interface renderer
   108 """"""""""""""""""""""""""""""""""
   111 """"""""""""""""""""""""""""""""""
   109 
   112 
       
   113 In the renderer definition:
       
   114 
   110 .. code-block:: python
   115 .. code-block:: python
   111         settings_interface = ICustomRendererSettings
   116         settings_interface = ICustomRendererSettings
   112 
   117 
   113 By linking a setting_interface with renderer you can use directly in the template, setting attributs
       
   114 
   118 
       
   119 .. tip::
       
   120     When a setting_interface is associated to a renderer, you can acces to `settings` attributs through the template
       
   121