Re: [Zope-dev] Python Product as DataSkin

2001-02-21 Thread Michael R. Bernstein

Steve Alexander wrote:
 
 Michael R. Bernstein wrote:
  
   File /home/webmaven/Products/ZPatterns/DataSkins.py, line 208, in
   __set_attr__ (Object: ElementWithAttributes) KeyError: (see above)
 
 What version of ZPatterns are you using?

0.4.3b2 on Zope 2.2.0

 I certainly don't have the __set_attr__ method covering line 208 in my
 version.

In my DataSkins.py, line 208 is the one marked below:

  def __set_attr__(self,name,val,_v_dm_=_v_dm_):
  try:
 208   dm = self.__dict__[_v_dm_]
  except KeyError:
  if name=='id' and val==self.__dict__['id']: return
  raise
 
 If they don't, you'll get the error that you're reporting.

Well, that's the version I've got, and that is how the
__set_attr__ method reads. What do I check next?

Backtracking a bit more, line 46 in ArchiveImage.py is in
the manage_addArchiveImage method, marked below:

def manage_addArchiveImage(self, id, file, title='',
displays=None, precondition='',
   content_type='', REQUEST=None):
  """
  Add a new ArchiveImage object.
  """
   # This constructor basically ripped off from Image/File
   id, title = cookId(id, title, file)
   self=self.this()
   # First, we create the ArchiveImage without data:
46self._setObject(id,
ArchiveImage(id,title,'',displays,content_type,precondition))
   # Now we "upload" the data.  By doing this in two steps,
we
   # can use a database trick to make the upload more
efficient.
   self._getOb(id).manage_upload(file)
   if REQUEST:
   try:url=self.DestinationURL()
   except: url=REQUEST['URL1']
   REQUEST.RESPONSE.redirect('%s/manage_main' % url)
   return id

Does this help?

Thanks,

Michael Bernstein.

___
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope )



Re: [Zope-dev] Python Product as DataSkin

2001-02-20 Thread Steve Alexander

Michael R. Bernstein wrote:
 

 In Zope 2.3) it is aliased to Globals.InitializeClass.
  
 So, if I'm developing this on 2.2, I need to use
 Globals.default__class_init__(FooClass) instead of
 Globals.InitializeClass(FooClass)?

Yes. At least, using default__class_init__ will work on Zope 2.2 and 2.3.
I don't know whether InitializeClass is in Zope 2.2, but it is definitely in Zope 2.3.
  
 Use it by having
 
   import Globals
 
 somewhere in your class definition,
 
 If 'import Globals' appears at the start of the FooClass.py
 file, does it still need to appear in the class definition
 itself?

Sorry -- my imprecise language!
"import Globals" needs to be in the .py file that your
class is defined in, at the module level of indentation.
You're importing Globals so that you can use it in the 
module rather than in the Class definition.


   Globals.InitializeClass(YourClassName)
 
 at the end.
 
 
 At the end on the file, or the end of the class definition?

After the class definition, so, qiute probably at the end of the file.

--
Steve Alexander
Software Engineer
Cat-Box limited
http://www.cat-box.net


___
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope )



Re: [Zope-dev] Python Product as DataSkin

2001-02-19 Thread Steve Alexander

Michael R. Bernstein wrote:

 
  Hmm. I thought I was doing it wrong. Here is the error and traceback
  from trying to instantiate the modified Product (through the
  standard mgmt interface):
 
  This resource may be trying to reference a nonexistent object or
  variable _v_dm_

snipped

  Any ideas?

Is the __init__ method of DataSkin getting called?

This would happen if, for example, you define an __init__ method in your 
class, but you don't use something like:

from Globals import default__class_init__

default__class_init__(yourClass)

(At least, I *think* that's one of the things that default__class_init__ 
does. Otherwise, you'll need to make sure you call DataSkin.__init__ 
from your __init__ method, probably using Acquisition.inheritedAttribute.)

--
Steve Alexander
Software Engineer
Cat-Box limited
http://www.cat-box.net


___
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope )



Re: [Zope-dev] Python Product as DataSkin

2001-02-19 Thread Michael R. Bernstein

Steve Alexander wrote:
 
 Is the __init__ method of DataSkin getting called?
 
 This would happen if, for example, you define an __init__ method in your
 class, but you don't use something like:
 
 from Globals import default__class_init__
 
 default__class_init__(yourClass)
 
 (At least, I *think* that's one of the things that default__class_init__
 does. Otherwise, you'll need to make sure you call DataSkin.__init__
 from your __init__ method, probably using Acquisition.inheritedAttribute.)

This sounds like it's on the right track because I *am*
defining an __init__ method, and I don't have any code
resembling what you typed. 

Where do I put this again? Does this go in the myclass.py
file or the products __init__.py file? And where in the file
does the code in the second line get used exactly?

Sorry for being a little dense,

Michael Bernstein

___
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope )



Re: [Zope-dev] Python Product as DataSkin

2001-02-19 Thread Michael R. Bernstein

"Phillip J. Eby" wrote:
 
 At 10:47 PM 2/18/01 -0800, Michael R. Bernstein wrote:
 
 Hmm. So I need to refactor the 'manage_add' method inside
 the python product into two methods, 'manage_add' which
 would be used by the 'normal' object creation process and
 that would also call a second 'setup' method which could be
 called by the specialists 'myadd' method directly, bypassing
 the 'manage_add' method entirely.
 
 Is that correct?
 
 Pretty much

Ok, but in that case a simple dtml-call
"newItem(REQUEST.id)" should at least execute without
error, and it doesn't:

Error Type: TypeError
Error Value: not enough arguments; expected 4, got 2

Traceback (innermost last):
  File
/usr/local/Zope-2.2.0-src/lib/python/ZPublisher/Publish.py,
line 222, in publish_module
  File
/usr/local/Zope-2.2.0-src/lib/python/ZPublisher/Publish.py,
line 187, in publish
  File
/usr/local/Zope-2.2.0-src/lib/python/Zope/__init__.py, line
221, in zpublisher_exception_hook
(Object: ProviderContainer)
  File
/usr/local/Zope-2.2.0-src/lib/python/ZPublisher/Publish.py,
line 171, in publish
  File
/usr/local/Zope-2.2.0-src/lib/python/ZPublisher/mapply.py,
line 160, in mapply
(Object: addArchiveImage)
  File
/usr/local/Zope-2.2.0-src/lib/python/ZPublisher/Publish.py,
line 112, in call_object
(Object: addArchiveImage)
  File
/usr/local/Zope-2.2.0-src/lib/python/OFS/DTMLMethod.py, line
167, in __call__
(Object: addArchiveImage)
  File
/usr/local/Zope-2.2.0-src/lib/python/DocumentTemplate/DT_String.py,
line 502, in __call__
(Object: addArchiveImage)
  File
/usr/local/Zope-2.2.0-src/lib/python/DocumentTemplate/DT_Util.py,
line 337, in eval
(Object: newItem(REQUEST.id))
(Info: newItem)
  File lt;stringgt;, line 0, in ?
  File /home/webmaven/Products/ZPatterns/Specialists.py,
line 40, in newItem
(Object: ProviderContainer)
  File /home/webmaven/Products/ZPatterns/Rack.py, line 73,
in newItem
(Object: ProviderContainer)
  File /home/webmaven/Products/ZPatterns/Rack.py, line 135,
in createItem
(Object: ProviderContainer)
  File /home/webmaven/Products/ZPatterns/Rack.py, line 232,
in _RawItem
(Object: ProviderContainer)
TypeError: (see above)

What am I doing wrong?

Michael Bernstein.

___
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope )



Re: [Zope-dev] Python Product as DataSkin

2001-02-19 Thread Steve Alexander

Michael R. Bernstein wrote:

 Steve Alexander wrote:
 
 Is the __init__ method of DataSkin getting called?
 
 This would happen if, for example, you define an __init__ method in your
 class, but you don't use something like:
 
 from Globals import default__class_init__
 
 default__class_init__(yourClass)
 
 At least, I *think* that's one of the things that default__class_init__
 does.

Nope... I got confused. Globals.default__class_init__ sets up the security
attributes for you class, from whatever combination of security
declarations you've used.

In Zope 2.3) it is aliased to Globals.InitializeClass.

Use it by having

  import Globals

somewhere in your class definition, and 

  Globals.InitializeClass(YourClassName)

at the end.

See the following URL for more information:

http://www.zope.org//Wikis/DevSite/Projects/DeclarativeSecurity/ZopeSecurityForDevelopers


 Otherwise, you'll need to make sure you call DataSkin.__init__
 from your __init__ method, probably using Acquisition.inheritedAttribute.)

So, at the start of your __init__ method, call:
   NameOfYourClass.inheritedAttribute('__init__')(self, id)

Your __init__ method might look like this:

   def __init__(self, id, title):
   FooClass.inheritedAttribute('__init__')(self, id)
   # rest of your __init__ method


--
Steve Alexander
Software Engineer
Cat-Box limited
http://www.cat-box.net


___
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope )



Re: [Zope-dev] Python Product as DataSkin

2001-02-19 Thread Michael R. Bernstein

Steve Alexander wrote:
 
 Michael R. Bernstein wrote:
 
  Steve Alexander wrote:
 
  Is the __init__ method of DataSkin getting called?
 
  This would happen if, for example, you define an __init__ method in your
  class, but you don't use something like:
 
  from Globals import default__class_init__
 
  default__class_init__(yourClass)
 
  At least, I *think* that's one of the things that default__class_init__
  does.
 
 Nope... I got confused. Globals.default__class_init__ sets up the security
 attributes for you class, from whatever combination of security
 declarations you've used.
 
 In Zope 2.3) it is aliased to Globals.InitializeClass.

So, if I'm developing this on 2.2, I need to use
Globals.default__class_init__(FooClass) instead of
Globals.InitializeClass(FooClass)?

 Use it by having
 
   import Globals
 
 somewhere in your class definition,

If 'import Globals' appears at the start of the FooClass.py
file, does it still need to appear in the class definition
itself?

 and
 
   Globals.InitializeClass(YourClassName)
 
 at the end.

At the end on the file, or the end of the class definition?

Thanks for the help,

Michael Bernstein.

___
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope )



[Zope-dev] Python Product as DataSkin

2001-02-18 Thread Michael R. Bernstein

I have an existing Python Product that I would like to use
as a DataSkin in a Rack.

What do I need to change (import/subclass) in order to use
it in this way?

Thanks,

Michael Bernstein.

___
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope )



Re: [Zope-dev] Python Product as DataSkin

2001-02-18 Thread Phillip J. Eby

At 12:51 PM 2/18/01 -0800, Michael R. Bernstein wrote:
I have an existing Python Product that I would like to use
as a DataSkin in a Rack.

What do I need to change (import/subclass) in order to use
it in this way?


from ZPatterns.DataSkins import DataSkin

class MyClass(DataSkin,...all other bases...):
...


___
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope )



Re: [Zope-dev] Python Product as DataSkin

2001-02-18 Thread Michael R. Bernstein

"Phillip J. Eby" wrote:
 
 At 12:51 PM 2/18/01 -0800, Michael R. Bernstein wrote:
 I have an existing Python Product that I would like to use
 as a DataSkin in a Rack.
 
 What do I need to change (import/subclass) in order to use
 it in this way?
 
 
 from ZPatterns.DataSkins import DataSkin
 
 class MyClass(DataSkin,...all other bases...):

Hmm. I thought I was doing it wrong. Here is the error and
traceback from trying to instantiate the modified Product
(through the standard mgmt interface):

This resource may be trying to reference a
nonexistent object or variable _v_dm_

The URL may be incorrect.
The parameters passed to this resource may be incorrect.
A resource that this resource relies on may be encountering
an error.

Traceback (innermost last):
  File
/usr/local/Zope-2.2.0-src/lib/python/ZPublisher/Publish.py,
line 222, in publish_module
  File
/usr/local/Zope-2.2.0-src/lib/python/ZPublisher/Publish.py,
line 187, in publish
  File
/usr/local/Zope-2.2.0-src/lib/python/Zope/__init__.py, line
221, in zpublisher_exception_hook
  File
/usr/local/Zope-2.2.0-src/lib/python/ZPublisher/Publish.py,
line 171, in publish
  File
/usr/local/Zope-2.2.0-src/lib/python/ZPublisher/mapply.py,
line 160, in mapply
(Object: manage_addArchiveImage)
  File
/usr/local/Zope-2.2.0-src/lib/python/ZPublisher/Publish.py,
line 112, in call_object
(Object: manage_addArchiveImage)
  File /home/webmaven/Products/ArchiveImage/ArchiveImage.py,
line 46, in manage_addArchiveImage
(Object: ApplicationDefaultPermissions)
  File /home/webmaven/Products/ArchiveImage/ArchiveImage.py,
line 79, in __init__
(Object: ElementWithAttributes)
  File /home/webmaven/Products/ZPatterns/DataSkins.py, line
208, in __set_attr__
(Object: ElementWithAttributes)
KeyError: (see above)

Any ideas?

Michael Bernstein.

___
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope )



Re: [Zope-dev] Python Product as DataSkin

2001-02-18 Thread Michael R. Bernstein

"Phillip J. Eby" wrote:
 
 At 12:51 PM 2/18/01 -0800, Michael R. Bernstein wrote:
 I have an existing Python Product that I would like to use
 as a DataSkin in a Rack.
 
 What do I need to change (import/subclass) in order to use
 it in this way?
 
 
 from ZPatterns.DataSkins import DataSkin
 
 class MyClass(DataSkin,...all other bases...):

Ok, assuming that the 'normal' instantiation is either
solved or a non-issue, do I need to do anything special to
get the newItem() method to call my products manage_add
method?

The manage_add method takes an id, an optional title, and an
uploaded file.

When I try passing these to newItem(), it complains that
it's getting "too many arguments, expected 2 got 4", but
when I only pass the id, it complains that "not enough
arguments; expected 4, got 2"

As far as I can determine, the fourth/second argument that
it gets in each case is 'self'.

So what do I do next?

Michael Bernstein.

___
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope )



Re: [Zope-dev] Python Product as DataSkin

2001-02-18 Thread Phillip J. Eby

At 09:49 PM 2/18/01 -0800, Michael R. Bernstein wrote:

Ok, assuming that the 'normal' instantiation is either
solved or a non-issue, do I need to do anything special to
get the newItem() method to call my products manage_add
method?

newItem() will not do that.  A Rack's newItem() method always takes only an
'id' method.  You'll need a method on the object itself that can be given
anything else you want to give it, which you'll call from a method you
create on the specialist, e.g. a "myAdd" method that takes all four
parameters and then does something like:

newObject = self.newItem(id)
newObject.setup(extraParm1,extraParm2,...)
return newObject


___
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope )



Re: [Zope-dev] Python Product as DataSkin

2001-02-18 Thread Michael R. Bernstein

"Phillip J. Eby" wrote:
 
 At 09:49 PM 2/18/01 -0800, Michael R. Bernstein wrote:
 
 Ok, assuming that the 'normal' instantiation is either
 solved or a non-issue, do I need to do anything special to
 get the newItem() method to call my products manage_add
 method?
 
 newItem() will not do that.  A Rack's newItem() method always takes only an
 'id' method.  You'll need a method on the object itself that can be given
 anything else you want to give it, which you'll call from a method you
 create on the specialist, e.g. a "myAdd" method that takes all four
 parameters and then does something like:
 
 newObject = self.newItem(id)
 newObject.setup(extraParm1,extraParm2,...)
 return newObject

Hmm. So I need to refactor the 'manage_add' method inside
the python product into two methods, 'manage_add' which
would be used by the 'normal' object creation process and
that would also call a second 'setup' method which could be
called by the specialists 'myadd' method directly, bypassing
the 'manage_add' method entirely.

Is that correct?

Is there anything else I would need to change?

Thanks,

Michael Bernstein.

___
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope )



Re: [Zope-dev] Python Product as DataSkin

2001-02-18 Thread Phillip J. Eby

At 10:47 PM 2/18/01 -0800, Michael R. Bernstein wrote:

Hmm. So I need to refactor the 'manage_add' method inside
the python product into two methods, 'manage_add' which
would be used by the 'normal' object creation process and
that would also call a second 'setup' method which could be
called by the specialists 'myadd' method directly, bypassing
the 'manage_add' method entirely.

Is that correct?

Pretty much


Is there anything else I would need to change?

Anything that carries any assumptions about the normal Zope management
creation process.  For example, manage_afterAdd is only called when a
DataSkin is added to a Folder, not a Rack.


___
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope )



Re: [Zope-dev] Python Product as DataSkin

2001-02-18 Thread Michael R. Bernstein

Philip,

I have gone spelunking into the DataSkin class source to try
to find out why subclassing from DataSkin is interfering
with 'normal' (not in a rack) instantiation of the product,
but with no success. Any assistance you could give would be
appreciated.

BTW, I think the first line needs to read:

from Products.ZPatterns.DataSkins import DataSkin

Thanks,

Michael Bernstein.

Michael Bernstein wrote:
 
 "Phillip J. Eby" wrote:
 
  At 12:51 PM 2/18/01 -0800, Michael R. Bernstein wrote:
  
  What do I need to change (import/subclass) in order to use
  it in this way?
 
  from ZPatterns.DataSkins import DataSkin
 
  class MyClass(DataSkin,...all other bases...):
 
 Here is the error and
 traceback from trying to instantiate the modified Product
 (through the standard mgmt interface):
 
 This resource may be trying to reference a
 nonexistent object or variable _v_dm_
 
 The URL may be incorrect.
 The parameters passed to this resource may be incorrect.
 A resource that this resource relies on may be encountering
 an error.
 
 Traceback (innermost last):
   File
 /usr/local/Zope-2.2.0-src/lib/python/ZPublisher/Publish.py,
 line 222, in publish_module
   File
 /usr/local/Zope-2.2.0-src/lib/python/ZPublisher/Publish.py,
 line 187, in publish
   File
 /usr/local/Zope-2.2.0-src/lib/python/Zope/__init__.py, line
 221, in zpublisher_exception_hook
   File
 /usr/local/Zope-2.2.0-src/lib/python/ZPublisher/Publish.py,
 line 171, in publish
   File
 /usr/local/Zope-2.2.0-src/lib/python/ZPublisher/mapply.py,
 line 160, in mapply
 (Object: manage_addArchiveImage)
   File
 /usr/local/Zope-2.2.0-src/lib/python/ZPublisher/Publish.py,
 line 112, in call_object
 (Object: manage_addArchiveImage)
   File /home/webmaven/Products/ArchiveImage/ArchiveImage.py,
 line 46, in manage_addArchiveImage
 (Object: ApplicationDefaultPermissions)
   File /home/webmaven/Products/ArchiveImage/ArchiveImage.py,
 line 79, in __init__
 (Object: ElementWithAttributes)
   File /home/webmaven/Products/ZPatterns/DataSkins.py, line
 208, in __set_attr__
 (Object: ElementWithAttributes)
 KeyError: (see above)

___
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope )