external method problem

3 messages Options
Embed this post
Permalink
Jan Pokorny () external method problem
Reply Threaded More More options
Print post
Permalink
Hello,

I have created an external method which returns an class object:

def validateUser(username,password):
    res = Result()
    ... some code producing reply ...
    if reply != None:
        res.success = True
    return res

The method works well.

But when I try use res.success (in another script or in TAL in a page  
template), Plone returns an error saying Unauthorized: You are not  
allowed to access 'success' in this context .

For example:

if res.success == True:
    return 'OK'
else:
    return 'KO'

Is there any restriction in returning class objects from external  
methods? Have I missed something?

Thank you for any help.

Jan

_______________________________________________
Product-Developers mailing list
[hidden email]
http://lists.plone.org/mailman/listinfo/product-developers
Hedley Roos-2 () Re: external method problem
Reply Threaded More More options
Print post
Permalink
You are encountering this because page templates execute within a
restricted python environment. This basically means that only a few
classes and functions are available in a page template.

Google for allow_module or grep your Products directory for an example
of how to allow your Result class.

Hedley

_______________________________________________
Product-Developers mailing list
[hidden email]
http://lists.plone.org/mailman/listinfo/product-developers
Radim Novotny-2 () Re: external method problem
Reply Threaded More More options
Print post
Permalink
In reply to this post by Jan Pokorny
Jan Pokorný wrote:

> Hello,
>
> I have created an external method which returns an class object:
>
> def validateUser(username,password):
>    res = Result()
>    ... some code producing reply ...
>    if reply != None:
>        res.success = True
>    return res
>
> The method works well.
>
> But when I try use res.success (in another script or in TAL in a page
> template), Plone returns an error saying Unauthorized: You are not
> allowed to access 'success' in this context .
>

Try to set

__allow_access_to_unprotected_subobjects__ = 1

as attribute of the Result class.
See eg. Products/CMFPlone/PloneBatch.py/class Batch.

If you want to import Result class from Python script or Page template,
you must use allow_module/allow_class as Hedley wrote.

--
Radim Novotny


> For example:
>
> if res.success == True:
>    return 'OK'
> else:
>    return 'KO'
>
> Is there any restriction in returning class objects from external
> methods? Have I missed something?
>
> Thank you for any help.
>
> Jan


_______________________________________________
Product-Developers mailing list
[hidden email]
http://lists.plone.org/mailman/listinfo/product-developers