[BlueBream] Attribute Annotation

Justin Ryan justin.ryan at reliefgarden.org
Thu Jun 17 21:05:14 EDT 2010


Howdy!

I'm trying to use an Attribute Annotation Adapter to store Geo
Location info on some content types.  Roughly, I've been following the
doctest at:

  http://pypi.python.org/pypi/zope.annotation

I am happy to provide example code, what I have is a bit frazzled at
the moment because I upgraded my mac to snow leopard the other day and
apparently failed to commit the last set of changes to my project.
Whups.

Basically, here's the thing.

I have a couple interfaces:

class  IGeoLocation(Interface):
  address = TextLine(title=u"Address")

class IGeoCodedLocation(Interface)
  latitude = Float(title=u"Latitude")
  longitude = Float(title=u"Longitude")

I have an annotation adapter, as best I could manage:

class GeoCodedLocation(object):
  implements(IGeoCodedLocation)
  adapts(IGeoLocation)

  def __init__(self, context):
    self.longitude = 0.0
    self.latitude = 0.0

I have an event subscriber for (IObjectModified, IGeoLocation) which
is able to successfully adapt my original content type implement
IGeoLocation to an IGeoCodedLocation, hit the Google Geocoding API,
and log the geocoded lat and long.  I am able to log the lat and log
values from the adapted IGeoCodedLocation object.

But, it doesn't persist.  The next view of the object shows 0.0, 0.0.

I have a report of someone who had a similar problem with grok.  Is
this an underutilized feature that has a problem, or am I a completely
delusional idiot?

:)

Of course, I wish to contribute to the BlueBream docs info on this
because Attribute Annotation Adapters are a super freaking handy
pattern which are far more lightweight than containment for ancillary
functionality like commenting, rating, geolocation, etc..

Best,

Justin


More information about the bluebream mailing list