[CPS-devel] can call script via url but not from script

Georges Racinet gracinet at nuxeo.com
Fri Nov 10 11:27:28 CET 2006


On Nov 10, 2006, at 10:35 AM, Joachim Schmitz wrote:

> Santi Camps schrieb:
>> On 11/9/06, Joachim Schmitz <js at aixtraware.de> 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.
> there a slight but important difference, the first one works, and  
> the second one throws an Unauthorized Exeption for getContent.

Maybe, but then it's not normal:
(CPSCore.ProxyBase extract)
>     security.declareProtected(View, 'getContent')
>     def getContent(self, lang=None, rev=None):
>         """Get the content object referred to by this proxy.
>


>
>
>
> -- 
> Mit freundlichen Grüßen                                Joachim Schmitz
> ......................................................................
> AixtraWare eK ..Joachim Schmitz ..www.aixtraware.de ..t: +49-2464-8851
> Hüsgenstr. 33a .....d-52457 Aldenhoven .............f: +49-2464-905163
>
>
> _______________________________________________
> cps-devel mailing list
> http://lists.nuxeo.com/mailman/listinfo/cps-devel
>

---------
Georges Racinet,   Nuxeo SAS
Open Source Enterprise Content Management (ECM)
Web: http://www.nuxeo.com/ and http://www.nuxeo.org/ - Tel: +33 1 40  
33 79 87






This list archive provided by Nuxeo, the leaders of open source ECM. Check out the Nuxeo 5 open source, standards-based ECM project.