[Product-Developers] Adapter issue/ Products.Maps / SQLAlchemy

Derek Broughton derek at pointerstop.ca
Sun Aug 16 21:11:09 UTC 2009


I'm trying to add a map to a page containing the results of a SQL query.

I tried installing Products.Maps, and hooking their map view into my content 
type.

A sqlalchemy result set consists of sqlalchemy.engine.base.RowProxy, so the 
first thing I needed was an interface I could use to adapt to Product.Maps 
IRichMarker interface (or any geolocated interface, I guess).

  <five:implements
      class="sqlalchemy.engine.base.RowProxy"
      interface=".mapadapter.IRowProxy" 
      />

Now, an adapter:
  <adapter
      factory=".mapadapter.RowLocation"
      provides="Products.Maps.interfaces.marker.IRichMarker"
      for=".mapadapter.IRowProxy"
      />

And this piece of zcml that doesn't actually seem to be doing anything for 
me, but just matches something in Products.Maps...

  <class class=".mapadapter.RowLocation">
     <allow interface="Products.Maps.interfaces.marker.IRichMarker" />
  </class>

Finally, the actual adapter:

  class RowLocation(object):
    implements(IRichMarker)
    adapts(IRowProxy)

    def __init__(self, context):
        self.context = context

If I write a log message in __init__ I can see that I get to that point 
without problems. If I don't define any of the methods of the IRichMarker 
interface, I get an error that shows I'm on the right track:
  Module Products.Maps.browser.map, line 30, in getMarkers
  AttributeError: 'RowLocation' object has no attribute 'longitude'

Perfect!  It's obviously getting the view I wanted 
(Products.Maps.browser.map) and it's executing the adapter, and it's true 
the RowLocation object has no attribute 'longitude".

Unfortunately, if I define longitude (or any other attribute/method of 
IRichMarker), either in __init__ as:
     self.longitude = context.longitude
or the way RichMarker does:
    @property
    def longitude(self):
        return self.context.longitude
or even:
        return ''

I get the dreaded "Insufficient Privileges" message.  When I turn on Verbose 
Security, I don't see any kind of security message, I see a browser message:
  The requested operation could not be completed
  Request Aborted By User

Any ideas what I'm missing?
-- 
derek






More information about the Product-Developers mailing list