src/pyams_file/skin/__init__.py
changeset 219 1c07e0c889ba
parent 218 458cf3d033aa
equal deleted inserted replaced
218:458cf3d033aa 219:1c07e0c889ba
     9 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
     9 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
    10 # FOR A PARTICULAR PURPOSE.
    10 # FOR A PARTICULAR PURPOSE.
    11 #
    11 #
    12 
    12 
    13 __docformat__ = 'restructuredtext'
    13 __docformat__ = 'restructuredtext'
       
    14 
       
    15 import json
    14 
    16 
    15 from pyramid.renderers import render
    17 from pyramid.renderers import render
    16 from zope.interface import Interface
    18 from zope.interface import Interface
    17 
    19 
    18 from pyams_utils.adapter import ContextRequestViewAdapter, adapter_config
    20 from pyams_utils.adapter import ContextRequestViewAdapter, adapter_config
    33     embedding all image attributes.
    35     embedding all image attributes.
    34     """
    36     """
    35 
    37 
    36     def render(self, context=None, lg_thumb='lg', lg_width=12, md_thumb='md', md_width=12,
    38     def render(self, context=None, lg_thumb='lg', lg_width=12, md_thumb='md', md_width=12,
    37                sm_thumb='sm', sm_width=12, xs_thumb='xs', xs_width=12,
    39                sm_thumb='sm', sm_width=12, xs_thumb='xs', xs_width=12,
    38                def_thumb=None, def_width=None, alt='', css_class='', img_width='100%'):
    40                def_thumb=None, def_width=None, alt='', css_class='', pic_class=None,
       
    41                img_width='100%', data=None):
    39         if context is None:
    42         if context is None:
    40             context = self.context
    43             context = self.context
    41         if context.content_type.startswith('image/svg'):
    44         if context.content_type.startswith('image/svg'):
    42             return render('templates/svg-picture.pt', {
    45             return render('templates/svg-picture.pt', {
    43                 'image': context,
    46                 'image': context,
    52         else:
    55         else:
    53             if def_thumb is None:
    56             if def_thumb is None:
    54                 def_thumb = md_thumb or lg_thumb or sm_thumb or xs_thumb
    57                 def_thumb = md_thumb or lg_thumb or sm_thumb or xs_thumb
    55             if def_width is None:
    58             if def_width is None:
    56                 def_width = md_width or lg_width or sm_width or xs_width
    59                 def_width = md_width or lg_width or sm_width or xs_width
       
    60             data = json.dumps(data) if data else ''
    57             return render('templates/picture.pt', {
    61             return render('templates/picture.pt', {
    58                 'image': context,
    62                 'image': context,
    59                 'lg_thumb': lg_thumb,
    63                 'lg_thumb': lg_thumb,
    60                 'lg_width': lg_width,
    64                 'lg_width': lg_width,
    61                 'md_thumb': md_thumb,
    65                 'md_thumb': md_thumb,
    65                 'xs_thumb': xs_thumb,
    69                 'xs_thumb': xs_thumb,
    66                 'xs_width': xs_width,
    70                 'xs_width': xs_width,
    67                 'def_thumb': def_thumb,
    71                 'def_thumb': def_thumb,
    68                 'def_width': def_width,
    72                 'def_width': def_width,
    69                 'alt': alt,
    73                 'alt': alt,
       
    74                 'pic_class': pic_class,
    70                 'css_class': css_class,
    75                 'css_class': css_class,
    71                 'img_width': img_width
    76                 'img_width': img_width,
       
    77                 'data': data
    72             }, request=self.request)
    78             }, request=self.request)