Question

With archetypes.schemaextender I add an ImageField to ATEvent.

The code of extender.py can be found here : http://pastealacon.com/29670

And in the configure.zcml I have this :

<include package="archetypes.schemaextender" />
<adapter for="Products.ATContentTypes.interface.IATEvent"
    factory=".extender.ContentImageExtender" />

This work pretty good, when I edit an ATEvent, I saw my field, no problem.

But, in the Summary View, the exists:item_object/image return False

I think it's because it's on the object itself, not on the adapter... How can I make it work ?

Was it helpful?

Solution

If you want to access a schema extended field, you cannot rely on the accessors that Archetypes would normally automatically create for you, because Archetypes is at that time not yet aware of the schema extended fields.

Instead, you have to call the Schema() method, which will fetch the object's normal schema as well as all extended fields. And from that you can get the field and call its accessor.

So you could get the image like this:

item_object.Schema().getField('image').getAccessor(item_object)()

I looked at the folder_summary_view.pt template, and you would have to change the code to look like this:

<a href="#"
   tal:define="image python:item_object.Schema().getField('image');
               image python:image and image.getAccessor(item_object)();"
   tal:condition="image"
   tal:attributes="href python:test(item_type in use_view_action, item_url+'/view', item_url)">
   <img src="" alt=""
        tal:replace="structure python:path('nocall:image/tag')(scale=0.5, css_class='tileImage')" />
</a>

It will then work.

EDIT: You can also go the route that ggozad suggests. In your bobo_traverse method you then still have to get the field by first calling Schema() as I mention above.

OTHER TIPS

The summary view in Plone checks for image_thumb if I remember correctly. You schema extender is fine, but you miss altering the traverse. To do so you need to monkey patch __bobo_traverse__. Have a look at ATImage in ATContentTypes to see how to do this.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top