[BlueBream] Attribute Annotation
Ilshad Khabibullin
astoon.net at gmail.com
Thu Jun 17 21:57:59 EDT 2010
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.zope.org/pipermail/bluebream/attachments/20100618/8d308466/attachment.html
More information about the bluebream
mailing list