[Product-Developers] UnicodeDecodeError while rendering image from dexterity content type

Noe Nieto nnieto at noenieto.com
Thu Jul 28 16:42:33 UTC 2011


Plone 4.1, Dexterity 1.0.1
I have a Dexterity content-type with
plone.app.content.interfaces.INameFromTitle and
plone.app.dexterity.behaviors.metadata.IBasic behaviors:
The schema is this:

class IAuthor(form.Schema):
    """
    Profile for Book or DVD authors.
    """

    portrait = namedfile.NamedBlobImage(
        title=_(u"Author's Portrait/Photo"),
        description=_(u"Portrayal of the Author."),
        required=True,
    )

    form.widget(bio="plone.app.z3cform.wysiwyg.WysiwygFieldWidget")
    bio = schema.Text(
        title=_(u"Author's Bio"),
        description=_(u"The Author's Bio"),
        required=True,
    )

The template is very basic:

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"
      xmlns:tal="http://xml.zope.org/namespaces/tal"
      xmlns:metal="http://xml.zope.org/namespaces/metal"
      xmlns:i18n="http://xml.zope.org/namespaces/i18n"
      lang="en"
      metal:use-macro="context/main_template/macros/master"
      i18n:domain="holokinesislibros.contenttypes">
<body>


<metal:main fill-slot="content-core">
  <metal:content-core define-macro="content-core">

        <div class="bio-portrait"
             tal:define="portrait nocall:context/portrait"
             tal:condition="nocall:portrait">
             <img tal:replace="structure context/@@images/portrait/mini" />
        </div>

       <div tal:content="structure context/bio" />

  </metal:content-core>
</metal:main>

</body>
</html>

If I add an author with non-ascii chars in the title, the template will
throw a traceback:

2011-07-28 09:34:42 ERROR Zope.SiteErrorLog 1311870882.960.569752426632
http://localhost:8002/Plone/author-with-accents-aeion/view
Traceback (innermost last):
  Module ZPublisher.Publish, line 126, in publish
  Module ZPublisher.mapply, line 77, in mapply
  Module ZPublisher.Publish, line 46, in call_object
  Module grokcore.view.components, line 100, in __call__
  Module grokcore.view.components, line 104, in _render_template
  Module five.grok.components, line 134, in render
  Module zope.pagetemplate.pagetemplate, line 113, in pt_render
  Module zope.tal.talinterpreter, line 271, in __call__
  Module zope.tal.talinterpreter, line 343, in interpret
  Module zope.tal.talinterpreter, line 888, in do_useMacro
  Module zope.tal.talinterpreter, line 343, in interpret
  Module zope.tal.talinterpreter, line 533, in do_optTag_tal
  Module zope.tal.talinterpreter, line 518, in do_optTag
  Module zope.tal.talinterpreter, line 513, in no_tag
  Module zope.tal.talinterpreter, line 343, in interpret
  Module zope.tal.talinterpreter, line 954, in do_defineSlot
  Module zope.tal.talinterpreter, line 343, in interpret
  Module zope.tal.talinterpreter, line 533, in do_optTag_tal
  Module zope.tal.talinterpreter, line 518, in do_optTag
  Module zope.tal.talinterpreter, line 513, in no_tag
  Module zope.tal.talinterpreter, line 343, in interpret
  Module zope.tal.talinterpreter, line 858, in do_defineMacro
  Module zope.tal.talinterpreter, line 343, in interpret
  Module zope.tal.talinterpreter, line 954, in do_defineSlot
  Module zope.tal.talinterpreter, line 343, in interpret
  Module zope.tal.talinterpreter, line 533, in do_optTag_tal
  Module zope.tal.talinterpreter, line 518, in do_optTag
  Module zope.tal.talinterpreter, line 513, in no_tag
  Module zope.tal.talinterpreter, line 343, in interpret
  Module zope.tal.talinterpreter, line 954, in do_defineSlot
  Module zope.tal.talinterpreter, line 343, in interpret
  Module zope.tal.talinterpreter, line 533, in do_optTag_tal
  Module zope.tal.talinterpreter, line 518, in do_optTag
  Module zope.tal.talinterpreter, line 513, in no_tag
  Module zope.tal.talinterpreter, line 343, in interpret
  Module zope.tal.talinterpreter, line 946, in do_defineSlot
  Module zope.tal.talinterpreter, line 343, in interpret
  Module zope.tal.talinterpreter, line 533, in do_optTag_tal
  Module zope.tal.talinterpreter, line 518, in do_optTag
  Module zope.tal.talinterpreter, line 513, in no_tag
  Module zope.tal.talinterpreter, line 343, in interpret
  Module zope.tal.talinterpreter, line 858, in do_defineMacro
  Module zope.tal.talinterpreter, line 343, in interpret
  Module zope.tal.talinterpreter, line 533, in do_optTag_tal
  Module zope.tal.talinterpreter, line 518, in do_optTag
  Module zope.tal.talinterpreter, line 513, in no_tag
  Module zope.tal.talinterpreter, line 343, in interpret
  Module zope.tal.talinterpreter, line 852, in do_condition
  Module zope.tal.talinterpreter, line 343, in interpret
  Module zope.tal.talinterpreter, line 531, in do_optTag_tal
  Module zope.tal.talinterpreter, line 513, in no_tag
  Module zope.tal.talinterpreter, line 343, in interpret
  Module zope.tal.talinterpreter, line 742, in do_insertStructure_tal
  Module Products.PageTemplates.Expressions, line 218, in evaluateStructure
  Module zope.tales.tales, line 696, in evaluate
   - URL:
/home/tzicatl/Aplicaciones/Codigo/pu/holokinesis_libros/src/holokinesislibros.contenttypes/holokinesislibros/contenttypes/templates/
author.pt
   - Line 17, Column 13
   - Expression: <PathExpr standard:u'context/@@images/portrait/mini'>
   - Names:
      {'args': (),
       'container': <Author at /Plone/author-with-accents-aeion>,
       'context': <Author at /Plone/author-with-accents-aeion>,
       'default': <object object at 0xb783b6b0>,
       'here': <Author at /Plone/author-with-accents-aeion>,
       'loop': {},
       'nothing': None,
       'options': {},
       'repeat': <Products.PageTemplates.Expressions.SafeMapping object at
0xcb6289c>,
       'request': <HTTPRequest, URL=
http://localhost:8002/Plone/author-with-accents-aeion/view>,
       'root': <Application at >,
       'static': <five.grok.components.ZopeTwoDirectoryResource object at
0xb5309c0c>,
       'template':
<Products.Five.browser.pagetemplatefile.ViewPageTemplateFile object at
0xd329c8c>,
       'traverse_subpath': [],
       'user': <PropertiedUser 'admin'>,
       'view': <holokinesislibros.contenttypes.author.View object at
0xb533848c>,
       'views': <Products.Five.browser.pagetemplatefile.ViewMapper object at
0xb532348c>}
  Module zope.tales.expressions, line 217, in __call__
  Module Products.PageTemplates.Expressions, line 147, in _eval
  Module zope.tales.expressions, line 124, in _eval
  Module Products.PageTemplates.Expressions, line 97, in
trustedBoboAwareZopeTraverse
  Module zope.traversing.adapters, line 136, in traversePathElement
   - __traceback_info__: (<Products.Five.metaclass.ImageScaling object at
0xb53306cc>, 'portrait')
  Module plone.namedfile.scaling, line 126, in traverse
  Module plone.namedfile.scaling, line 68, in tag
  Module plone.namedfile.scaling, line 68, in <genexpr>
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 20:
ordinal not in range(128)


This is the plone.namedfile.scaling.ImageScale::tag() function:

    def tag(self, height=_marker, width=_marker, alt=_marker,
            css_class=None, title=_marker, **kwargs):
        """Create a tag including scale
        """
        if height is _marker:
            height = getattr(self, 'height', self.data._height)
        if width is _marker:
            width = getattr(self, 'width', self.data._width)

        if alt is _marker:
            alt = self.context.Title()
        if title is _marker:
            title = self.context.Title()

        values = [
            ('src', self.url),
            ('alt', alt),
            ('title', title),
            ('height', height),
            ('width', width),
            ('class', css_class),
            ]
        values.extend(kwargs.items())

        parts = ['<img']
        parts.extend("%s=%s" % (k, quoteattr(unicode(v))) for k, v in values
if v is not None)
        parts.append('/>')

        return u' '.join(parts)

It takes the context's title and uses it for the alt and title attributes of
the img tag.  Is this a bug in plone.app.scaling or in my code?


-- 
---
Noe Nieto
NNieto Consulting Services
M: nnieto at noenieto.com
W: http://noenieto.com
T:  @tzicatl <https://twitter.com/#%21/tzicatl>
Li: Perfil en LinkedIn <http://www.linkedin.com/profile/view?id=84300665>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.plone.org/pipermail/plone-product-developers/attachments/20110728/fa79960e/attachment-0001.html>


More information about the Product-Developers mailing list