Re: [Zope] Still Chipping Away At Formulator/ZPT Interface
At 06:53 PM 11/5/2002 -0600, you wrote:
>> from Products.Formulator.Errors import ...
beno> Hmmm. Went there. Was referred to a file called *Errors.py* in beno> Formulator. File doesn't exist. Noticed the thread was recent and beno> the author was the author of the program. What did I miss?!
Depending how your directory tree is set up, you may have to look in more than one place. I have a binary Plone installed (MacOSX). It has the following relevant directories:
/Applications/Plone/PloneInstance/Products /Applications/Plone/Zope/lib/python/Products
I d'l'd the latest version and found an Errors.py file (so I must have had an old version). This is what it reads: """Exception Classes for Formulator""" # These classes are placed here so that they can be imported into TTW Python # scripts. To do so, add the following line to your Py script: # from Products.Formulator.Errors import ValidationError, FormValidationError from Products.PythonScripts.Utility import allow_class class FormValidationError(Exception): def __init__(self, errors, result): Exception.__init__(self,"Form Validation Error") self.errors = errors self.result = result allow_class(FormValidationError) class ValidationError(Exception): def __init__(self, error_key, field): Exception.__init__(self, error_key) self.error_key = error_key self.field_id = field.id self.field = field self.error_text = field.get_error_message(error_key) allow_class(ValidationError) So I did as instructed, added this line: from Products.Formulator.Errors import ValidationError, FormValidationError and now it wants me to authenticate! Why? I changed the security on *access contents information* to *anonymous* just to see if that was it, but no. What do? TIA, beno
Hi beno, [...]
So I did as instructed, added this line: from Products.Formulator.Errors import ValidationError, FormValidationError and now it wants me to authenticate! Why? I changed the security on *access contents information* to *anonymous* just to see if that was it, but no. What do?
This cannot happen; I therfore conclude You do not exist ;-) It would be useful if You try to debug the problem first: - press the "cancel" button when authentification is required. You should get an error page telling You what specifically You can't access. Then there is a traceback in the usual place (if using Zope2.6.0, logging of Unauthorized exceptions must be turned on explicitely in the /error_log ..) - visit Your script in the line number told by the traceback, and figure out why Zope does not let You access this. - if You fail in figuring out what happens, come back to the list with a more complete error description (ErrorType, ErrorValue, preferably the relevant parts of the script causing the error). The mistake I most commonly have is a some typo which makes the script trying to access some internal thing instead of the proper public item. Another more obscure source of an unconditional Unauthorized error is using the wrong arguments to the "getattr" function. E.g. "getattr(context, context)" is certainly nonsense, if only that the second argument has to be a string. I would expect a TypeError, but I get an Unauthorized (both Zope2.5.1 and 2.6.0). Cheers, Clemens
At 01:34 PM 11/6/2002 +0100, you wrote:
Hi beno,
[...]
So I did as instructed, added this line: from Products.Formulator.Errors import ValidationError, FormValidationError and now it wants me to authenticate! Why? I changed the security on *access contents information* to *anonymous* just to see if that was it, but no. What do?
This cannot happen; I therfore conclude You do not exist ;-)
I exist as a problem to myself ;) It was my bad. I didn't restart Zope <:-) So I did that and now I get this error upon submitting incorrect info from my form: Error Type: Attribute Error Error Val: args and it comes from this script: try: result = context.email_us_formulator.validate_all(context.REQUEST) except FormValidationError, errlist: for item in errlist: return "<", item.args, ">" Now, from the Errors.py script we have the following: class FormValidationError(Exception): def __init__(self, errors, result): Exception.__init__(self,"Form Validation Error") self.errors = errors self.result = result So, what is *args*? Is this something defined in Python itself? TIA, beno
beno> Error Type: Attribute Error beno> Error Val: args beno> and it comes from this script: beno> try: beno> result = context.email_us_formulator.validate_all(context.REQUEST) beno> except FormValidationError, errlist: beno> for item in errlist: beno> return "<", item.args, ">" That looks like my (also non-working) code you're trying to execute! beno> Now, from the Errors.py script we have the following: beno> class FormValidationError(Exception): beno> def __init__(self, errors, result): beno> Exception.__init__(self,"Form Validation Error") beno> self.errors = errors beno> self.result = result beno> So, what is *args*? Is this something defined in Python itself? The thing that confuses me is that Exception does define an args attribute: % /Applications/Plone/Python/bin/python Python 2.1.3 (#2, Sep 16 2002, 19:32:07) [GCC 3.1 20020420 (prerelease)] on darwin6 Type "copyright", "credits" or "license" for more information. >>> dir(Exception()) ['args'] >>> Exception().args () I don't know why it wouldn't be available. It doesn't appear to be deleted by any Formulator code. I asked about this a few days ago but don't remember seeing a response. As you can see from the code you quoted, item.errors and item.result should exist though. -- Skip Montanaro - skip@pobox.com http://www.mojam.com/ http://www.musi-cal.com/
participants (3)
-
beno -
Clemens Robbenhaar -
Skip Montanaro