how to call script from page template

classic Classic list List threaded Threaded
8 messages Options
Reuben A Christie Reuben A Christie
Reply | Threaded
Open this post in threaded view
|

how to call script from page template

Hi, I modifying a page template in skin folder, from
popupreferencewidget. I am trying to call a python script which is in
Extension folder. but It gives me an error if i try
python:here.myScript()
can anybody pleaes tell me how do i call script from page template. ?

I can not put the script in the same folder where page template
is,because i am importing aq_base from that script and aq_base can not
be imported from that context.

thanks
--
Reuben Christie

Decision Technologies Inc.
New York.



-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions,
and more. http://solutions.newsforge.com/ibmarch.tmpl
_______________________________________________
Plone-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/plone-users
J Cameron Cooper-3 J Cameron Cooper-3
Reply | Threaded
Open this post in threaded view
|

Re: how to call script from page template

Reuben Christie wrote:
> Hi, I modifying a page template in skin folder, from
> popupreferencewidget. I am trying to call a python script which is in
> Extension folder. but It gives me an error if i try
> python:here.myScript()
> can anybody pleaes tell me how do i call script from page template. ?
>
> I can not put the script in the same folder where page template
> is,because i am importing aq_base from that script and aq_base can not
> be imported from that context.

External Methods are not automatically discovered. You must create an
object that points at the code in your Extensions directory. Please read
the part of the Zope book that deals with External Methods.

Can you not use the aq_base property? All objects should have that.

                --jcc
--
"Building Websites with Plone"
http://plonebook.packtpub.com/

Enfold Systems, LLC
http://www.enfoldsystems.com


-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions,
and more. http://solutions.newsforge.com/ibmarch.tmpl
_______________________________________________
Plone-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/plone-users
Reuben A Christie Reuben A Christie
Reply | Threaded
Open this post in threaded view
|

Re: how to call script from page template

Ok now i created the external method object that points to the code that
i have in Extensions directory. but now i get the new error that global
name context is not defined .


On Wed, 2005-10-19 at 12:42, J Cameron Cooper wrote:

> Reuben Christie wrote:
> > Hi, I modifying a page template in skin folder, from
> > popupreferencewidget. I am trying to call a python script which is in
> > Extension folder. but It gives me an error if i try
> > python:here.myScript()
> > can anybody pleaes tell me how do i call script from page template. ?
> >
> > I can not put the script in the same folder where page template
> > is,because i am importing aq_base from that script and aq_base can not
> > be imported from that context.
>
> External Methods are not automatically discovered. You must create an
> object that points at the code in your Extensions directory. Please read
> the part of the Zope book that deals with External Methods.
>
> Can you not use the aq_base property? All objects should have that.
>
> --jcc
--
Reuben Christie

Decision Technologies Inc.
New York.



-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions,
and more. http://solutions.newsforge.com/ibmarch.tmpl
_______________________________________________
Plone-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/plone-users
J Cameron Cooper-3 J Cameron Cooper-3
Reply | Threaded
Open this post in threaded view
|

Re: how to call script from page template

Reuben Christie wrote:
> Ok now i created the external method object that points to the code that
> i have in Extensions directory. but now i get the new error that global
> name context is not defined .

That is because it is not defined. The computer is not lying to you.

External Methods do not get magic additions to the namespace like Python
Scripts et al. However, 'self', which should be the first argument, is
equivalent to 'context'.


                --jcc


> On Wed, 2005-10-19 at 12:42, J Cameron Cooper wrote:
>
>>Reuben Christie wrote:
>>
>>>Hi, I modifying a page template in skin folder, from
>>>popupreferencewidget. I am trying to call a python script which is in
>>>Extension folder. but It gives me an error if i try
>>>python:here.myScript()
>>>can anybody pleaes tell me how do i call script from page template. ?
>>>
>>>I can not put the script in the same folder where page template
>>>is,because i am importing aq_base from that script and aq_base can not
>>>be imported from that context.
>>
>>External Methods are not automatically discovered. You must create an
>>object that points at the code in your Extensions directory. Please read
>>the part of the Zope book that deals with External Methods.
>>
>>Can you not use the aq_base property? All objects should have that.
>>
>> --jcc


--
"Building Websites with Plone"
http://plonebook.packtpub.com/

Enfold Systems, LLC
http://www.enfoldsystems.com


-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions,
and more. http://solutions.newsforge.com/ibmarch.tmpl
_______________________________________________
Plone-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/plone-users
Reuben A Christie Reuben A Christie
Reply | Threaded
Open this post in threaded view
|

Re: how to call script from page template

Oh okay thanks,now it seems I am getting the real error. What is the
right way of getting hold of the AT instance that the
popupreferencewidget.pt currently referring to ? because in my python
script i want to get hold of the AT class and call the  method on it,
that would give me the physicalpath (ie. initial_location) where my
popupreferencewidget should look for the reference objects.

i hope if i figure this out then i would be able to call a method
instead of using a string for the property initial_location in
popupreferencewidget
thanks
Reuben
On Wed, 2005-10-19 at 12:52, J Cameron Cooper wrote:

> Reuben Christie wrote:
> > Ok now i created the external method object that points to the code that
> > i have in Extensions directory. but now i get the new error that global
> > name context is not defined .
>
> That is because it is not defined. The computer is not lying to you.
>
> External Methods do not get magic additions to the namespace like Python
> Scripts et al. However, 'self', which should be the first argument, is
> equivalent to 'context'.
>
>
> --jcc
>
>
> > On Wed, 2005-10-19 at 12:42, J Cameron Cooper wrote:
> >
> >>Reuben Christie wrote:
> >>
> >>>Hi, I modifying a page template in skin folder, from
> >>>popupreferencewidget. I am trying to call a python script which is in
> >>>Extension folder. but It gives me an error if i try
> >>>python:here.myScript()
> >>>can anybody pleaes tell me how do i call script from page template. ?
> >>>
> >>>I can not put the script in the same folder where page template
> >>>is,because i am importing aq_base from that script and aq_base can not
> >>>be imported from that context.
> >>
> >>External Methods are not automatically discovered. You must create an
> >>object that points at the code in your Extensions directory. Please read
> >>the part of the Zope book that deals with External Methods.
> >>
> >>Can you not use the aq_base property? All objects should have that.
> >>
> >> --jcc
--
Reuben Christie

Decision Technologies Inc.
New York.



-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions,
and more. http://solutions.newsforge.com/ibmarch.tmpl
_______________________________________________
Plone-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/plone-users
Reuben A Christie Reuben A Christie
Reply | Threaded
Open this post in threaded view
|

Re: how to call script from page template

In reply to this post by J Cameron Cooper-3
Ok this is myscript looks like. i have the error comming  from the line
where i call getToolByName, the error is Attribute Error:portal_url'
i dont know if I am missing any import (which i dont think) or is there
any security issue.
please help
Reuben
_-----------------------------------------------
from Acquisition import aq_base,aq_parent
from Products.CMFCore.utils import getToolByName
def initial_location_finder(self,instance,initial_location=''):
    if initial_location=='':
        purl = getToolByName(instance, 'portal_url')
        return purl.getRelativeUrl(aq_parent(instance))
    else:
        value = getattr(aq_base(instance),
initial_location,initial_location)
        if callable(value):
            value = value()
        return value
________________________________________________________
On Wed, 2005-10-19 at 12:52, J Cameron Cooper wrote:

> Reuben Christie wrote:
> > Ok now i created the external method object that points to the code that
> > i have in Extensions directory. but now i get the new error that global
> > name context is not defined .
>
> That is because it is not defined. The computer is not lying to you.
>
> External Methods do not get magic additions to the namespace like Python
> Scripts et al. However, 'self', which should be the first argument, is
> equivalent to 'context'.
>
>
> --jcc
>
>
> > On Wed, 2005-10-19 at 12:42, J Cameron Cooper wrote:
> >
> >>Reuben Christie wrote:
> >>
> >>>Hi, I modifying a page template in skin folder, from
> >>>popupreferencewidget. I am trying to call a python script which is in
> >>>Extension folder. but It gives me an error if i try
> >>>python:here.myScript()
> >>>can anybody pleaes tell me how do i call script from page template. ?
> >>>
> >>>I can not put the script in the same folder where page template
> >>>is,because i am importing aq_base from that script and aq_base can not
> >>>be imported from that context.
> >>
> >>External Methods are not automatically discovered. You must create an
> >>object that points at the code in your Extensions directory. Please read
> >>the part of the Zope book that deals with External Methods.
> >>
> >>Can you not use the aq_base property? All objects should have that.
> >>
> >> --jcc
--
Reuben Christie

Decision Technologies Inc.
New York.



-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions,
and more. http://solutions.newsforge.com/ibmarch.tmpl
_______________________________________________
Plone-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/plone-users
Reuben A Christie Reuben A Christie
Reply | Threaded
Open this post in threaded view
|

Re: how to call script from page template

In reply to this post by J Cameron Cooper-3
I am calling my external method from popupreference.pt like this is it correct way to call ?
location python:here.initial_location_finder(here,widget.initial_location);



-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions,
and more. http://solutions.newsforge.com/ibmarch.tmpl
_______________________________________________
Plone-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/plone-users
Reuben A Christie Reuben A Christie
Reply | Threaded
Open this post in threaded view
|

Re: how to call script from page template

In reply to this post by Reuben A Christie
hi, I am into ditch now. dont know where to go. I have put somuch of
errorts doing it and now when it seems like almost done, i got this
problem that i have no idea how to solve.

the function i have in the AT class is following
security.declarePublic('myFunc')
def myFunc(self):
    """
    """
    currpath=self.getPhysicalPath()
    searchBase=self.restrictedTraverse(currpath[:3])
    ldfolders=searchBase.ZopeFind(obj=searchBase,search_sub=0,
obj_metatypes='LaborDetailFolder')
    ldfolder=ldfolders[0][1]
    retpath=ldfolder.getPhysicalPath()
    return '/'.join(retpath)

now, i have a external method in my zope instant's Extension folder
which is actually called by popupreferencewidget. This external method
takes the instance of AT as argument and then checks for the function
name in one of the widget attributes. if its callable then the external
method calls, here is the external method
----------------------------------------------
from Acquisition import aq_base,aq_parent
from Products.CMFCore.utils import getToolByName

def initial_location_finder(self,instance,initial_location):
    if not initial_location:
#        purl = getToolByName(instance, 'portal_url')
#        return purl.getRelativeUrl(aq_parent(instance))
         return '/'
    else:
        value = getattr(aq_base(instance),
initial_location,initial_location)
        if callable(value):
            value = value()
            print value
        return value
--------------------------
The problem is when external method make  the call using value=value()
i get the error that NameError: global name 'self' is not defined
i tried replacing self with context also,but error is same
please help me
Reuben

 



On Wed, 2005-10-19 at 14:58, Reuben Christie wrote:

> Ok this is myscript looks like. i have the error comming  from the line
> where i call getToolByName, the error is Attribute Error:portal_url'
> i dont know if I am missing any import (which i dont think) or is there
> any security issue.
> please help
> Reuben
> _-----------------------------------------------
> from Acquisition import aq_base,aq_parent
> from Products.CMFCore.utils import getToolByName
> def initial_location_finder(self,instance,initial_location=''):
>     if initial_location=='':
>         purl = getToolByName(instance, 'portal_url')
>         return purl.getRelativeUrl(aq_parent(instance))
>     else:
>         value = getattr(aq_base(instance),
> initial_location,initial_location)
>         if callable(value):
>             value = value()
>         return value
> ________________________________________________________
> On Wed, 2005-10-19 at 12:52, J Cameron Cooper wrote:
> > Reuben Christie wrote:
> > > Ok now i created the external method object that points to the code that
> > > i have in Extensions directory. but now i get the new error that global
> > > name context is not defined .
> >
> > That is because it is not defined. The computer is not lying to you.
> >
> > External Methods do not get magic additions to the namespace like Python
> > Scripts et al. However, 'self', which should be the first argument, is
> > equivalent to 'context'.
> >
> >
> > --jcc
> >
> >
> > > On Wed, 2005-10-19 at 12:42, J Cameron Cooper wrote:
> > >
> > >>Reuben Christie wrote:
> > >>
> > >>>Hi, I modifying a page template in skin folder, from
> > >>>popupreferencewidget. I am trying to call a python script which is in
> > >>>Extension folder. but It gives me an error if i try
> > >>>python:here.myScript()
> > >>>can anybody pleaes tell me how do i call script from page template. ?
> > >>>
> > >>>I can not put the script in the same folder where page template
> > >>>is,because i am importing aq_base from that script and aq_base can not
> > >>>be imported from that context.
> > >>
> > >>External Methods are not automatically discovered. You must create an
> > >>object that points at the code in your Extensions directory. Please read
> > >>the part of the Zope book that deals with External Methods.
> > >>
> > >>Can you not use the aq_base property? All objects should have that.
> > >>
> > >> --jcc
--
Reuben Christie

Decision Technologies Inc.
New York.



-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions,
and more. http://solutions.newsforge.com/ibmarch.tmpl
_______________________________________________
Plone-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/plone-users