Re: can call script via url but not from script

"Santi Camps" <[email protected]>
Newsgroups gmane.comp.web.zope.cps.devel
Message-ID <[email protected]>
On 11/9/06, Joachim Schmitz <[email protected]> wrote:
> In the port_root I have a ProxyFolder campus of portal_type University.
> In the University-Class I defined a routine to get a certain value.
>
> when I call this via the browser-url like so:
>
> http://www.test.de/srp/campus/getHallTitle?hall=xxx
>
> the correct title is returned.
>
> but when I call it in a script:
>
> context.portal_url.getPortalObject().campus.getHallTitle("xxx")
>
> I get an attribute error "getHallTitle"
>
> this works also in a script:
>

This is because your "campus" object is really a CPS Proxy,
referencing a really campus object existing in the portal_repository
(named the "Content").   So, the proxy object doesn't have the
getHallTitle method, but the content object have.

A __getitem__ method exists in the proxies to do some magic, so your
call http://www.test.de/srp/campus/getHallTitle?hall=xxx works.   To
do the same in a script, you can use either:

context.portal_url.getPortalObject().campus['getHallTitle']("xxx")

or

content = context.portal_url.getPortalObject().campus.getContent()
content.getHallTitle("xxx")

That's no difference between them, but the second option is a cheaper
operation if you need to call more methods or attributes.

Regards
-- 
Santi Camps
Earcon S.L. - http://www.earcon.com
                  - http://www.kmkey.com
_______________________________________________
cps-devel mailing list
http://lists.nuxeo.com/mailman/listinfo/cps-devel
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.