Adapters for cataloged objects

4 messages Options
Embed this post
Permalink
taito () Adapters for cataloged objects
Reply Threaded More More options
Print post
Permalink
Hi All,

Can somebody tell me what is the best practice to adapts adapters to cataloged objects?

For example, I have ATDocument cataloged as Products.ZCatalog.Catalog.mybrains object.

I have adapter MyAdapter which adapts ATDocument and provide IMyAdapter.

To Adapt this cataloged object, I need to wake it up by using getObject() method like:

IMyAdapter(cataloged_object.getObject())

Waking up object from zodb is not good practice so, I wonder how you guys do this better.

Please let me share your better way of dealing with this.

Taito


_______________________________________________
Product-Developers mailing list
[hidden email]
http://lists.plone.org/mailman/listinfo/product-developers
Martin Aspeli () Re: Adapters for cataloged objects
Reply Threaded More More options
Print post
Permalink
Taito Horiuchi wrote:

> Hi All,
>
> Can somebody tell me what is the best practice to adapts adapters to
> cataloged objects?
>
> For example, I have ATDocument cataloged as
> Products.ZCatalog.Catalog.mybrains object.
>
> I have adapter MyAdapter which adapts ATDocument and provide IMyAdapter.
>
> To Adapt this cataloged object, I need to wake it up by using
> getObject() method like:
>
> IMyAdapter(cataloged_object.getObject())
>
> Waking up object from zodb is not good practice so, I wonder how you
> guys do this better.

That depends on how many objects you're waking up and how big they are.
It's not always going to be a bad idea.

> Please let me share your better way of dealing with this.

You can either index the value you care about using a custom indexer
(i.e. you do the adaptation on indexing rather than after your search),
or wake up the object, or approach your problem differently. :)

Martin


--
Author of `Professional Plone Development`, a book for developers who
want to work with Plone. See http://martinaspeli.net/plone-book


_______________________________________________
Product-Developers mailing list
[hidden email]
http://lists.plone.org/mailman/listinfo/product-developers
Martin Aspeli () Re: Adapters for cataloged objects
Reply Threaded More More options
Print post
Permalink
In reply to this post by taito
Taito Horiuchi wrote:

> Hi All,
>
> Can somebody tell me what is the best practice to adapts adapters to
> cataloged objects?
>
> For example, I have ATDocument cataloged as
> Products.ZCatalog.Catalog.mybrains object.
>
> I have adapter MyAdapter which adapts ATDocument and provide IMyAdapter.
>
> To Adapt this cataloged object, I need to wake it up by using
> getObject() method like:
>
> IMyAdapter(cataloged_object.getObject())
>
> Waking up object from zodb is not good practice so, I wonder how you
> guys do this better.

... and I forgot to add: you can always use a different adapter that
adapts IZCatalogBrain or whatever it is (see the ZCatalog code) and
provides your interface. This then needs to be able to do all its work
with the information on the catalog brain (or wake up the object).

However, you can't get a *different* adapter depending on what the
underlying object was when it was cataloged. All brains are created equal.

Martin

--
Author of `Professional Plone Development`, a book for developers who
want to work with Plone. See http://martinaspeli.net/plone-book


_______________________________________________
Product-Developers mailing list
[hidden email]
http://lists.plone.org/mailman/listinfo/product-developers
taito () Re: Re: Adapters for cataloged objects
Reply Threaded More More options
Print post
Permalink
Thanks Martin,

I was talking about waking up a few objects to less than 100 objects from zodb,
so getObject() method may be the right choice.

I considered using IZCatalogBrain, but as you mentioned, brains don't give underlying object's implementation, so I rejected to use this in my use case.

Thanks,

Taito


On Thu, Jun 18, 2009 at 9:27 PM, Martin Aspeli <[hidden email]> wrote:
Taito Horiuchi wrote:
Hi All,

Can somebody tell me what is the best practice to adapts adapters to cataloged objects?

For example, I have ATDocument cataloged as Products.ZCatalog.Catalog.mybrains object.

I have adapter MyAdapter which adapts ATDocument and provide IMyAdapter.

To Adapt this cataloged object, I need to wake it up by using getObject() method like:

IMyAdapter(cataloged_object.getObject())

Waking up object from zodb is not good practice so, I wonder how you guys do this better.

... and I forgot to add: you can always use a different adapter that adapts IZCatalogBrain or whatever it is (see the ZCatalog code) and provides your interface. This then needs to be able to do all its work with the information on the catalog brain (or wake up the object).

However, you can't get a *different* adapter depending on what the underlying object was when it was cataloged. All brains are created equal.


Martin

--
Author of `Professional Plone Development`, a book for developers who
want to work with Plone. See http://martinaspeli.net/plone-book


_______________________________________________
Product-Developers mailing list
[hidden email]
http://lists.plone.org/mailman/listinfo/product-developers


_______________________________________________
Product-Developers mailing list
[hidden email]
http://lists.plone.org/mailman/listinfo/product-developers