Adding new portlet in plone skin product with custom class py file

Here describing how to add new portlet in skin product of plone

in the products in configure.zcml

add this line

<include package=”.portlets” />

create a file portlets.xml if not exists in profiles/default and add this

<?xml version=”1.0″?>
<portlets>

<!– Portlet registrations –>

<portlet
addview=”portlets.Customnavigator”
title=”Custom navigator”
description=”Portlet to custom navigate”
/>

<!– Assign portlets automatically –>

<assignment
manager=”plone.leftcolumn”
category=”context”
key=”/”
type=”portlets.Customnavigator”
name=”Customnavigator”
/>

</portlets>

</dd>
</dl>

Now customnavigator.py

from zope.interface import implements
from zope.component import adapts, getMultiAdapter, queryUtility
from plone.app.portlets.portlets import base
from plone.memoize.instance import memoize
from plone.portlets.interfaces import IPortletDataProvider

from Acquisition import aq_inner, aq_parent
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
from Products.CMFCore.utils import getToolByName
from Products.CMFCore.interfaces import ISiteRoot

#from Products.SitsPatient import CFApplicantMessageFactory as _

class ICustomnavigatorPortlet(IPortletDataProvider):
“””
test
“””

class Assignment(base.Assignment):

implements(ICustomnavigatorPortlet)

@property
def title(self):
return “custom navigator”

class Renderer(base.Renderer):

def __init__(self, context, request, view, manager, data):

base.Renderer.__init__(self, context, request, view, manager, data)

@property

def available(self):

return self.show() is not False

def custom_link(self):

if self.context.portal_type == ‘CustomObject’:

if str(self.context.REQUEST.get(‘ACTUAL_URL’,)).find(‘portal_factory’)<0:

return aq_inner(self.context).absolute_url()

else:

return None


render = ViewPageTemplateFile(‘hospitalnavigator.pt’)

def show(self):

#import pdb

#pdb.set_trace()

if self.portal_state.anonymous():

return False

#if not self.pas_info.hasLoginPasswordExtractor():

# return False

#page = self.request.get(‘URL’, ”).split(‘/’)[-1]

#return page not in (‘login_form’, ‘join_form’)

return True


render = ViewPageTemplateFile(‘hospitalnavigator.pt’)

def show(self):

#import pdb

#pdb.set_trace()

if self.portal_state.anonymous():

return False

#if not self.pas_info.hasLoginPasswordExtractor():

# return False

#page = self.request.get(‘URL’, ”).split(‘/’)[-1]

#return page not in (‘login_form’, ‘join_form’)

return True

Now create a folder portlets and inside that put 3 files __init__.py configure.zcml and customnavigator.pt and customnavigator.py

configure.zcml:

<configure
xmlns=”http://namespaces.zope.org/zope&#8221;
xmlns:plone=”http://namespaces.plone.org/plone”&gt;

<include package=”plone.app.portlets” />

<plone:portlet
name=”portlets.Customnavigator”
interface=”.customnavigator.ICustomnavigatorPortlet”
assignment=”.customnavigator.Assignment”
renderer=”.customnavigator.Renderer”
addview=”.customnavigator.AddForm”
/>

</configure>

customnavigator.pt

<dl id=”portlet-navigation” i18n:domain=”plone”>

<dt >
<span></span>
<span></span>

<span i18n:translate=”portlet_navigation_custom_menu”>Custom menu</span>
</dt>
<dd>

<ul>
<li>
<a href=” tal:attributes=”href string:${view/custom_link}” i18n:translate=””>My link</a>
</li>

</ul>


Advertisements
About

Work is fun!

Tagged with: , , , , , , ,
Posted in ploneCMS, python, Tips And Tricks, Zope

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Disclaimer
All content provided on this "tareqalam.com" blog is for informational purposes only. The owner of this blog makes no representations as to the accuracy or completeness of any information on this site or found by following any link on this site. The owner of [tareqalam.wordpress.com] will not be liable for any errors or omissions in this information nor for the availability of this information. The owner will not be liable for any losses, injuries, or damages from the display or use of this information.
July 2010
M T W T F S S
« May   Aug »
 1234
567891011
12131415161718
19202122232425
262728293031  

Enter your email address to follow this blog and receive notifications of new posts by email.

Join 23 other followers

%d bloggers like this: