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=getsearch=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
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=getsearch=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
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=getsearch=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
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: TABLE BORDER=0 WIDTH=100% TR VALIGN=TOP TD WIDTH=10% ALIGN=CENTER nbsp; /TD TD WIDTH=90% H2Site Error/H2 PAn error was encountered while publishing this resource. /P PSTRONGDebugging Notice/STRONG/P Zope has encountered a problem publishing your object.p Cannot locate object at: http://localhost:8080/vitester/asonhe HR NOSHADE PTroubleshooting Suggestions/P UL LIThe URL may be incorrect./LI LIThe parameters passed to this resource may be incorrect./LI LIA resource that this resource relies on may be encountering an error./LI /UL PFor more detailed information about the error, please refer to error log. /P PIf the error persists please contact the site maintainer. Thank you for your patience. /P /TD/TR /TABLE -- 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=getsearch=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
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=getsearch=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] Passing args to PageTemplateFile instances
On Fri, Sep 23, 2005 at 12:06:00PM +0100, Peter Bengtsson wrote: Please press Reply-All and not just to me. Sorry about that. That is the correct way of calling PageTemplateFile objects in python code. I've got it working in many places. The error must be either a new zope bug or something else being wrong. Is your setup as simple as you've described in the email? Yes. This is the class I am using: 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()) test = PageTemplateFile(templates/test, globals()) def __init__(self, id, title): self.id = id self.title = title def testit(self, REQUEST=None): return self.test(self, self.REQUEST, something=blah) And the test template: !DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Strict//EN http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd; html head meta http-equiv=content-type content=text/html;charset=ISO-8859-1 / meta name=copyright content=copy; 2004 amp; Anders Bruun Olsen lt;anders(AT)bruun-olsen(DOT)net / link rel=stylesheet type=text/css href=css / title tal:content=container/title_or_idTITLE/title /head body div pWelcome to tal:block tal:replace=container/title_or_id//p p tal:content=python:str(options)/ p tal:content=python:len(request.form.keys())/ p tal:content=python:context.absolute_url_path()/ /div /body /html I have added it to the rootfolder in ZMI with the ID testing. What happens when you in that TAL do something like: br tal:replace=python:str(options) / Gives: {'args': ()} Do the other namespaces work in the page template? Eg. br tal:replace=python:len(request.form.keys()) / or br Gives: 0 tal:replace=python:context.absolute_url_path() / Gives: /testing -- 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=getsearch=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] Passing args to PageTemplateFile instances
On Fri, Sep 23, 2005 at 12:39:31PM +0100, Peter Bengtsson wrote: RESULT: --- Welcome to testprod {'args': (TestProd at /test/testprod used for /test/testprod, HTTPRequest, URL=http://localhost:8080/test/testprod/test_testprod), 'something': 'blah'} 0 /test/testprod http://www.peterbe.com/test/TestProd.tgz So it works just fine in Zope 2.8.0 I suspect that the code you paste was idented wrong because the def testit() function looked like it was part of the __init__ function. Yes, the paste was wrong, but there was more than that, I had my editor slightly misconfigured, which meant that the testit method was done with tab-indention and the rest of the file with space-indention. After I fixed that, it worked correctly and something shows up in options. I am absolutely stumped by why an indention problem can cause such a weird bug. I would have expected Zope/python to spew out an error telling me that indention was fucked up. To just silently make things not work is definitely not nice. Anyway, thank you so much for your help! -- 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=getsearch=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 )
[Zope] Passing args to PageTemplateFile instances
Hi, I have read some posts about this before, but the solutions given there does not seem to work for me. The deal is that I would like to make a product where amongst other things there needs to be a search feature. I then make a method that takes input from a form with searchwords but then I get stuck. How do I get the search results handed over to a ZPT that will display them? I would like to just pass the results as an argument to it, and have made a simple test-product to test how this would work. 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()) test = PageTemplateFile(templates/test, globals()) def __init__(self, id, title): self.id = id self.title = title def testit(self, REQUEST=None): return self.test.__of__(self)(something=blah) In the template I should now be able to access options/something according to previous posts, but this: span tal:replace=options/something/ results in: Error Type: KeyError Error Value: 'something' I am using Zope 2.8.0. Am I doing it wrong? How can it be done correctly? -- 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=getsearch=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 )
[Zope] Security framework troubles
Hi, I am attempting to make a zope product (a custom book-database for use by my employer) and of course want to secure it. I have added this code to my class: security = ClassSecurityInfo() security.setDefaultAccess(deny) security.declareProtected(View Bookbase, index_html) security.declareProtected(View Bookbase, standard_page) security.declareProtected(View management screens, manage_main) And also of course InitializeClass(Bookbase) When the template tries to access container/title an access denied expection is raised. With VerboseSecurity I get this explanaition: Unauthorized: The container has no security assertions. Access to 'title' of (Bookbase at /bookbase) denied. What exactly am I missing here? It works if I do setDefaultAccess(allow), but I don't want to allow access by default and then just deny for those I know I want to deny access to. I want it the other way around. -- 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=getsearch=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 )