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):
  [...]
   [...]




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:



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



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 



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
> 
>   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]
   [...]


   [...]

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 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 think the notify call should be like notify((event.object, event))

> def addIntId(event):
>   notify(event.object,event)
> 
> 
> 
> [configure.zcml, not tested]
>[...]
>  handler=".event.addIntId"
>   />
>  handler=".events.removeIntId"
>   />
>[...]
> 
Ok, the removeIntId function is called and it dispatch the event through
the notify call.

Then, my original subscriber, e.g.:



is still not called. I have checked that in the removeIntId subscriber
the object in event.object provides IMyInterface, but this makes no
difference.

Anyway, thanks for this answer (and all the other answer you gave me
before) :-)

Regards,

Lorenzo

___
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


[Zope3-Users] FieldIndex on boolean field - error

2007-03-28 Thread Alek Kowalczyk
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)

  File "C:\Python24\Lib\site-packages\zope\app\catalog\catalog.py", line 121, in
searchResults
results = self.apply(searchterms)
  File "C:\Python24\Lib\site-packages\zope\app\catalog\catalog.py", line 100, in
apply
r = index.apply(index_query)
  File "C:\Python24\Lib\site-packages\zope\index\field\index.py", line 99, in 
apply
if len(query) != 2 or not isinstance(query, tuple):
TypeError: len() of unsized object

___
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


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

2007-03-28 Thread Aleksander Kowalczyk

On 3/28/07, FB <[EMAIL PROTECTED]> wrote:


Hi,

On Wed, Mar 28, 2007 at 03:55:28PM +, Alek Kowalczyk wrote:
> Hi,Is FieldIndex able to index bool field? If not, how to create own
> index for doing that?
>
> anomalies = catalog.searchResults(anomaly=True)

Try

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

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



Thanks! I didn't think that the solution is so simple.
___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


[Zope3-Users] Formlib - handleSubmit, custom validator on action

2007-03-28 Thread Darryl Cousins
Hi,

I'm curious about custom validators on a form action:

@action('Edit', validator=my_validator)
def edit(self, **data):
...

The validator is called from 'update' method of the form:
formlib/form.py line 736:

  errors, action = handleSubmit(self.actions, data, self.validate)

but the line previous says

  data = {}

So my validator always receives an empty dictionary to validate.

The validator is called with arguments 'form, action, data' and should
return a list of errors (if any). Do I need then to use the form object
to retrieve the submitted values? If so, why is 'data' passed at all if
it is always an empty dictionary?

Curious.
Regards,
Darryl

PS I know and have used @invariant but I'm generating the schema
formfields instead of using an interface (where I would normally place
the invariant).

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