Changeset 3282 in products


Ignore:
Timestamp:
Sep 26, 2011 1:56:13 PM (13 years ago)
Author:
vmaksymiv
Message:

Added option to display portlet for anonymous users only

File:
1 edited

Legend:

Unmodified
Added
Removed
  • quintagroup.portlet.static/trunk/quintagroup/portlet/static/staticstylishportlet.py

    r2776 r3282  
    99from zope.formlib import form 
    1010from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile 
     11from Products.CMFCore.utils import getToolByName 
     12from Acquisition import aq_inner 
    1113 
    1214from quintagroup.portlet.static.utils import getVocabulary 
     
    2123    same. 
    2224    """ 
     25 
     26    anonymous_only = schema.Bool( 
     27        title=_(u"Anonymous only"), 
     28        description=_(u"Check this to hide the portlet for logged-in users."), 
     29        required=False, 
     30        default=False, 
     31        ) 
    2332 
    2433    styling = schema.Choice(title=_(u"Portlet style"), 
     
    4049 
    4150    styling = '' 
    42      
     51 
     52    anonymous_only = False 
     53 
    4354    def __init__(self, header=u"", text=u"", omit_border=False, footer=u"", 
    44                  more_url='', hide=False, styling=''): 
     55                 more_url='', hide=False, styling='', anonymous_only=False): 
    4556        super(Assignment, self).__init__(header=header, text=text, omit_border=omit_border, footer=footer, 
    4657                                         more_url=more_url) 
    47          
     58 
    4859        self.styling = styling 
    49      
     60        self.anonymous_only = anonymous_only 
     61 
    5062class Renderer(static.Renderer): 
    5163    """Portlet renderer. 
     
    5769 
    5870    render = ViewPageTemplateFile('staticstylishportlet.pt') 
     71 
     72    @property 
     73    def available(self): 
     74        if self.data.anonymous_only: 
     75            context = aq_inner(self.context) 
     76            mtool = getToolByName(context, 'portal_membership') 
     77            return mtool.isAnonymousUser() 
     78 
     79        return True 
    5980 
    6081 
Note: See TracChangeset for help on using the changeset viewer.