-2

How do I call a method which is in the filesystem from a TAL Portlet (made available by collective.portlet.tal)?

This is how I did it: I defined a new BrowserView (createPictMenu.py in my case) and then registered it as the renderer for a new portlet component:

class AddressTAL(BrowserView)

    def my_address()
        address_bar = ViewTemplatePageFile('templates/address_left.pt') # this 
         is the page template I want for my new portlet.

And in configure.zcml:

<plone:portlet
    name="collective.portlet.tal.TALPortlet"
    interface="collective.portlet.tal.talportlet.ITALPortlet"
    assignment="collective.portlet.tal.talportlet.Assignment"
    view_permission="zope2.View"
    edit_permission="cmf.ManagePortal"
    renderer=".browser.createPictMenu.AddressTAL"
    addview="collective.portlet.tal.talportlet.AddForm"
    editview="collective.portlet.tal.talportlet.EditForm"
    />

Then I went to localhost:8080/myproject/@@manage-portlets and selected the TAL Portlet option from the Add Portlet dropdown list. I informed title as address and for description I inserted the snippet below to call address_tal():

<span tal:define="global li view/myaddress">
    <span tal:replace="structure li" /> 
</span> 

Unfortunately, it didn't work. Please help.

Davi Lima
  • 800
  • 1
  • 6
  • 20
Nirmala Sudhir
  • 119
  • 1
  • 3
  • 13
  • 2
    If you only change the renderer you should use plone:portletRenderer. Please allow me to ask, what is the final goal of your customization? Because I think collective.portlet.tal is not what you need. – Mathias Aug 28 '13 at 15:09
  • I created my TAL Portlet.I want to get return value of method of one class which is in filesystem(createPictMenu.py) in TAL Portlet. How to access the method in TAL Portlet(in zmi).... – Nirmala Sudhir Aug 29 '13 at 04:58
  • @@mat: I Will send you one link which i explained about my need clearly(i think). So please have a look at http://plone.293351.n2.nabble.com/How-to-render-a-template-page-by-calling-its-method-from-TAL-portlet-manage-portlets-tt7567464.html#a7567490 – Nirmala Sudhir Aug 29 '13 at 05:33
  • So you have a template that renders a template that calls a method that renders a template. What possesses you to think this is a good idea? – Lennart Regebro Aug 29 '13 at 06:17
  • Voting to close as you don't explain what the problem is. python: `view.myaddress()` is a correct way to call a portlet renderer view method. – Lennart Regebro Aug 29 '13 at 10:00
  • Please provide an error description in your posts. – Lennart Regebro Aug 30 '13 at 07:55

2 Answers2

0

It's of very little information or matter that the method is on the file system. That's where it should be. Having it in the ZODB is possible but a bad idea.

But there are many types of methods, and how you call them from TAL differs.

You can have what in the ZMI is called "Script (Python) methods" that are accessed through portal_skins, you can have methods on content objects and you can have methods on views. These are all callable from TAL.

For methods that are neither of these, you will have to create a method of the above type that you can call, which in turn then calls the method you want to call. For a portlet the obvious place to create that method is by adding a method on the Renderer, which is a type of view, and which you can call from the portlets template.

In your case, the method you want to call is a method on the renderer already. That means you just call it.

<p tal:content="view/myaddress" />

Note that you have forgotten the self parameter in the definition. Also, please follow PEP8.

Lennart Regebro
  • 167,292
  • 41
  • 224
  • 251
  • @@regebro:I dont want to put a taladdress() method in zmi script. Why means. The class and the method is not truly independent. Some of its values is fetched by another class which is in creatPictMenu.py. So its not good idea for me to put the method alone in zmi script – Nirmala Sudhir Aug 29 '13 at 06:19
  • @@regebro: So only thing i can do is i have to call the method from file system to get return values in TAL Portlet – Nirmala Sudhir Aug 29 '13 at 06:21
  • @nirmala: Your comments are like random generated text and make no sense whatsoever. "I dont want to put a taladdress() method in zmi script. " - I didn't tell you to do that. In fact I told you to NOT do that. Read my answer. Explain which words you don't understand. – Lennart Regebro Aug 29 '13 at 06:27
  • @@regebro: You said this "You can have what in the ZMI is called "Script (Python) methods" that are accessed through portal_skins, you can have methods on content objects and you can have methods on views. These are all callable from TAL." thays y i told you that i dont want to put the method directly inside the zmi script – Nirmala Sudhir Aug 29 '13 at 06:34
  • @@regebro: I cant understand part which you told me "For methods that are neither of these, you will have to create a method of the above type that you can call, which in turn then calls the method you want to call. For a portlet the obvious place to create that method is by adding a method on the Renderer, which is a type of view, and which you can call from the portlets template." – Nirmala Sudhir Aug 29 '13 at 06:35
  • @nirmala: Do you understand the difference between "can" and "should"? Yes, you *can* have that. I didn't say you *should*. – Lennart Regebro Aug 29 '13 at 06:35
  • @nirmala: Ignore that bit. I tried making a generally useful answer, this is what you do on Stackoverflow. What *you* should do is delete the portlet and start over. You don't want to use the TAL portlet. – Lennart Regebro Aug 29 '13 at 06:38
  • @@regebro: I understood that you didnt me that "i should do like that".But i just tried to explain that i want that way to do – Nirmala Sudhir Aug 29 '13 at 06:38
  • @nirmala: You want to do it that way? Above you said you did NOT want to do it that way. In any case, you should not do it that way. – Lennart Regebro Aug 29 '13 at 06:39
  • @nirmala OK, good. Now delete whatever you are doing, and create a new portlet, based on how to make portlets in Aspelis book, as I know you have it. Just copy that code. You can also use [ZopeSkel](https://pypi.python.org/pypi/ZopeSkel) to create a basic portlet with less typing. – Lennart Regebro Aug 29 '13 at 06:43
  • @@regebro: Will do it. Thanks for your advice – Nirmala Sudhir Aug 29 '13 at 06:45
  • can anyone tell us what is the TAL code for calling a method which is in filesystem from TAL Portlet(in zmi) – Nirmala Sudhir Aug 29 '13 at 09:42
  • @nirmala `

    ` Note that you have forgotten the self parameter in the definition. Also, please learn to read.
    – Lennart Regebro Aug 29 '13 at 09:54
  • @@regebro: I used the line

    in TAL portlet.. but its not working. I m reading the documents and trying it
    – Nirmala Sudhir Aug 29 '13 at 10:24
  • @nirmala: I'm starting to think that you have a learning disability or something. How many times have I told you that "It's not working" isn't a useful error description? I don't think I've ever talked with a programmer that is so stubbornly and brutally incompetent as you. Why is it so impossible for you to include an error description or a traceback? – Lennart Regebro Aug 29 '13 at 10:29
  • @@regebro: I include self in my code. But its my mistake i didn't post it correctly. So the problem is not with self in method – Nirmala Sudhir Aug 29 '13 at 11:33
  • @nirmala: You didn't understand a word I just said, did you? – Lennart Regebro Aug 29 '13 at 11:41
0

You should have registered your class AddressTAL with a browser:view directive, not a plone:portlet one. Like this:

<configure
    xmlns="http://namespaces.zope.org/zope"
    xmlns:browser="http://namespaces.zope.org/browser">

  <browser:page
      name="address-view"
      class=".browser.createPictMenu.AddressTAL"
      for="*"
      permission="zope2.View"
      />

</configure>

And then call it with:

<div tal:define="my_address python:context.restrictedTraverse('@@address-view').my_address()" >
    Your method returns <span tal:content="my_address" />
</div>

Or:

<div tal:define="address_view context/@@address-view" >
    Your method returns <span tal:content="address_view/my_address" />
</div>
Davi Lima
  • 800
  • 1
  • 6
  • 20
  • The AddressTAL view is actually the portlet renderer. Hence `view/my_address` should be enough. My guess is that the problem is that they forgot the `self`. But since they don't provide an error message... – Lennart Regebro Aug 29 '13 at 09:55
  • @@Davi Lima: Hi davi,thanks for your msg now i m getting my output some what. But i have to correct it to get exact output which i expected. Thanks for the help – Nirmala Sudhir Aug 29 '13 at 10:52
  • @@Davi : Hi, TAL portlet is working fine but now the problem is m just getting the entire addressleft.pt html code. But i want it to be display only the content not the entire code. So what i have to change further. – Nirmala Sudhir Aug 30 '13 at 06:10