Re: [Zope] __getitem__ and returning a PageTemplateFile instance
Anders Bruun Olsen wrote at 2005-10-21 15:06 +0200: > ... >Ahh.. that makes sense I guess. It just seems counterintuitive that you >can return a string in a normal function, but not in __getitem__. Can can return a string from "__getitem__" (without problem), *but* you cannot use this string during URL traversal. By the way, it does not matter for URL traversal whether the string (or other simple type object or object without docstring) was returned by "__getitem__", "getattr" or "__bobo_traverse__" (these are the possibilities to obtain the subobject during URL traversal) -- the publisher will in all cases reject it. -- Dieter ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] __getitem__ and returning a PageTemplateFile instance
Anders Bruun Olsen wrote: Ahh.. that makes sense I guess. It just seems counterintuitive that you can return a string in a normal function, but not in __getitem__. I have a feeling you're after traverse_subpath, which is available in both Python Scripts and Page Templates... cheers, Chris -- Simplistix - Content Management, Zope & Python Consulting - http://www.simplistix.co.uk ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] __getitem__ and returning a PageTemplateFile instance
On Thu, Oct 20, 2005 at 09:43:24PM +0200, Dieter Maurer wrote: > >asonhe is not there, but vitester has a __getitem__ method which > >executes a PageTemplateFile instance and returns it. I.e. > Thus, it returns a string. > However, ZPublisher requires that all intermediate traversal > steps return an object which is not of a simple type and does > have a docstring. A string is a simple type, you cannot use it > during traversal... Ahh.. that makes sense I guess. It just seems counterintuitive that you can return a string in a normal function, but not in __getitem__. > >But that way I can't put any values in there. How can I do this then? > Can can return a wrapper and give it a docstring. > class Wrapper: > '''a wrapper around a string.''' # this is the docstring > def __init__(self, str): > self.str = str > def __call__(self): return self.str > Some security declarations might be necessary as well. > Probably, a class attribute "__roles__ = None" is sufficient. Okay, that will work. Thanks so much for your help, I really appreciated it. -- Anders -BEGIN GEEK CODE BLOCK- Version: 3.12 GCS/O d--@ s:+ a-- C++ UL+++$ P++ L+++ E- W+ N(+) o K? w O-- M- V PS+ PE@ Y+ PGP+ t 5 X R+ tv+ b++ DI+++ D+ G e- h !r y? --END GEEK CODE BLOCK-- PGPKey: http://random.sks.keyserver.penguin.de:11371/pks/lookup?op=get&search=0xD4DEFED0 ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] __getitem__ and returning a PageTemplateFile instance
Anders Bruun Olsen wrote at 2005-10-20 11:52 +0200: >On Wed, Oct 19, 2005 at 09:47:50PM +0200, Dieter Maurer wrote: >> >Zope has encountered a problem publishing your object. >> >Cannot locate object at: http://localhost:8080/vitester/asonhe >> This is a "NotFound" problem. >>Zope is unable to locate "vitester/asonhe" >> Are you sure, "vitester/asonhe" is there? > >asonhe is not there, but vitester has a __getitem__ method which >executes a PageTemplateFile instance and returns it. I.e. Thus, it returns a string. However, ZPublisher requires that all intermediate traversal steps return an object which is not of a simple type and does have a docstring. A string is a simple type, you cannot use it during traversal... >return self.test(self, self.REQUEST, value=value) >(where self.test is a PageTemplateFile) This results in a string (a simple type)... >It actually works if I just do: > >return self.test.__of__(self) This results in a "PageTemplateFile", which has a docstring and is not of simple type. >But that way I can't put any values in there. How can I do this then? Can can return a wrapper and give it a docstring. class Wrapper: '''a wrapper around a string.''' # this is the docstring def __init__(self, str): self.str = str def __call__(self): return self.str Some security declarations might be necessary as well. Probably, a class attribute "__roles__ = None" is sufficient. -- Dieter ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] __getitem__ and returning a PageTemplateFile instance
On Wed, Oct 19, 2005 at 09:47:50PM +0200, Dieter Maurer wrote: > >Zope has encountered a problem publishing your object. > >Cannot locate object at: http://localhost:8080/vitester/asonhe > This is a "NotFound" problem. >Zope is unable to locate "vitester/asonhe" > Are you sure, "vitester/asonhe" is there? asonhe is not there, but vitester has a __getitem__ method which executes a PageTemplateFile instance and returns it. I.e. return self.test(self, self.REQUEST, value=value) (where self.test is a PageTemplateFile) It actually works if I just do: return self.test.__of__(self) But that way I can't put any values in there. How can I do this then? Do I need to make a completely new custom item to return or what? -- Anders -BEGIN GEEK CODE BLOCK- Version: 3.12 GCS/O d--@ s:+ a-- C++ UL+++$ P++ L+++ E- W+ N(+) o K? w O-- M- V PS+ PE@ Y+ PGP+ t 5 X R+ tv+ b++ DI+++ D+ G e- h !r y? --END GEEK CODE BLOCK-- PGPKey: http://random.sks.keyserver.penguin.de:11371/pks/lookup?op=get&search=0xD4DEFED0 ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] __getitem__ and returning a PageTemplateFile instance
Anders Bruun Olsen wrote at 2005-10-17 00:59 +0200: > >Zope has encountered a problem publishing your object. > >Cannot locate object at: http://localhost:8080/vitester/asonhe This is a "NotFound" problem. Zope is unable to locate "vitester/asonhe" Are you sure, "vitester/asonhe" is there? Note, that "ObjectManager.__getitem__" just locates its "ObjectManager" items... -- Dieter ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] __getitem__ and returning a PageTemplateFile instance
On Tue, Oct 18, 2005 at 08:47:23PM -0500, J Cameron Cooper wrote: > >>error_log is by default set to ignore three common types of exceptions. > >>You should remove NotFound from the list if you're getting NotFound > >>exceptions and want to see them. > >Ahhh.. Thanks, now I have a traceback, unfortunately it didn't make it any > >more clear to me what the problem is. > >Traceback (innermost last): > > Module ZPublisher.Publish, line 104, in publish > > Module ZPublisher.BaseRequest, line 355, in traverse > > Module ZPublisher.HTTPResponse, line 651, in debugError > In Zope 2.7, I see that line raising a debug error. Why it doesn't get > through I don't know, but here's what it says:: > "The object at %s has an empty or missing " \ > "docstring. Objects must have a docstring to be " \ > "published." % URL > That should help you, I think. All Zope objects that are to be published > to the web must have a docstring. Thanks, but I do have a docstring on the __getitem__ in question. This error is really starting to annoy me :-/. If I return a custom object (i.e. a SimpleItem based class instance) from __getitem__ it works fine, but if I return a PageTemplateFile instance it screws up. -- Anders -BEGIN GEEK CODE BLOCK- Version: 3.12 GCS/O d--@ s:+ a-- C++ UL+++$ P++ L+++ E- W+ N(+) o K? w O-- M- V PS+ PE@ Y+ PGP+ t 5 X R+ tv+ b++ DI+++ D+ G e- h !r y? --END GEEK CODE BLOCK-- PGPKey: http://random.sks.keyserver.penguin.de:11371/pks/lookup?op=get&search=0xD4DEFED0 ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] __getitem__ and returning a PageTemplateFile instance
Anders Bruun Olsen wrote: On Tue, Oct 18, 2005 at 03:30:42PM -0500, J Cameron Cooper wrote: error_log is by default set to ignore three common types of exceptions. You should remove NotFound from the list if you're getting NotFound exceptions and want to see them. Ahhh.. Thanks, now I have a traceback, unfortunately it didn't make it any more clear to me what the problem is. Traceback (innermost last): Module ZPublisher.Publish, line 104, in publish Module ZPublisher.BaseRequest, line 355, in traverse Module ZPublisher.HTTPResponse, line 651, in debugError In Zope 2.7, I see that line raising a debug error. Why it doesn't get through I don't know, but here's what it says:: "The object at %s has an empty or missing " \ "docstring. Objects must have a docstring to be " \ "published." % URL That should help you, I think. All Zope objects that are to be published to the web must have a docstring. --jcc -- "Building Websites with Plone" http://plonebook.packtpub.com/ Enfold Systems, LLC http://www.enfoldsystems.com ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] __getitem__ and returning a PageTemplateFile instance
On Tue, Oct 18, 2005 at 03:30:42PM -0500, J Cameron Cooper wrote: > error_log is by default set to ignore three common types of exceptions. > You should remove NotFound from the list if you're getting NotFound > exceptions and want to see them. Ahhh.. Thanks, now I have a traceback, unfortunately it didn't make it any more clear to me what the problem is. Traceback (innermost last): Module ZPublisher.Publish, line 104, in publish Module ZPublisher.BaseRequest, line 355, in traverse Module ZPublisher.HTTPResponse, line 651, in debugError NotFound: Site Error An error was encountered while publishing this resource. Debugging Notice Zope has encountered a problem publishing your object. Cannot locate object at: http://localhost:8080/vitester/asonhe Troubleshooting Suggestions 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. For more detailed information about the error, please refer to error log. If the error persists please contact the site maintainer. Thank you for your patience. -- Anders -BEGIN GEEK CODE BLOCK- Version: 3.12 GCS/O d--@ s:+ a-- C++ UL+++$ P++ L+++ E- W+ N(+) o K? w O-- M- V PS+ PE@ Y+ PGP+ t 5 X R+ tv+ b++ DI+++ D+ G e- h !r y? --END GEEK CODE BLOCK-- PGPKey: http://random.sks.keyserver.penguin.de:11371/pks/lookup?op=get&search=0xD4DEFED0 ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] __getitem__ and returning a PageTemplateFile instance
Anders Bruun Olsen wrote: On Sun, Oct 16, 2005 at 06:50:09PM +0200, Dieter Maurer wrote: I am trying to make a product where-in I want to be able to return a page based on the url, think something like /product/username which would return a page with the users details. For this purpose I am using __getitem__, but when I return a PageTemplateFile instance it just tells me it has encountered a problem publishing the object. I such a case, you look at the traceback (which you can find in the "error_log" object in your Zope "Root Folder" (ZMI)). It just says "No exceptions logged." So it does not log any errors in error_log. The error message I am getting is: Site Error An error was encountered while publishing this resource. Debugging Notice Zope has encountered a problem publishing your object. Cannot locate object at: http://localhost:8080/vitester/asonhe If it does not solve the problem directly, you include the full error information (at least "Error Type", "Error Value" *AND* "traceback") in your post. If there had been a better error description I would of course have included it, but the thing that has made this difficult to understand is that I haven't been able to find any real error messages. I have enabled debug-mode and am running Zope in the foreground, but it reports no errors at all. error_log is by default set to ignore three common types of exceptions. You should remove NotFound from the list if you're getting NotFound exceptions and want to see them. --jcc -- "Building Websites with Plone" http://plonebook.packtpub.com/ Enfold Systems, LLC http://www.enfoldsystems.com ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] __getitem__ and returning a PageTemplateFile instance
On Sun, Oct 16, 2005 at 06:50:09PM +0200, Dieter Maurer wrote: > >I am trying to make a product where-in I want to be able to return a > >page based on the url, think something like /product/username > >which would return a page with the users details. > >For this purpose I am using __getitem__, but when I return a > >PageTemplateFile instance it just tells me it has encountered a problem > >publishing the object. > I such a case, you look at the traceback (which you can find in > the "error_log" object in your Zope "Root Folder" (ZMI)). It just says "No exceptions logged." So it does not log any errors in error_log. The error message I am getting is: Site Error An error was encountered while publishing this resource. Debugging Notice Zope has encountered a problem publishing your object. Cannot locate object at: http://localhost:8080/vitester/asonhe > If it does not solve the problem directly, you include > the full error information (at least "Error Type", "Error Value" > *AND* "traceback") in your post. If there had been a better error description I would of course have included it, but the thing that has made this difficult to understand is that I haven't been able to find any real error messages. I have enabled debug-mode and am running Zope in the foreground, but it reports no errors at all. -- Anders -BEGIN GEEK CODE BLOCK- Version: 3.12 GCS/O d--@ s:+ a-- C++ UL+++$ P++ L+++ E- W+ N(+) o K? w O-- M- V PS+ PE@ Y+ PGP+ t 5 X R+ tv+ b++ DI+++ D+ G e- h !r y? --END GEEK CODE BLOCK-- PGPKey: http://random.sks.keyserver.penguin.de:11371/pks/lookup?op=get&search=0xD4DEFED0 ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] __getitem__ and returning a PageTemplateFile instance
Anders Bruun Olsen wrote at 2005-10-14 11:53 +0200: > ... >I am trying to make a product where-in I want to be able to return a >page based on the url, think something like /product/username >which would return a page with the users details. >For this purpose I am using __getitem__, but when I return a >PageTemplateFile instance it just tells me it has encountered a problem >publishing the object. I such a case, you look at the traceback (which you can find in the "error_log" object in your Zope "Root Folder" (ZMI)). If it does not solve the problem directly, you include the full error information (at least "Error Type", "Error Value" *AND* "traceback") in your post. -- Dieter ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
[Zope] __getitem__ and returning a PageTemplateFile instance
Hi, I am trying to make a product where-in I want to be able to return a page based on the url, think something like /product/username which would return a page with the users details. For this purpose I am using __getitem__, but when I return a PageTemplateFile instance it just tells me it has encountered a problem publishing the object. Example: class TestProd(SimpleItem): """A TestProd object""" meta_type = "TestProd" manage_options = ( {"label": "Edit", "action": "manage_main"}, {"label": "View", "action": "index_html"}) manage_main = PageTemplateFile("templates/mainTestProd", globals()) index_html = PageTemplateFile("templates/indexTestProd", globals()) userdetails = PageTemplateFile("templates/userdetails", globals()) def __init__(self, id, title): self.id = id self.title = title def __getitem__(self, id): # Does not work! results = fetch_userdata_from_db(id) return self.userdetails(self, self.REQUEST, results=results) def test(self, username): # Works, but uses /product/test?username=username results = fetch_userdata_from_db(username) return self.userdetails(self, self.REQUEST, results=results) I have tried with everything I can think of to debug this, but have so far failed. What am I doing wrong here? Please note that I have also tried with static data, that is returning self.userdata(self, self.REQUEST, results="some data") -- Anders -BEGIN GEEK CODE BLOCK- Version: 3.12 GCS/O d--@ s:+ a-- C++ UL+++$ P++ L+++ E- W+ N(+) o K? w O-- M- V PS+ PE@ Y+ PGP+ t 5 X R+ tv+ b++ DI+++ D+ G e- h !r y? --END GEEK CODE BLOCK-- PGPKey: http://random.sks.keyserver.penguin.de:11371/pks/lookup?op=get&search=0xD4DEFED0 ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )