[BlueBream] Attribute Annotation

Adam GROSZER agroszer at gmail.com
Sat Jun 19 06:57:42 EDT 2010


Hello Justin,

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.

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


Saturday, June 19, 2010, 4:23:12 AM, you wrote:

JR> I think I did follow the directions, without an adapter registered in
JR> zcml I got an adaptation failure.

JR> Once it's adapted, it doesn't persist is my problemski.

JR> On Thu, Jun 17, 2010 at 6:57 PM, Ilshad Khabibullin
JR> <astoon.net at gmail.com> wrote:
>> Hi Justin,
>>
>> That's crafty hook with "factories" to build annnotation, yes :)
>> It seems you missed Persistent inheritance for that adapter factory, i.e.::
>>
>> class GeoCodedLocation(Persistent):
>>     implements(IGeoCodedLocation)
>>     adapts(IGeoLocation)
>>
>>     def __init__(self, context):
>>         self.longitude = 0.0
>>         self.latitude = 0.0
>>
>> 2010/6/18 Justin Ryan <justin.ryan at reliefgarden.org>
>>>
>>> FWIW, when I put the lat/long schema fields onto IGeoLocation, and
>>> changed all adaptions from IGeoCodedLocation to IGeoLocation, which of
>>> course the object already implemented, everything worked.
>>>
>>> There are some details in here where, I set the form up with two
>>> schemas, but the IGeoLocation adaption was just the original object.
>>>
>>> If what I'm doing is crazy, I'd appreciate any input, and be happy to
>>> help impart that wisdom into the BB docs.
>>>
>>> On Thu, Jun 17, 2010 at 6:05 PM, Justin Ryan
>>> <justin.ryan at reliefgarden.org> wrote:
>>> > 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
>>> >
>>> _______________________________________________
>>> bluebream mailing list
>>> bluebream at zope.org
>>> https://mail.zope.org/mailman/listinfo/bluebream
>>
>>
>>
>> --
>> Ilshad R. Khabibullin
>> http://astoon.zwiki.org
>> +7 922 600 56 06
>>
JR> _______________________________________________
JR> bluebream mailing list
JR> bluebream at zope.org
JR> https://mail.zope.org/mailman/listinfo/bluebream


-- 
Best regards,
 Adam GROSZER                            mailto:agroszer at gmail.com
--
Quote of the day:
You cannot kill time without injuring eternity.



More information about the bluebream mailing list