Re: [Zope3-Users] buildout recipe for ReportLab

2008-07-11 Thread Lorenzo Gil Sanchez
El vie, 11-07-2008 a las 10:35 +0200, Christian Theune escribió:
 On Thu, 2008-07-10 at 21:21 +0200, Lorenzo Gil Sánchez wrote:
  Hi,
  
  I'd like to ask if anybody is using a buildout recipe to install
  ReportLab in the buildout.
 
 I only declare 'ReportLab' as a dependency. Whats the issue?

There is no egg for ReportLab so just adding it as a dependency can't
make setuptools/easy_install to download and install it:

(z3env)[EMAIL PROTECTED] z3env]$ easy_install reportlab
Searching for reportlab
Reading http://pypi.python.org/simple/reportlab/
Reading http://www.reportlab.com/
Reading http://www.reportlab.org/downloads.html
No local packages or download links found for reportlab
error: Could not find suitable distribution for
Requirement.parse('reportlab')

So, what recipe can download the ReportLab tarball and install it?

I feel like I'm missing something...

Lorenzo

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


[Zope3-Users] public view on a private object

2007-12-19 Thread Lorenzo Gil Sanchez
Hi zopers,

I got a security problem today and I finally fix it but I still wanted
to share it with the rest of you to ask for advice and to help others to
avoid my problem.

My problem was that I have a content type whose class was configured
with:

require
permission=zope.ManageContent
interface=.interfaces.IMyContent
/

And I have a default view for this class that looks like this:

page

  for=mypackage.interfaces.IMyContent
  name=welcome.html
  class=.views.IndexView
  permission=zope.View
  template=index.pt
  title=Index menu=zmi_views
  /

As you can see there is a contradiction here: the view is 'public' but the 
object is 'private'.
I see it now but it tooked my a while to discover it. Obviously I have a bunch 
of content types,
packages and configure.zcml files so it was not so easy.

So the real problem in my opinion is how Zope helps us to discover this kind of 
configuration
bugs. All I have was an 'Internal Server Error' (500) and a stack trace like 
this:

--- exception caught here ---
  File /home/lgs/Python-2.4.4/Zope-3.3.1/lib/python/twisted/web2/wsgi.py, 
line 139, in run
result = self.application(self.environment, self.startWSGIResponse)
  File 
/home/lgs/Python-2.4.4/Zope-3.3.1/lib/python/zope/app/wsgi/__init__.py, line 
55, in __call__
request = publish(request, handle_errors=handle_errors)
  File 
/home/lgs/Python-2.4.4/Zope-3.3.1/lib/python/zope/publisher/publish.py, line 
141, in publish
publication.handleException(
  File 
/home/lgs/Python-2.4.4/Zope-3.3.1/lib/python/zope/app/publication/zopepublication.py,
 line 261, in handleException
self._logErrorWithErrorReportingUtility(object, request, exc_info)
  File 
/home/lgs/Python-2.4.4/Zope-3.3.1/lib/python/zope/app/publication/zopepublication.py,
 line 215, in _logErrorWithErrorReportingUtility
'error reporting utility')
  File 
/home/lgs/Python-2.4.4/Zope-3.3.1/lib/python/zope/app/publication/zopepublication.py,
 line 384, in beginErrorHandlingTransaction
self.annotateTransaction(txn, request, ob)
  File 
/home/lgs/Python-2.4.4/Zope-3.3.1/lib/python/zope/app/publication/http.py, 
line 55, in annotateTransaction
txn = super(BaseHTTPPublication, self).annotateTransaction(
  File 
/home/lgs/Python-2.4.4/Zope-3.3.1/lib/python/zope/app/publication/zopepublication.py,
 line 197, in annotateTransaction
path = locatable.getPath()
  File 
/home/lgs/Python-2.4.4/Zope-3.3.1/lib/python/zope/location/traversing.py, 
line 147, in getPath
path.append(context.__name__)
zope.security.interfaces.Unauthorized: (mypackage.mycontent.MyContent object 
at 0xa9e3aec, '__name__', 'zope.ManageContent')

Some questions arises:

- Why didn't it pop up the typical http challengue asking me for credentials 
when
it discovered that I was trying to access an object and I didn't have the
appropiate permissions?

- Why do I have to define permissions for a view if I already configured the 
same
permissions for the class? The view should always have more restrictive 
permissions
that the content type class or is there any use case for the opposite?

- Is the above stack trace clear enough for experienced zope3 developers so they
can quickly spot the problem or is it just me that I couldn't figure it out for 
a
long time?

Thanks for your patience

Lorenzo Gil

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


Re: [Zope3-Users] Re: lack of security declaration: bug or feature?

2007-11-07 Thread Lorenzo Gil Sanchez
Oh, I didn't know you could use the 'attributes' attribute in the
require directive! It looks quite useful and fits perfectly in this
case.

Thanks for your answers to this newbie!

Lorenzo

El lun, 05-11-2007 a las 13:10 +0100, Thierry Florac escribió:
 Le lundi 05 novembre 2007 à 12:35 +0100, Lorenzo Gil Sanchez a écrit :
  Oh, that's true indeed. It's a shame IOrderedContainer is defined as
  inheriting from IContainer because I can't declare a permission for the
  updateOrder method in an independent way. Something like: I want Public
  permission for reading an ordered folder and I want ManageContent
  permission for writing *and* changing the folder order.
 
 I've done this configuration, which seems OK for me until now :
 
 class class=.MyOrderedContainer
 implements
 interface=zope.annotation.interfaces.IAttributeAnnotatable /
 require
 interface=zope.app.container.interfaces.IReadContainer
 permission=zope.View /
 require
 interface=zope.app.container.interfaces.IWriteContainer
 attributes=updateOrder
 permission=zope.ManageContent /
 /class
 
 
   Thierry Florac

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


Re: [Zope3-Users] Re: lack of security declaration: bug or feature?

2007-11-05 Thread Lorenzo Gil Sanchez
El vie, 02-11-2007 a las 22:32 +0100, Philipp von Weitersehausen escribió:

 I think OrderedContainer is a base class for your own container types. I 
 don't see a problem if it doesn't have security declarations.
 

I understand. Thanks for the aclaration.

 By the way, you probably want to split up your security declarations 
 into read and write...
 
Oh, that's true indeed. It's a shame IOrderedContainer is defined as
inheriting from IContainer because I can't declare a permission for the
updateOrder method in an independent way. Something like: I want Public
permission for reading an ordered folder and I want ManageContent
permission for writing *and* changing the folder order.

Thanks for your answers Philipp!

Best regards,

Lorenzo

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


[Zope3-Users] lack of security declaration: bug or feature?

2007-11-02 Thread Lorenzo Gil Sanchez
Hi,

I'm using zope.app.container.ordered.OrderedContainer in my application
and I got this error:

ForbiddenAttribute: ('__getitem__',
zope.app.container.ordered.OrderedContainer object at 0xaf5aa6c)

I added this lines to my configure.zcml:

  class class=zope.app.container.ordered.OrderedContainer
require
permission=zope.ManageContent
interface=zope.app.container.interfaces.IOrderedContainer
/
  /class

and that fixed the error.

It's totally ok when it's adding security declarations to my classes but
I feel a little bit awkward addind security declarations to Zope
classes.

Is this the right way to do? Shouldn't those lines belong to
zope.app.container's configure.zcml file?

Best regards

Lorenzo

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


Re: [Zope3-Users] zopeproject and debugging zope

2007-09-10 Thread Lorenzo Gil Sanchez
I finally make a quick'n'dirty script to run the debugger. I'll paste it
here justs in case anybody find it useful:

#!/opt/bin/python

import sys
sys.path[0:0] = [
  # lots of eggs
]

import os
import code
import zope.app.debug

banner = Welcome to the Zope 3 debugger.
The application root object is available as the root variable.
A Zope debugger instance is available as the debugger (aka app)
variable.


def debug():
base_dir =
os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
zodb = os.path.join(base_dir, 'var', 'Data.fs')
zcml = os.path.join(base_dir, 'site.zcml')
debugger = zope.app.debug.Debugger(zodb, zcml)

globs = dict(
debugger = debugger,
app = debugger,
root = debugger.root()
)
code.interact(banner=banner, local=globs)

if __name__ == '__main__':
debug()


It is based on zc.zope3recipes.debugzope, which I couldn't make to work.

Best regards

Lorenzo Gil

El sáb, 08-09-2007 a las 20:27 +0200, Lorenzo Gil Sanchez escribió:
 Hi,
 
 I recently switched to use zope3 as a library instead as a big
 application where you hook your webapp. Thanks to Philipp for his great
 zopeproject!
 
 Now I miss something from the old 'bin/runzope' days. I liked how you
 could run an interactive debug session using zope.app.debug.Debugger and
 the command 'bin/zopectl debug'.
 
 I'm willing to contribute something to zopeproject to add this feature
 but I'm not quite sure about where to start.
 
 I guess at least an egg with an entry point that starts the debugger and
 another part for the buildout.cfg that uses the zc.recipe.egg recipe and
 that egg need to be done.
 
 Something I don't understand about the current buildout.cfg file is how
 this part
 
 [app]
 recipe = zc.recipe.egg
 eggs = PruebasZ3
Paste
PasteScript
PasteDeploy
 
 ends creating the paster script in the bin directory. I guess I need
 something similar to be able to run the debugger.
 
 Can anybody give me a clue?
 
 Lorenzo
 
 ___
 Zope3-users mailing list
 Zope3-users@zope.org
 http://mail.zope.org/mailman/listinfo/zope3-users
 

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


Re: [Zope3-Users] zopeproject and debugging zope

2007-09-09 Thread Lorenzo Gil Sanchez
El sáb, 08-09-2007 a las 16:27 -0400, Benji York escribió:
 Lorenzo Gil Sanchez wrote:
  Now I miss something from the old 'bin/runzope' days. I liked how you
  could run an interactive debug session using zope.app.debug.Debugger and
  the command 'bin/zopectl debug'.
 
 If you use the zc.zope3recipes:instance recipe to build an instance 
 (even one that you never start) it will accept a debug command, just 
 like zopectl.

I read
http://svn.zope.org/zc.zope3recipes/trunk/zc/zope3recipes/README.txt?rev=78368view=auto

and tried to use zc.zope3recipes. The instance recipe depends on the
application recipe which I can't get to work. This is my buildout.cfg
file:

[buildout]
develop = .
parts = myapp
find-links = http://download.zope.org/distribution/
eggs-directory = /home/lgs/proyectos/jt-yaco/zope3-eggs
newest = false

[zope3]
location = . 

[myapp]
recipe = zc.zope3recipes:app
site.zcml = include package=pruebasz3 /
principal id=zope.manager
 title=Manager
 login=admin
 password_manager=Plain Text
 password=admin
 /
grant role=zope.Manager
 principal=zope.manager
 /
eggs = PruebasZ3


And this is the error I get when running bin/buildout:

[EMAIL PROTECTED] PruebasZ3]$ bin/buildout 
Develop: '/home/lgs/proyectos/jt-yaco/PruebasZ3/.'
Installing myapp.
While:
  Installing myapp.

An internal error occured due to a bug in either zc.buildout or in a
recipe being used:

NameError:
global name 'logger' is not defined


I'm not sure if this is due to a conflict with my existing buildout
environment created by zopeproject. Nevertheless, I really apreciate
your answer but I was looking to a more integrated aproach with
zopeproject which I like best because it's simpler, at least for newbies
like me.

Maybe the problem with zopeproject and debuging a zope3 application is
that zopeproject uses Paste for the http server instead of zserver or
twisted and that make it harder to use with zope.app.debug.Debugger.

Lorenzo

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


[Zope3-Users] zopeproject and debugging zope

2007-09-08 Thread Lorenzo Gil Sanchez
Hi,

I recently switched to use zope3 as a library instead as a big
application where you hook your webapp. Thanks to Philipp for his great
zopeproject!

Now I miss something from the old 'bin/runzope' days. I liked how you
could run an interactive debug session using zope.app.debug.Debugger and
the command 'bin/zopectl debug'.

I'm willing to contribute something to zopeproject to add this feature
but I'm not quite sure about where to start.

I guess at least an egg with an entry point that starts the debugger and
another part for the buildout.cfg that uses the zc.recipe.egg recipe and
that egg need to be done.

Something I don't understand about the current buildout.cfg file is how
this part

[app]
recipe = zc.recipe.egg
eggs = PruebasZ3
   Paste
   PasteScript
   PasteDeploy

ends creating the paster script in the bin directory. I guess I need
something similar to be able to run the debugger.

Can anybody give me a clue?

Lorenzo

___
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 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] Views for adapted components

2007-03-26 Thread Lorenzo Gil Sanchez
Hi everybody,

I have several components and now I want to add ImportExport
funcionality to some of them.

So I created a simple interface called IImportExport:

class IImportExport(Interface):

  def importFromFile(filename):
pass

  def exportToFile(filename):
pass

Now, all I have to do is write an adapter for each component I want to
make importable/exportable. Piece of cake:

class ImportExportAdapter1(object):
  implements(IImportExport)
  __used_for__ = IMyComponent

 def importFromFile(self, filename):
   pass

 def exportToFile(self, filename):
   pass

and in the zcml:

adapter
  for=.interfaces.IMyComponent
  provides=.interfaces.IImportExport
  factory=.adapters.ImportExportAdapter1
  /

So far so good.

Now the problem: I have a view for IImportExport objects. It just lets
the user choose a name for the file and execute the import or export
method. I want this view to appears in the ZMI tabs for every object
that has an adapter to IImportExport.

If I use implements(IImportExport) in MyComponent class even when it
does not implements IImportExport directly but trough an adapter I can
see the view for objects of type IMyComponent *but* instead of doing

IImportExport(object).exportFromFile(filename)

I have to write

adapter = zope.component.getAdapter(object, IImportExport)
adapter.exportFromFile(filename)

This is not so bad. The real problem is that I have to modify the
original IMyCompoment component to tell zope it implements IImportExport
even when this is false. The adapter does it, not the compoment. But I
don't know other way to make my view work with my components.

I hope I made myself clear. Best regards.

Lorenzo

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


[Zope3-Users] keeping GET data in a formlib based form

2007-03-14 Thread Lorenzo Gil Sanchez
Hi everybody,

I have a formlib based form. It is not accesible from an application
menu because it is part of a wizard like process.

The first time it gets called the url looks something like this:

http://localhost:8080/myapp/mycontent/myform?myarg=23

So in the update() method of the form I read the myarg argument from the
request and use it to setup some widgets in a particular way.

The problem is that when the action buttons of the form are clicked, and
the form is reloaded, the 'myarg' argument is lost and I run into
problems.

I need a way to keep 'myarg' information in my form for subsequent
calls. Ideally I would like some mechanism that ends writing an input
type=hidden id=myarg value=23/ tag in the html because that way
my code:

def update(self):
  [..]
  data = self.request['myarg']
  [..]

will still work, right?

I have thought about extending the formlib template to just do that or
maybe adding a form.Field to my form with a special Widget associated to
it. No idea of what's the best aproach.

Anyone has pointer for this?

thanks

Lorenzo Gil

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


Re: [Zope3-Users] IAdding behaviour changed from 3.2 to 3.3

2006-10-30 Thread Lorenzo Gil Sanchez
Thanks a lot, Stephan. Removing the 'menu' and 'title' attributes of the
page directive solved my problem!!

Best regards

Lorenzo

El lun, 30-10-2006 a las 13:07 -0400, Stephan Richter escribió:
 On Saturday 14 October 2006 06:50, Lorenzo Gil Sanchez wrote:
  Hi,
 
  I'm having problems with my Add Forms views (based in
  formlib.form.AddForm) in my transition from Zope 3.2 to Zope 3.3.
 
  In Zope 3.2 I registered my views like this:
 
  page
for=zope.app.container.interfaces.IAdding
name=addPerson.html
class=.person.AddForm
permission=zope.Public
menu=zmi_views
title=Add Person
/
 
 Well, the menu entry should not really be here; also adding it to zmi_views 
 is 
 wrong. You want to use the addMenuItem directive. However, this does not 
 explain that the menu item is showing up in the IPerson tabs.
 
  1. If I don't add the directive containerViews to my container I get a
  NotFound exception when going to '/mycontainer/+/addPerson.html'. To fix
  this problem I have added this directive:
 
view
name=+
for=myapp.interfaces.IMyContainer
class=zope.app.container.browser.adding.Adding
permission=zope.ManageContent
/
 
 You should not need this, if you specify the add attribute in the 
 containerViews directive:
 
   browser:containerViews
   for=zope.app.folder.interfaces.IFolder
   contents=zope.ManageContent
   index=zope.View
   add=zope.ManageContent
   /
 
  2. When my add form is displayed in the Rotterdam skin I get an extra tab
  for every other contenttype I have a page registered like the example
  above. For example, I also have a Product content type and it has an
  AddForm like the Person AddForm. When I'm looking at
  '/mycontainer/+/addPerson.html' I got 4 tabs:
 
- Add (the one for adding the person)
- Add Product
- Introspection
- Registration
 
 All that makes sense, since you are in the adding view and you registered a 
 zmi_views entry for IAdding. Just remove it, as I suggested above.
 
 Regards,
 Stephan

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


[Zope3-Users] IAdding behaviour changed from 3.2 to 3.3

2006-10-14 Thread Lorenzo Gil Sanchez
Hi,

I'm having problems with my Add Forms views (based in
formlib.form.AddForm) in my transition from Zope 3.2 to Zope 3.3.

In Zope 3.2 I registered my views like this:

page
  for=zope.app.container.interfaces.IAdding
  name=addPerson.html
  class=.person.AddForm
  permission=zope.Public
  menu=zmi_views
  title=Add Person
  /

And my container implemented the marker interface 
zope.app.container.interfaces.IContentContainer.
The default view for my container has an 'Add' button with an action that just 
redirect
to '+/addPerson.html'

Everything worked fine with this model.

Now, in Zope 3.3 I have two problems:

1. If I don't add the directive containerViews to my container I get a 
NotFound exception when 
   going to '/mycontainer/+/addPerson.html'. To fix this problem I have added 
this directive:

  view
  name=+
  for=myapp.interfaces.IMyContainer
  class=zope.app.container.browser.adding.Adding
  permission=zope.ManageContent
  /

2. When my add form is displayed in the Rotterdam skin I get an extra tab for 
every other contenttype
I have a page registered like the example above. For example, I also have a 
Product content type and it
has an AddForm like the Person AddForm. When I'm looking at 
'/mycontainer/+/addPerson.html' I got 4 tabs:

  - Add (the one for adding the person)
  - Add Product
  - Introspection
  - Registration

And obviously I shouldn't get the second tab. Looks like it is showing 
everything that is registered for the
IAdding interface, and that sound logical but my question is: Why it didn't 
work that way in Zope 3.2? and,
How do I get my expected behavior?

Best regards,

Lorenzo Gil


Extra thoughts: Probably the cause of my problems is that I don't fully 
understand the adding process
in Zope 3 so I'll try to explain what I think it is happening just in case 
anyone can correct me if I'm wrong:

When traversing '/mycontainer/+/addPerson.html' Zope gets to the '+' path and 
it gets a view for the
IMyContainer interface. This view is handled by the 
zope.app.container.browser.adding.Adding class that
implements the zope.app.container.interfaces.IAdding interface. Then, traversal 
continues to 'addPerson.html'
and Zope gets my view that is registered for IAdding. So I got a view for a 
(previous) view object that is
applied to my container. That's why in my AddForm self.context is the Adding 
object and self.context.context
is my container object.

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


[Zope3-Users] Virtual hosting problem

2006-08-30 Thread Lorenzo Gil Sanchez
Hi,

I know Zope3 has great support for virtual hosting and you can easily
set it up using the Rewrite module of Apache as described here:

http://www.zope.org/Wikis/DevSite/Projects/ComponentArchitecture/Zope3Book/virtualhosting.html

My problem is that my hosting provider does not allow me to create
custom rewrite rules so I need to do the same in Zope3 side.

Basically I want to change all request with the form
http://www.mysite.com/$1 to http://localhost:8080/site_folder/++vh
++http:www.mysite.com:80/++$1

I guess I need to slightly change Zope publishing mechanism and I saw
IVirtualHostRoot in zope.publisher.interfaces.http. Probably calling
setVirtualHostRoot when the traversal is at 'site_folder' is what I need
but I have no clue about where should I do that.

Any help?

Thanks in advance

Lorenzo

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


Re: [Zope3-Users] Re: how to know if a principal has the right permissions

2006-08-28 Thread Lorenzo Gil Sanchez
El lun, 28-08-2006 a las 20:49 +0200, Philipp von Weitershausen
escribió:
 Lorenzo Gil Sanchez wrote:
  Right. Because you're not supposed to poke at __data. The two
  underscores should scare you off!
 
  By the way, this is a rule of thumb:
 
  Whenever you get ForbiddenAttribute errors, you're doing something
  wrong. Either:
 
1. you're missing security declarations
 
2. you're accessing something that purposely has no security
   declarations because you're not supposed to access it.
 
  Most of the times when newbies hit ForbiddenAttribute, it's #1. In your
  case it's #2.
 
  If you would take advantage of interfaces and look at IContainer, you
  would see that contianers are like mappings (=dictionaries). Therefore,
  in order to add something in the container, you need to be able to
  access the __setitem__ method. Check for that and you'll be all set.
 
  Sorry, my fault: I forgot to mention that I *did try*
  zope.security.canWrite(obj, '__setitem__') before and it always returns
  False, no matter if I try with the right user.
 
 Why canWrite? You're not trying to *set* __setitem__! You should be
 checking for canAccess(container, '__setitem__'). People who want to add
 stuff to a container want to *call* container.__setitem__(...). I
 suggest you read up on the Python mapping API.
 

Oh! that was a stupid error indeed :(

Using canAccess now just does the opposite: it always returns True. I
guess that's because when I register my container in the ZCML file I'm
using zope.Public for the whole interface. I should split my interface
in two interfaces, one for read-only attributes and one for write
attributes, like the IContainer does.

So instead of inheriting my INewsFolder interface from IContainer I
inherit from IReadContainer and I explicit say in the configure.zcml
that it also implements IWriteContainer. That way I can specify
different permission for read and write attributes.

Thanks a lot for your answers Philipp

Lorenzo

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


[Zope3-Users] how to know if a principal has the right permissions

2006-08-27 Thread Lorenzo Gil Sanchez
Hello,

I have a INewsItem content type that anonynmous users can see but only
editors can create/edit/remove. I have a view which list all my news
items. I want to show links from this view to the add, edit and remove
views for every news item but only if the principal is an editor.

So, from my ListNewsView class I want to make a method called 'canEdit'
and in the ZPT for that view I can write something like:

 a  href=./edit.html tal:condition=view/canEditChange news .../a

The question is: how do I know if the current principal has permission
for a specific view? Something like:

def canEdit(self):
   ppal = self.request.principal
   return canView('edit', INewsItem, ppal)

Thanks in advance

Lorenzo Gil

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


[Zope3-Users] adding indexes in a __init__ method

2006-07-25 Thread Lorenzo Gil Sanchez
Hi,

I have a special Folder content. When an instance of this class is
created I want to create a catalog and an index in its __init__ method.
Something like:

class FilterableContainer(BTreeContainer):

implements(IFilterableContainer)

def __init__(self):
super(FilterableContainer, self).__init__()
self._catalog = LocalCatalog()
self._catalog['attr1'] = FieldIndex(field_name='attr1')

where LocalCatalog is a subclass of Catalog that only indexes objects
that belong to its parent.

The problem arises when I add my FieldIndex to my internal catalog. Some
events are triggered and at the end I got this exception:

  File /opt/Zope-3.2.1/lib/python/zope/app/keyreference/persistent.py,
line 41, in __init__
raise zope.app.keyreference.interfaces.NotYet(object)
NotYet: zope.app.catalog.field.FieldIndex object at 0x2aaab3609b90


It happens because the key reference adaptor to Persistent thinks my
FieldIndex object is already stored in the database, which is not the
case.

Anybody knows how should I add an index to my catalog in the __init__
method?

Thanks in advance

Lorenzo

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


Re: [Zope3-Users] adding indexes in a __init__ method

2006-07-25 Thread Lorenzo Gil Sanchez
Hi Darryl,

this is how I ended implementing it:


class FilterableContainer(BTreeContainer):

implements(IFilterableContainer)

def __init__(self, catalog=None):
super(FilterableContainer, self).__init__()
self.catalog = contained(LocalCatalog(), self, 'catalog')

def createIndexes(self):
self.catalog['attr1'] = FieldIndex('attr1')
self.catalog['attr2'] = FieldIndex('attr2')


def onFilterableContainerAdded(obj, event):
if IFilterableContainer.providedBy(obj):
obj.createIndexes()


Thanks a lot for your help and suggestions!

Lorenzo

El mar, 25-07-2006 a las 22:38 +1200, Darryl Cousins escribió:
 Hi Lorenzo,
 
 I got this test to work::
 
  class TestField(Persistent):
 ... pass
 
  class TestCase(Persistent):
 ... def __init__(self):
 ... self.fieldkey = KeyReferenceToPersistent(TestField())
 
  t = TestCase()
 Traceback (most recent call last):
 ...
 NotYet:...
 
  class TestCaseTwo(Persistent):
 ... def __init__(self):
 ... self.field = TestField()
 ... def initfield(self):
 ... self.fieldkey = KeyReferenceToPersistent(self.field)
 ... del(self.field)
 
  t = TestCaseTwo()
  tc = root['t'] = t
 
  transaction.commit()
  tc.initfield()
  print tc.field
 Traceback (most recent call last):
 ...
 AttributeError:...
 
 (Set up for test is shown in 
 
 Which would mean that if you created the FieldIndex in __init__ and the
 catalog[key] part in the initialization handler then it should work.
 
 I put the del(self.field) bit in as a test in case you don't want that
 attribute unecessarily hanging around.
 
 Hope **that** helps.
 
 Regards,
 Darryl
 
 On Tue, 2006-07-25 at 12:24 +0200, Lorenzo Gil Sanchez wrote:
  No worries, in fact I actually tried the same aproach and hit the same
  problem
  
  Thanks anyway
  
  Lorenzo
  
  El mar, 25-07-2006 a las 22:16 +1200, Darryl Cousins escribió:
   Hi again,
   
   I was a too hasty. Because it is the FieldIndex that is missing the
   _p_oid attribute, and the fix I offered is for the container. Sorry
   about that.
   
   I need more thinking.
   
   Regards,
   Darryl
   
   
   On Tue, 2006-07-25 at 22:10 +1200, Darryl Cousins wrote:
Hi Lorenzo,

The key reference adapter can only get a key reference **after** the
object is added to the database (because it uses _p_oid).

The problem could be fixed with a subscriber to IObjectAddedEvent::

  def FilterableContainerInitializationHandler(object, event):
  Initialize container after its ObjectAddedEvent.

# I have checks here too (maybe unecessary)
if not IObjectAddedEvent.providedBy(event):
return
if not IFilterableContainer.providedBy(object):
return
# whatever needs to be done
# self._catalog ...

This handler is configured::

  !-- initialization handler --
  subscriber
for=.IFilterableContainer
 zope.app.container.interfaces.IObjectAddedEvent
handler=.subscribers.FilterableContainerInitializationHandler
/

Hope that helps.

Best regards,
Darryl

On Tue, 2006-07-25 at 11:26 +0200, Lorenzo Gil Sanchez wrote:
 Hi,
 
 I have a special Folder content. When an instance of this class is
 created I want to create a catalog and an index in its __init__ 
 method.
 Something like:
 
 class FilterableContainer(BTreeContainer):
 
 implements(IFilterableContainer)
 
 def __init__(self):
 super(FilterableContainer, self).__init__()
 self._catalog = LocalCatalog()
 self._catalog['attr1'] = FieldIndex(field_name='attr1')
 
 where LocalCatalog is a subclass of Catalog that only indexes objects
 that belong to its parent.
 
 The problem arises when I add my FieldIndex to my internal catalog. 
 Some
 events are triggered and at the end I got this exception:
 
   File 
 /opt/Zope-3.2.1/lib/python/zope/app/keyreference/persistent.py,
 line 41, in __init__
 raise zope.app.keyreference.interfaces.NotYet(object)
 NotYet: zope.app.catalog.field.FieldIndex object at 0x2aaab3609b90
 
 
 It happens because the key reference adaptor to Persistent thinks my
 FieldIndex object is already stored in the database, which is not the
 case.
 
 Anybody knows how should I add an index to my catalog in the __init__
 method?
 
 Thanks in advance
 
 Lorenzo
 
 ___
 Zope3-users mailing list
 Zope3-users@zope.org
 http://mail.zope.org/mailman/listinfo/zope3-users

___
Zope3-users mailing list
Zope3-users@zope.org
http

Re: [Zope3-Users] adding indexes in a __init__ method

2006-07-25 Thread Lorenzo Gil Sanchez
Hi Darryl

El mié, 26-07-2006 a las 00:48 +1200, Darryl Cousins escribió:
 Hi Lorenzo,
 
 Cool. Where is the `contained` imported from? There is some magic there
 because I couldn't get the test to work when creating the FieldIndex in
 your createIndexes method without it.

from zope.app.container.contained import contained

Regards

Lorenzo

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


Re: [Zope3-Users] searching and relations

2006-07-22 Thread Lorenzo Gil Sanchez
El vie, 21-07-2006 a las 10:21 -0400, Pete Taylor escribió:
 Lorenzo,
 I've run into a very (very!) similar situation, and ended up writing
 some wrapper/simplification utilities for zc.relationship.
 zc.relationship is wonderfully powerful, but a bit complex.  It's use
 is intuitive once you wade through the 2000+ lines of documentation
 (which is worthwhile reading), but it's a bit intimidating at first.

Ok, I was afraid of an answer like this because in a recent thread I've
read Jim Fulton saying that we are trying to use zodb as a relational
database which is a shame and I think I agree with that quote.

So that's why I tried not to use external packages like zc.relationship
and stick to a plain object model with intrinsic relations modeled as
simple object attributes. The obvious question is: does this allow
powerful queries like the ones I mentioned in my first email or I should
switch and use extrinsic relations for this kind of features?

 
 I've packaged up my wrapper utilities as a product, and ZPL2.1'd the
 code.  If you'd like it, even just for reference, let me know.  I
 intend to release it more publicly shortly.

Sure! I'm 120% interested in reading your solution since reinventing the
wheel is something I always try to avoid. Thanks a lot for you kindly
offer!

Lorenzo

   It implements nice
 adapters, so objects implementing a particular marker interface can do
 things like:
 
 client = MyClient()
 q = IQuestion(obj)
 orders = q.ask_as_subject(owns)
 orders
 ['some.Order object at...']
 
 you can also build filter functions that take the relationship you're
 targeting as an argument, and check any property of the relationship
 in question...
 
 let me know if you'd like a copy.  if not, then i'd suggest going
 through at least the containers.txt in zc.relationship.
 
 as far as the catalog goes, i'd get into using hurry.query as fast as
 possible ;)
 
 On 7/21/06, Lorenzo Gil Sanchez [EMAIL PROTECTED] wrote:
  Hi,
 
  I've been following recent discussion about relations in Zope. Both
  intrinsic and extrinsic relationships.
 
  For the following question lets assume we have a IClient and an IOrder
  content types and the IOrder schema has a IClient attribute called 'client'.
 
  Reading previous messages to this list I understand that's the best way
  to model this kind of intrinsic relationship between an Order and a Client.
 
  Now the question: using a Catalog, what should I do to answer these kind
  of questions:
 
- Give me all orders whose client's name starts with 'John'
 
- Give me all orders whose client's age is between 20 and 30
 
- Give me all orders for a certain client
 
  I guess I need to use a special kind of FieldIndex for objects but I'm
  new to the Catalog land and I'm pretty much lost.
 
  Any help, examples or pointers to detailed doc are greatly appreciated :-)
 
  Best regards,
 
  Lorenzo Gil
  ___
  Zope3-users mailing list
  Zope3-users@zope.org
  http://mail.zope.org/mailman/listinfo/zope3-users
 
 
 

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


[Zope3-Users] searching and relations

2006-07-21 Thread Lorenzo Gil Sanchez

Hi,

I've been following recent discussion about relations in Zope. Both 
intrinsic and extrinsic relationships.


For the following question lets assume we have a IClient and an IOrder 
content types and the IOrder schema has a IClient attribute called 'client'.


Reading previous messages to this list I understand that's the best way 
to model this kind of intrinsic relationship between an Order and a Client.


Now the question: using a Catalog, what should I do to answer these kind 
of questions:


 - Give me all orders whose client's name starts with 'John'

 - Give me all orders whose client's age is between 20 and 30

 - Give me all orders for a certain client

I guess I need to use a special kind of FieldIndex for objects but I'm 
new to the Catalog land and I'm pretty much lost.


Any help, examples or pointers to detailed doc are greatly appreciated :-)

Best regards,

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


Re: [Zope3-Users] Re: formlib, action decorators and inheritance

2006-07-17 Thread Lorenzo Gil Sanchez

Hi Jürgen,

I did what you say and it's a little bit better.

Thanks

Lorenzo

Jürgen Kartnaller wrote:

Hi Lorenzo.

Lorenzo Gil Sanchez wrote:

Hi,

I have an add form which a subclass of form.AddForm. It just adds a 
'cancel' action.


This is my code:

class AddView(form.AddForm):

Try this here :
  actions = form.AddForm.actions


form_fields = form.Fields(IDocument).omit('__name__')

def create(self, data):
return Document(**data)

def nextURL(self):
url = zapi.absoluteURL(self.context.context, self.request)
return url

@form.action(u'Cancel', validator=always_good)
def handle_cancel(self, action, data):
self.request.response.redirect(self.nextURL())

When I define the 'cancel' action using the @form.action decorator it 
seems that the 'add' action is lost. That action is defined in my 
super class.


As a workaround I do the following:

def handle_cancel(self, action, data):
self.request.response.redirect(self.nextURL())

actions = form.AddForm.actions + form.Actions(
form.Action(u'Cancel',
success='handle_cancel', validator=always_good),
)

but I'm not sure if I'm missing something since my workaround is 
uglier than the decorator solution.


Best regards,

Lorenzo Gil


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



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


[Zope3-Users] license of z3c.multiform

2006-07-14 Thread Lorenzo Gil Sanchez

Hi everybody,

in my quest of looking for a Master/Slave forms solution (as I talked in 
a previous message) I have found the z3c.multiform[1] package in the 
Zope subversion repository[2]


I think it's pretty close to what I'm trying to do so I was very happy 
to find it. My next (inmediate) question was: what license does this 
nice piece of code have? But I couldn't find a LICENSE or COPYING file 
inside that directory.


Do all the code in svn.zope.org has the same license (the zope license) 
? If not, what license has this z3c.multiform package?


Sorry if this is a dumb question but I tried to find de answer before :-(

Best regards,

Lorenzo Gil


[1] http://svn.zope.org/z3c.multiform/Sandbox/src/z3c/multiform/

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


Re: [Zope3-Users] license of z3c.multiform

2006-07-14 Thread Lorenzo Gil Sanchez

Bernd Dorn wrote:


On 14.07.2006, at 10:01, Lorenzo Gil Sanchez wrote:


Hi everybody,

in my quest of looking for a Master/Slave forms solution (as I talked 
in a previous message) I have found the z3c.multiform[1] package in 
the Zope subversion repository[2]


I think it's pretty close to what I'm trying to do so I was very happy 
to find it. My next (inmediate) question was: what license does this 
nice piece of code have? But I couldn't find a LICENSE or COPYING file 
inside that directory.


Do all the code in svn.zope.org has the same license (the zope 
license) ? If not, what license has this z3c.multiform package?


Sorry if this is a dumb question but I tried to find de answer before :-(

Best regards,

Lorenzo Gil



Hi Lorenzo

It is under ZPL, i added a license header in __init__.py

Be aware that the api may change, that's the reason why the folder is 
called Sandbox.




No problem about that. I'm still in the research phase of my project.

Thanks a lot for this package!!

Lorenzo


regards, Bernd



[1] http://svn.zope.org/z3c.multiform/Sandbox/src/z3c/multiform/

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




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


[Zope3-Users] Master-slave forms with formlib

2006-07-10 Thread Lorenzo Gil Sanchez

Hi,

I want to write a form using the common pattern Master-Slave where there 
are some fields related to a master object and then a subform (the 
slave) with a tabular view of the children of that objet. Something 
similar to:


Personal Information
-

Name: [___]
Age:  [___]

Friends:
+--+---+--+
| Name | Cellphone | City |
+--+---+--+
| Mary | 0 | NY   |
| Pete | 1 | LA   |
+--+---+--+

As you can see we have two content objects: Person and Friend where a 
person has two attributes (name and age) and friend has three attributes 
(name, cellphone and city).


First question:

- If I want to write a form with a master-slave sort of functionality 
how should I define my content types?:


  a) Person is a container that can contains objects of type Friend

  b) Person has a list attribute where I can add/remove objects of type 
Friend using a specific API


Second question:

- Can I write a subform with the Friends tabular view and reuse that 
form in other places, not just in the Person edit form? The minimun 
functionality this subform should have would be adding, removing and 
editing objects of type Friend. Sorting them by columns or filtering 
would be added in the future.


Any tip about how to do this using formlib would be appreciated. I have 
used it for simple content types and I like it a lot.


Thanks in advance

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


Re: [Zope3-Users] Zope 3.3.0 beta 1 released!

2006-05-08 Thread Lorenzo Gil Sanchez
Hi

El lun, 08-05-2006 a las 15:13 -0400, Stephan Richter escribió:
 Hello everyone,
 
 The Zope 3 development team is proud to announce Zope 3.3.0 beta 1.
 
Great :)

   - The 'browser:layer' directive and the 'ILayer' interface
 has been deprecated.  Registering layers has become obsolete,
 layers should be created as interfaces extending
 'IBrowserRequest'.
 
   - The 'browser:skin' directive has been deprecated.  Skins
 should be created as interfaces extending 'IBrowserRequest'
 and can be registered using a simple 'utility' directive.
 
   - The 'ISkin' interface has been renamed to 'IBrowserSkinType'.
 
Is there a small document or howto explaining how to migrate from the
old skins/layers to the new system?

Best regards

Lorenzo Gil

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


Re: [Zope3-Users] Generation's install script

2006-04-30 Thread Lorenzo Gil Sanchez
I'll answer to myself just in case anybody else will ever have the same
problem:

The problem is that I was adding the folder to the root of the ZODB and
Zope's concept of root is differente. The root object you see using the
ZMI in Zope is a folder called 'Application', which is in the real root
ZODB object. So this fixes my problem:

root = context.connection.root()
app = root['Application']
app['my_folder'] = Folder()
transaction.commit()

Hope it helps

Lorenzo

El jue, 27-04-2006 a las 09:09 +0200, Lorenzo Gil Sanchez escribió:
 Hi list,
 
 I'm trying to use zope3 generations for the first time and I managed to
 get a schema manager working that support the IInstallableSchemaManager
 interface (it is just a subclass of SchemaManager).
 
 So I have an install.py module with an evolve function and it is getting
 called at zope startup. Actually it's called only the first time as it
 should be.
 
 This is how the little script looks like:
 
 import transaction
 from zope.app.folder.folder import Folder
 
 def evolve(context):
 Install initial basic data structure for the site
 print 'Installing application'
 root = context.connection.root()
 
 root['my_folder'] = Folder()
 transaction.commit()
 
 
 The problem is that after zope is started, I go to the ZMI and I don't
 see my new folder there.
 
 The way I test this is:
 
 1. Stop zope if it was running
 2. Remove var/Data.fs and var/Data.fs.index
 3. Start zope
 
 that way my install script is called for sured since I'm running a brand
 new database every time.
 
 Anybody knows what am I doing wrong?
 
 Thanks in advance
 
 Lorenzo Gil
 
 ___
 Zope3-users mailing list
 Zope3-users@zope.org
 http://mail.zope.org/mailman/listinfo/zope3-users
 

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


Re: [Zope3-Users] problems with contains and containers

2006-03-23 Thread Lorenzo Gil Sanchez
Hi Katsutoshi,

your explanations make things much clearer. Thanks a lot for sharing
them with us!

Lorenzo

El jue, 23-03-2006 a las 17:30 +0900, [EMAIL PROTECTED] escribió:
 Hi, Lorenzo.
 
 Today, I suffered the same problem as you met.
 
 This is what I figured out.
 
 
 'containers' function add '__parent__' attribute to IMyContent
 interface, like you did to IMyContentContained interface.
 
 It means that new implementation of IMyContent has '__parent__',
 while old implementation didn't. the difference causes the error.
 Now, addform will try to render '__parent__', because IMyContent
 has it. however, the view of '__parent__' is never found. then
 the error raised.
 
 
 If you want to omit '__parent__', you have to specify that 
 using 'fields' attribute of 'addform' directive in your zcml,
 or old implementation might be better.
 
 I think that this situation lessen the value of
 'contains'/'containers' functions. I wonder if I understand
 things correctly. it might be some other way.
 
 
 Regards,
 Katsutoshi
 --
 Watanabe, Katsutoshi
 
 ___
 Zope3-users mailing list
 Zope3-users@zope.org
 http://mail.zope.org/mailman/listinfo/zope3-users
 

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


[Zope3-Users] problems with contains and containers

2006-03-21 Thread Lorenzo Gil Sanchez
Hi,

I have a custom container and a custom content type and I want to make
some simple restrictions:

- Only objects that implement IMyContent can be added to objects that
implement IMyContainer

- Only objects that implement IMyContainer can contain objects that
implement IMyContent

Looks like the typical example. I implemented it following Stephan book
instructions and it worked well. The only issue was that I was getting
the feeling that splitting the interface in two and having something
like IMyContent, IMyContentContained was a little bit ugly.

Then I read about 'contains' and 'containers' and that they allowed me
to keep the interfaces together because I could use strings as their
arguments with the path for the other interfaces. Much nicer indeed. So
here is my little demo code:

from persistent import Persistent
from zope.app.container.interfaces import IContainer, IContained
from zope.app.container.constraints import contains, containers
from zope.app.container.contained import Contained
from zope.app.container.btree import BTreeContainer
from zope.interface import implements

class IMyContent(IContained):
containers('.IMyContainer')

class IMyContainer(IContainer):
contains(IMyContent)

class MyContent(Persistent, Contained):
implements(IMyContent)

class MyContainer(BTreeContainer):
implements(IMyContainer)

And in my browser package I have defined add views for both content
types. Then I start Zope and create an instance of MyContainer in the
root folder. I go into this objects and in the right hand add menu I see
the only object I can add is MyContent. So far so good. The problem is
when I try to get to the add form of MyContent. I get this error:

2006-03-21T18:58:13 ERROR SiteError http://localhost:8080/a/@@
+/action.html
Traceback (most recent call last):
  File
/usr/local/src/Zope-3.2.0/build/lib.linux-i686-2.4/zope/publisher/publish.py, 
line 138, in publish
result = publication.callObject(request, object)
  File
/usr/local/src/Zope-3.2.0/build/lib.linux-i686-2.4/zope/app/publication/zopepublication.py,
 line 161, in callObject
return mapply(ob, request.getPositionalArguments(), request)
  File
/usr/local/src/Zope-3.2.0/build/lib.linux-i686-2.4/zope/publisher/publish.py, 
line 113, in mapply
return debug_call(object, args)
  File
/usr/local/src/Zope-3.2.0/build/lib.linux-i686-2.4/zope/publisher/publish.py, 
line 119, in debug_call
return object(*args)
  File
/usr/local/src/Zope-3.2.0/build/lib.linux-i686-2.4/zope/app/container/browser/adding.py,
 line 128, in action
name=view_name) is not None:
  File
/usr/local/src/Zope-3.2.0/build/lib.linux-i686-2.4/zope/component/__init__.py,
 line 165, in queryMultiAdapter
return sitemanager.queryMultiAdapter(objects, interface, name,
default)
  File
/usr/local/src/Zope-3.2.0/build/lib.linux-i686-2.4/zope/component/site.py, 
line 75, in queryMultiAdapter
default)
  File
/usr/local/src/Zope-3.2.0/build/lib.linux-i686-2.4/zope/interface/adapter.py, 
line 475, in queryMultiAdapter
return factory(*objects)
  File
/usr/local/src/Zope-3.2.0/build/lib.linux-i686-2.4/zope/app/form/browser/editview.py,
 line 64, in __init__
self._setUpWidgets()
  File
/usr/local/src/Zope-3.2.0/build/lib.linux-i686-2.4/zope/app/form/browser/add.py,
 line 49, in _setUpWidgets
setUpWidgets(self, self.schema, IInputWidget, names=self.fieldNames)
  File /home/lgs/zope/Zope-3.2/lib/python/zope/app/form/utility.py,
line 153, in setUpWidgets
context=context)
  File /home/lgs/zope/Zope-3.2/lib/python/zope/app/form/utility.py,
line 97, in setUpWidget
widget = _createWidget(context, field, viewType, view.request)
  File /home/lgs/zope/Zope-3.2/lib/python/zope/app/form/utility.py,
line 65, in _createWidget
return zapi.getMultiAdapter((field, request), viewType)
  File
/usr/local/src/Zope-3.2.0/build/lib.linux-i686-2.4/zope/component/__init__.py,
 line 154, in getMultiAdapter
raise ComponentLookupError(objects, interface, name)
ComponentLookupError: ((zope.schema._bootstrapfields.Field object at
0xb52e44ec, zope.publisher.browser.BrowserRequest instance
URL=http://localhost:8080/a/@@+/action.html), InterfaceClass
zope.app.form.interfaces.IInputWidget, u'')

And it didn't happen with my old code with splitted interfaces.

Any idea?

thanks in advance

Lorenzo Gil

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


Re: [Zope3-Users] problems with contains and containers

2006-03-21 Thread Lorenzo Gil Sanchez
Just for the record, the following implementation works:

from persistent import Persistent
from zope.schema import Field
from zope.app.container.interfaces import IContainer, IContained
from zope.app.container.constraints import contains, containers
from zope.app.container.contained import Contained
from zope.app.container.btree import BTreeContainer
from zope.interface import implements, Interface
from zope.app.container.constraints import ContainerTypesConstraint
from zope.app.container.constraints import ItemTypePrecondition

class IMyContent(Interface):
pass

class IMyContainer(IContainer):
def __setitem__(name, object):
pass

__setitem__.precondition = ItemTypePrecondition(IMyContent)

class IMyContentContained(IContained):
__parent__ = Field(
constraint = ContainerTypesConstraint(IMyContainer))

class MyContent(Persistent, Contained):
implements(IMyContent, IMyContentContained)

class MyContainer(BTreeContainer):
implements(IMyContainer)

El mar, 21-03-2006 a las 19:10 +0100, Lorenzo Gil Sanchez escribió:
 Hi,
 
 I have a custom container and a custom content type and I want to make
 some simple restrictions:
 
 - Only objects that implement IMyContent can be added to objects that
 implement IMyContainer
 
 - Only objects that implement IMyContainer can contain objects that
 implement IMyContent
 
 Looks like the typical example. I implemented it following Stephan book
 instructions and it worked well. The only issue was that I was getting
 the feeling that splitting the interface in two and having something
 like IMyContent, IMyContentContained was a little bit ugly.
 
 Then I read about 'contains' and 'containers' and that they allowed me
 to keep the interfaces together because I could use strings as their
 arguments with the path for the other interfaces. Much nicer indeed. So
 here is my little demo code:
 
 from persistent import Persistent
 from zope.app.container.interfaces import IContainer, IContained
 from zope.app.container.constraints import contains, containers
 from zope.app.container.contained import Contained
 from zope.app.container.btree import BTreeContainer
 from zope.interface import implements
 
 class IMyContent(IContained):
 containers('.IMyContainer')
 
 class IMyContainer(IContainer):
 contains(IMyContent)
 
 class MyContent(Persistent, Contained):
 implements(IMyContent)
 
 class MyContainer(BTreeContainer):
 implements(IMyContainer)
 
 And in my browser package I have defined add views for both content
 types. Then I start Zope and create an instance of MyContainer in the
 root folder. I go into this objects and in the right hand add menu I see
 the only object I can add is MyContent. So far so good. The problem is
 when I try to get to the add form of MyContent. I get this error:
 
 2006-03-21T18:58:13 ERROR SiteError http://localhost:8080/a/@@
 +/action.html
 Traceback (most recent call last):
   File
 /usr/local/src/Zope-3.2.0/build/lib.linux-i686-2.4/zope/publisher/publish.py,
  line 138, in publish
 result = publication.callObject(request, object)
   File
 /usr/local/src/Zope-3.2.0/build/lib.linux-i686-2.4/zope/app/publication/zopepublication.py,
  line 161, in callObject
 return mapply(ob, request.getPositionalArguments(), request)
   File
 /usr/local/src/Zope-3.2.0/build/lib.linux-i686-2.4/zope/publisher/publish.py,
  line 113, in mapply
 return debug_call(object, args)
   File
 /usr/local/src/Zope-3.2.0/build/lib.linux-i686-2.4/zope/publisher/publish.py,
  line 119, in debug_call
 return object(*args)
   File
 /usr/local/src/Zope-3.2.0/build/lib.linux-i686-2.4/zope/app/container/browser/adding.py,
  line 128, in action
 name=view_name) is not None:
   File
 /usr/local/src/Zope-3.2.0/build/lib.linux-i686-2.4/zope/component/__init__.py,
  line 165, in queryMultiAdapter
 return sitemanager.queryMultiAdapter(objects, interface, name,
 default)
   File
 /usr/local/src/Zope-3.2.0/build/lib.linux-i686-2.4/zope/component/site.py, 
 line 75, in queryMultiAdapter
 default)
   File
 /usr/local/src/Zope-3.2.0/build/lib.linux-i686-2.4/zope/interface/adapter.py,
  line 475, in queryMultiAdapter
 return factory(*objects)
   File
 /usr/local/src/Zope-3.2.0/build/lib.linux-i686-2.4/zope/app/form/browser/editview.py,
  line 64, in __init__
 self._setUpWidgets()
   File
 /usr/local/src/Zope-3.2.0/build/lib.linux-i686-2.4/zope/app/form/browser/add.py,
  line 49, in _setUpWidgets
 setUpWidgets(self, self.schema, IInputWidget, names=self.fieldNames)
   File /home/lgs/zope/Zope-3.2/lib/python/zope/app/form/utility.py,
 line 153, in setUpWidgets
 context=context)
   File /home/lgs/zope/Zope-3.2/lib/python/zope/app/form/utility.py,
 line 97, in setUpWidget
 widget = _createWidget(context, field, viewType, view.request)
   File /home/lgs/zope/Zope-3.2/lib/python/zope/app/form/utility.py,
 line 65, in _createWidget
 return zapi.getMultiAdapter((field, request), viewType)
   File

Re: [Zope3-Users] Re: how to make static pages

2006-03-16 Thread Lorenzo Gil Sanchez
El vie, 17-03-2006 a las 06:11 +1100, Tom Dossis escribió:
 Lorenzo Gil Sanchez wrote:
  Hi,
  
  I'd like to ask what's the best way to create static html pages inside
  my application. For example, the intro page, a help page or a legal
  conditions page.
  
  I have a skin inside a browser package but if I understand them
  correctly the provide views for content objects.
 
 
  Do I need to create a
  content object for the each of my static pages?
 
 No, unless you want the static page(s) to show up in results from a
 catalog (text) search, then Yes.

Oh, that's a good point. I also want my static pages to show up in a
regular breadcrumbs section so I guess I will make them content objects

Thanks for the answers

Lorenzo

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


[Zope3-Users] skin concepts

2006-03-16 Thread Lorenzo Gil Sanchez
Hi all,

When trying to make my own skin I run into some problems. I have read
Stephan chapter of his book about creating a skin and it is quite useful
but still too simple for my needs.

I want to understand some concepts involved in skin development and I
haven't found any resource to read about this. I noticed that there is
no skin package inside the Zope codebase and so I couldn't find any
README.txt file as in other packages.

So here are my questions:

- What is the default view that is applied to a content object? If I
have something like this in my configure.zml:

  page
  for=mypackage.mycontenttype
  name=index.html
  permission=zope.View
  layer=mylayer
  template=index.pt/

 how do I make it the default view for objects of mycontenttype?

 Related question: what is the default view for the root object in a
zope instance? I have seen how to configure the default skin in a
configuration file inside /etc but I don't know how Zope knows what view
to apply if none is provide explicitly in the URL

- What are the dialog_macros, view_macros, skin_macros and friends? I
know that they are ZPT macros but how are they related? Which one is
taken in each view? where is this wired? I've seen the basicskin package
of the Zope codebase and the file standardmacros.py but I don't
understand how it works.

- In my template.pt file I have defined a macro called 'page' and I just
noticed that changing it to another name makes my template not being
called. So I assume someone is doing something like metal
use-macro=page but I'm too curious to trust magic: I want to know how
the internals of this mechanism work :)

If anyone knows some pointers I can read to answer these questions I
would be very grateful.

Thanks a lot

Lorenzo Gil

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


[Zope3-Users] breadcumbs in new skin

2006-02-13 Thread Lorenzo Gil Sanchez

Hi,

I'm working on a new skin and I want to use the breadcumbs functionality 
  in it. I have just one layer and the skin is defined like this:


  layer name=mylayer /

  skin name=myskin layers=mylayer rotterdam default /

Inside my template.pt I have tried to use the macro breadcumbs without luck:

span metal:use-macro=breadcrumbs /

This macro is defined in the template.pt file of the Rotterdam skin but 
I don't know how to use it.


Best Regards

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


Re: [Zope3-Users] updating objects in ZODB

2006-02-10 Thread Lorenzo Gil Sanchez

Thierry FLORAC wrote:

On Fri, 2006-02-10 at 11:15 +0100, Lorenzo Gil Sanchez wrote:
How do I update the old objects and add the new attribute to them? I can 
provide a default value for this attribute if that helps.
I know this is a common issue with application updates. I also know that 
during the development phase the best thing I can do is remove the 
Data.fs file and start again and that's what I'm currently doing. But 
I'm worried about installing the application in the client machines and 
two month later needing to add more fields to my content-types. If I 
understand correctly one of the advantages of Zope3 is the support for 
always-changing-applications. So how does it work in this particular 
situation?


I think that Zope3 handles this problem through the concept of 
generations.
Documentation and interfaces are available in package 
zope.app.generations.




Thanks for the pointer, that was exactly what I was looking for


  Thierry



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


Re: [Zope3-Users] Trying to use browser:form - 404

2006-02-10 Thread Lorenzo Gil Sanchez
El vie, 10-02-2006 a las 22:18 +0100, Florian Lindner escribió:
 Am Freitag, 10. Februar 2006 20:10 schrieb Garanin Michael:

 And I try to call it with:
 
 /++skin++centershock/cs/registerForm.html whereas cs is a ICentershock object.
 
 It still gives a 404.
 
 Any guess what's wrong?
 

Stupid question: isn't '@@' a prefix for the views? Like:

/++skin++centershock/cs/@@registerForm.html 

Just a newbie observation...

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


Re: [Zope3-Users] newbie problems with new content-type

2006-02-09 Thread Lorenzo Gil Sanchez

[EMAIL PROTECTED] wrote:


'test' command searches only packages under instance_lib.
and instance_lib is 'c:\path\to\your\instance\lib\python'



Ok, that's my problem. My package was outside the instance lib 
directory. I think I have read in the Zope Developers Book that you 
could put your application anywhere in your harddisk as long as 
PYTHONPATH includes it.


Now, the tests are found.

Thanks a lot Katsutoshi

Cheers

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


[Zope3-Users] default values in Choice fields

2006-02-09 Thread Lorenzo Gil Sanchez

Hi

I have a field in my schema like this:

fruit = Choice(title=u'Fruit',
   description=u'An example choice field',
   default=None,
   required=True,
   values=('Apple', 'Orange', 'Banana', 'Strawberry'))

I want to specify a default value for this field but I want it to be 
from the list of values.


Is there a preferred way to do it or just do something like this:

fruit_values = ('Apple', 'Orange', 'Banana', 'Strawberry')

fruit = Choice(title=u'Fruit',
   description=u'An example choice field',
   default=fruit_values[0],
   required=True,
   values=fruit_values)

In the implementation of my content type, do I have to write 'Apple' for 
the default value again or there is another way? I want to avoid 
duplicating hardwired names.


Sorry if this is a dumb question

Thanks in advance

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


Re: [Zope3-Users] newbie problems with new content-type

2006-02-08 Thread Lorenzo Gil Sanchez

Chris Withers wrote:

Lorenzo Gil Sanchez wrote:

c:\path\to\my\instance\bin\test -vpu --dir z:\my_root_app_dir
[ traceback ]
ImportError: No module named z:.my_root_app_dir


Is my_root_app_dir on your PYTHON_PATH?


Yes it is


also, do you have __init__.py files in \tests?


Yes I do



If you have, you should be able to do:

c:\path\to\my\instance\bin\test -vpu tests



c:\zope\development\bin\test -vpu tests
Running tests at level 1
Total: 0 tests, 0 failures, 0 errors

No tests are found :(

Thanks anyway

Lorenzo

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


[Zope3-Users] newbie problems with new content-type

2006-02-06 Thread Lorenzo Gil Sanchez

Hi,

I'm trying to get my first content-type working and I have some 
problems. For the record, I'm following Stephan great book and I'm 
running Zope 3.2.0 on Windows.


My content-type represents a Provider and is quite simple. The first 
problem I have is when I try to run the tests with the following code:


c:\path\to\my\instance\bin\test -vpu --dir z:\my_root_app_dir
[ traceback ]
ImportError: No module named z:.my_root_app_dir

So I go to the z:\ dir and try another form:

c:\path\to\my\instance\bin\test -vpu --dir my_root_app_dir
Running tests at level 1
Total: 0 tests, 0 failures, 0 errors


So no tests found. But when I run this command:

Z:\c:\python24\python my_root_app_dir\tests\test_provider.py
.
--
Ran 1 test in 0.010s

OK

It *runs* 1 test. What am I doing wrong?

Second question: When I register my content-type in Zope using a 
configure.zcml in the root directory and a browser package with its own 
configure.zcml everything seems to work fine. I can see an entry in the 
Add menu for my content type.


When I click on that entry I see a nice autogenerated form for the 
Provider. I fill some fields and click the Add button and then I get a 
security exception:


ForbiddenAttribute: ('name', my_root_app_dir.provider.Provider object 
at 0x034A2730)


I'm logging in as the only principal in my zope instance which is the 
one created with the mkzopeinstance script. In the configure.zcml file 
of the browser subpackage I have this code:


  addform
  label=Add Provider
  name=AddProvider.html
  schema=my_root_app_dir.interfaces.IProvider
  content_factory=my_root_app_dir.provider.Provider
  fields=name phone address email
  permission=zope.ManageContent
  /

Any help is greatly appreciated.

Thanks

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


Re: [Zope3-Users] newbie problems with new content-type

2006-02-06 Thread Lorenzo Gil Sanchez

Christoph Frick wrote:

On Mon, Feb 06, 2006 at 06:48:30PM +0100, Lorenzo Gil Sanchez wrote:


c:\path\to\my\instance\bin\test -vpu --dir z:\my_root_app_dir
[ traceback ]
ImportError: No module named z:.my_root_app_dir


dunnonothing about windows - but either the test-environment can not
handle the leading letter: or a relative path is expected.


Yeah, that's what I though so I try executing it with relative paths as 
you can see from my second try (in the original message).




ForbiddenAttribute: ('name', my_root_app_dir.provider.Provider object 
at 0x034A2730)


  addform
  label=Add Provider
  name=AddProvider.html
  schema=my_root_app_dir.interfaces.IProvider
  content_factory=my_root_app_dir.provider.Provider
  fields=name phone address email
  permission=zope.ManageContent
  /


is it possible you forgot to provide permissions for setting the schema?

content class=.provider.Provider
implements
interface=zope.app.annotation.IAttributeAnnotatable /
require permission=zope.View
			interface=.interface.IProvider 
		/

require permission=zope.ManageContent
set_schema=.interfaces.IProvider
/
/content

where interface.IProvider should have an attribute ``name''.



Thanks a lot Christoph. That was exactly my problem. It's great to have 
so fast feedback.


Lorenzo






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


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