Re: [Zope3-Users] view vs page confused

2007-03-28 Thread FB
Hi,

On Tue, Mar 27, 2007 at 06:03:54PM +0200, Dominique Lederer wrote:

[snip]

 so if i create a class which inherits from BrowserView, and then register it 
 via
 zcml as browser:page, it becomes adaptes to IBrowserRequest an turns to a
 BrowserPage (via the on-the-fly created class)? so inheriting from BrowserPage
 instead from BrowserView would make no sense with my example?

It doesn't event make sense to inherit from BrowserView because a 
browser:page-registered
view-class is just a mixin. A class like this is enough:

class MyView(object):
   def mySpecialMethod(self):
  [...]
   [...]


browser:page class=.views.MyView [...] /

Regards,

Frank
___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


[Zope3-Users] fine grained subscriber

2007-03-28 Thread Lorenzo Gil Sanchez
Hi,

I'm writing an event subscriber to the IIntIdRemoveEvent event type. It
looks like this:

def intIdRemovedSubscriber(event):
  if IMyInterface.providedBy(event.object):
 # do some stuff with event.object

and the zcml:

subscriber
 handler=.intIdRemovedSubscriber
 for=zope.app.intid.interfaces.IIntIdRemovedEvent
 /

But I'd like to avoid the if clause inside my subscriber function by
doing something similar to this:

def intIdRemovedSubscriber(obj, event):
  # do some stuff with obj, which is garanteed to provide IMyInterface

subscriber
 handler=.intIdRemovedSubscriber
 for=.interfaces.IMyInterface
  zope.app.intid.interfaces.IIntIdRemovedEvent
 /

But when doing this second aproach my subscriber is not called. I
supposed I could do this by looking in the zope source code and finding
this in zope.app.intid.__init__.py

@adapter(ILocation, IObjectRemovedEvent)
def removeIntIdSubscriber(ob, event):
  # 

and 

subscriber handler=.removeIntIdSubscriber /

So the question is: why the intid package is succesful in registering a
subscriber only for ILocation objects and I can't do the same with
IMyInterface objects?

I want to avoid a lot of calls to my subscriber which will happend
everytime an IntId is removed from *any* object.

Thanks in advance

Lorenzo Gil

___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


Re: [Zope3-Users] fine grained subscriber

2007-03-28 Thread FB
Hi,

On Wed, Mar 28, 2007 at 12:16:23PM +0200, Lorenzo Gil Sanchez wrote:

[snip]

 But I'd like to avoid the if clause inside my subscriber function by
 doing something similar to this:
 
 def intIdRemovedSubscriber(obj, event):
   # do some stuff with obj, which is garanteed to provide IMyInterface
 
 subscriber
  handler=.intIdRemovedSubscriber
  for=.interfaces.IMyInterface
   zope.app.intid.interfaces.IIntIdRemovedEvent
  /

[snip]

 So the question is: why the intid package is succesful in registering a
 subscriber only for ILocation objects and I can't do the same with
 IMyInterface objects?
 
 I want to avoid a lot of calls to my subscriber which will happend
 everytime an IntId is removed from *any* object.

[snip]

You need a dispatcher - a quite common concept in zope3:

[events.py, not tested]
from zope.event import notify

def removeIntId(event):
notify(event.object,event)

def addIntId(event):
notify(event.object,event)



[configure.zcml, not tested]
   [...]
subscriber for=zope.app.intid.interfaces.IntIdAddedEvent
handler=.event.addIntId
/
subscriber for=zope.app.intid.interfaces.IntIdRemovedEvent
handler=.events.removeIntId
/
   [...]

Thanks to zope3's component infrastructure, a package (like intid) doesn't
have to provide the dispatcher - a different package providing the dispatcher
is perfectly fine.

Regards,

Frank
___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


[Zope3-Users] problems with catalog: indexing field from an objects adapter

2007-03-28 Thread Dominique Lederer
hi,

I want to index a field from an object, which works perfectly via Catalog and
Field Index.

But if my callable field returns a value, which is returned from an adapter of
the object, things get complicated for me:

i create my object an add it to a container (not via zmi).
i do the notify(ObjectCreatedEvent(container[myobjectname]) thing, to let the
intid and catalog do their indexing stuff.
i look at the Catalog statistics in the zmi, where is see, that one item is 
indexed.
but when i delete the object (i used
notifiy(ObjectRemovedEvent(container[myobjectname])), there is still something
residing in the index, which causes a KeyError in the intid utility, when it
trys to getObject.

It seems, that the index is indexing the object and the adapter via the same
unique intid, and then deletes only the objects index, and not the adapter?

since my adapter is only accessing annotations on the object, i could feed the
index directly via the annotation value, but that goes against the use of
adapters and the idea, not to change the object implementation.

Do you have any idea, what i have to do?
Did i forget an event? or something else?

thanks
cheers Dominique
___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


Re: [Zope3-Users] fine grained subscriber

2007-03-28 Thread Lorenzo Gil Sanchez
El mié, 28-03-2007 a las 13:39 +0200, Lorenzo Gil Sanchez escribió:
 El mié, 28-03-2007 a las 12:50 +0200, FB escribió:
  
  You need a dispatcher - a quite common concept in zope3:
  
  [events.py, not tested]
  from zope.event import notify
  
  def removeIntId(event):
  notify(event.object,event)
  
 
I changed the removeIntId dispatcher to this code:

def removeIntId(event):
adapters = zope.component.subscribers((event.object, event), None)
for adapter in adapters:
pass # getting them does the work

and now it works!! My subscriber is called only when an IntId is removed
on objects that provide IMyInterface.

Thanks a lot Mark, for showing me the right direction.

Regards,

Lorenzo


___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


Re: [Zope3-Users] FieldIndex on boolean field - error

2007-03-28 Thread FB
Hi,

On Wed, Mar 28, 2007 at 03:55:28PM +, Alek Kowalczyk wrote:
 Hi,
 I'm trying to index a boolean field of some object, to simplify retrieving all
 the objects which have some flag turned on.
 
 I am adding in proper place the index:
 
 catalog['anomaly'] = FieldIndex('anomaly', IMyObject)
 
 But then, when I try to get the objects using the following command, I get an
 exception. Is FieldIndex able to index bool field? If not, how to create own
 index for doing that?
 
 anomalies = catalog.searchResults(anomaly=True)

[snip]

 TypeError: len() of unsized object

A fieldindex always requires a lower and an upper boundary, found objects must
fit into.

Try

 catalog.searchResults(anomaly=(True,True))

BTW: The error is raised because the fieldindex tries to interpret 'True'
as a tuple.

Regards,

Frank
___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users