[BlueBream] Attribute Annotation

Justin Ryan justin.ryan at reliefgarden.org
Sat Jun 19 12:30:15 EDT 2010


On Sat, Jun 19, 2010 at 3:57 AM, Adam GROSZER <agroszer at gmail.com> wrote:
> Hello Justin,
>

Howdy. :)

> How is your registration looking?
> Do you use zope.annotation?
>
>  >>> from zope.annotation import factory
>  >>> component.provideAdapter(factory(Bar))
>
> factory is there quite an important part there.
>
> If you "just" adapt, the adapter (GeoCodedLocation) won't be
> referenced by the adapted object, therefore it's never stored in the
> ZODB.
>

Sure, this is probably my problem.  What would this look like with
ZCML?  I have this:

  <adapter factory=".geolocation.GeoCodedLocation"
           provides="..interfaces.IGeoCodedLocation" />

  <subscriber
      for="reliefgarden.portal.interfaces.IGeoLocation
           zope.lifecycleevent.interfaces.IObjectModifiedEvent"
      handler="reliefgarden.portal.content.geolocation.update_geocode"
      />

Do I need to, in my .py file, define something =
factory(GeoCodedLocation) and refer to that?  This registration felt
wrong, but I couldn't find an example.

> A simpler, but non-transparent approach could be to make a property on
> IGeoLocation, and:
>
> class GeoCodedLocation(Persistent):
>     implements(IGeoCodedLocation)
>     adapts(IGeoLocation)
>
>     def __init__(self, context):
>        ###
>        context.geocode = self
>        ###
>         self.longitude = 0.0
>         self.latitude = 0.0
>

sure, or I could just adapt IAnnotations and set anno['geocode'], but
it seems unwise to choose a long-standing design based on something I
just couldn't figure out one day. :)

Thanks for your time..

Justin


More information about the bluebream mailing list