To get Current Logged username(code)is working in zpt views but the same code is not working in Plone(custome portlets) ......Please do need ful..........I am pasting total code here.....Please give reply as soon as possible.
from zope import schema
from zope.component import getMultiAdapter
from zope.formlib import form
from zope.interface import implements
from plone.app.portlets.portlets import base
from plone.memoize import ram
from plone.memoize.compress import xhtml_compress
from plone.memoize.instance import memoize
from plone.portlets.interfaces import IPortletDataProvider
from plone.app.portlets.cache import render_cachekey
from Acquisition import aq_inner
from Acquisition import aq_parent
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
from Products.CMFCore.utils import getToolByName
from zope.interface import Interface
from collective.mycontacts import mycontactsMessageFactory as _
class ISRSContactSearchPortlet(IPortletDataProvider):
"""A portlet
It inherits from IPortletDataProvider because for this portlet, the
data that is being rendered and the portlet assignment itself are the
same.
"""
# TODO: Add any zope.schema fields here to capture portlet configuration
# information. Alternatively, if there are no settings, leave this as an
# empty interface - see also notes around the add form and edit form
# below.
# some_field = schema.TextLine(title=_(u"Some field"),
# description=_(u"A field to use"),
# required=True)
class Assignment(base.Assignment):
"""Portlet assignment.
This is what is actually managed through the portlets UI and associated
with columns.
"""
implements(ISRSContactSearchPortlet)
# TODO: Set default values for the configurable parameters here
# some_field = u""
# TODO: Add keyword parameters for configurable parameters here
# def __init__(self, some_field=u"):
# self.some_field = some_field
def __init__(self):
pass
@property
def title(self):
"""This property is used to give the title of the portlet in the
"manage portlets" screen.
"""
return "Search Contacts Portlet"
class Renderer(base.Renderer):
"""Portlet renderer.
This is registered in configure.zcml. The referenced page template is
rendered, and the implicit variable 'view' will refer to an instance
of this class. Other methods can be added and referenced in the template.
"""
_template = ViewPageTemplateFile('srscontactsearchportlet.pt')
def __init__(self, *args):
base.Renderer.__init__(self, *args)
context = aq_inner(self.context)
portal_state = getMultiAdapter((context, self.request), name=u'plone_portal_state')
self.anonymous = portal_state.anonymous()
self.portal_url = portal_state.portal_url()
self.typesToShow = portal_state.friendly_types()
plone_tools = getMultiAdapter((context, self.request), name=u'plone_tools')
self.catalog = plone_tools.catalog()
@ram.cache(render_cachekey)
def render(self):
return xhtml_compress(self._template())
#@property
#def available(self):
# return len(self._data())
@memoize
def get_url(self):
return self._data()
@memoize
def _data(self):
""" """
context = aq_inner(self.context)
catalog = getToolByName(context, 'portal_catalog')
path = context.getPhysicalPath()
mt = getToolByName(self, 'portal_membership')
if mt.isAnonymousUser():
return ''
else:
member = mt.getAuthenticatedMember()
#path += '/'+'MyMicroSites'+'/'+ member.getUserName()+'Home'
path += '/'+'MyMicroSites'+'/'+ 'sreenath'+'Home'
#path += '/'+ member.getUserName() + 'MyContacts' + '/' + member.getUserName() + 'Contacts' + '/advcntsearch'
path += '/'+ 'sreenath' + 'MyContacts' + '/' + 'sreenath' + 'Contacts' + '/advcntsearch'
if path == '':
return ''
return path
# NOTE: If this portlet does not have any configurable parameters, you can
# inherit from NullAddForm and remove the form_fields variable.
class AddForm(base.AddForm):
"""Portlet add form.
This is registered in configure.zcml. The form_fields variable tells
zope.formlib which fields to display. The create() method actually
constructs the assignment that is being added.
"""
form_fields = form.Fields(ISRSContactSearchPortlet)
def create(self, data):
return Assignment(**data)
# NOTE: IF this portlet does not have any configurable parameters, you can
# remove this class definition and delete the editview attribute from the
# <plone:portlet /> registration in configure.zcml
class EditForm(base.EditForm):
"""Portlet edit form.
This is registered with configure.zcml. The form_fields variable tells
zope.formlib which fields to display.
"""
form_fields = form.Fields(ISRSContactSearchPortlet)