Creating Portlets

I was going through the Portlet Documentation, trying to learn how to create portlets. I understand that there needs to be an interface class for the portlet we want to create, but what I have a confusion over is which file should we create the interface class in.

The documentation mentioned above, asks us to create it in the interfaces.py file within the package root, but the example code given in the documentation has the same interface class written in two files:

  • interfaces.py
  • recent.py (the file that contains all the other classes required for creating the portlet i.e Assignment, AddForm, EditForm & Renderer).

I also checked out other codebases over at Collective that use portlets (qi.portlet.TagClouds & collective.portletalias). Most of them don't use an interfaces.py file and have directly written the interface class in the python file with the rest of the portlet classes.

So is an interfaces.py file not needed at all for creating portlets?

It is completely irrelevant to define an in interface class in a dedicated file or not.

@zopyx Alright!
So is putting the interface class in the interfaces.py file considered as good practice?
If not, I might as well just put in the file with the rest of the portlet classes.

I don't care. Tiny little modules only holding a single class definition is unlikely considered best practise but ask three people and get 5 opinions.

-aj

Okay! Thanks!

Since you're doing PR's to bobtemplates.plone, I suggest going to https://github.com/plone/bobtemplates.plone/issues/130 as well since it's a ticket about adding portlet support to the package: IMHO, the convention defined there is what you should be using.

Oh great! I'll have a look :slight_smile: