Back to index

plone3  3.1.7
info.py
Go to the documentation of this file.
00001 """
00002 $Id: base.py 1808 2007-02-06 11:39:11Z hazmat $
00003 """
00004 
00005 from zope.interface import implements
00006 
00007 from zope.viewlet.interfaces import IViewlet
00008 
00009 from DateTime import DateTime
00010 from AccessControl import getSecurityManager
00011 
00012 from Products.Five.browser import BrowserView
00013 from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
00014 from Products.CMFCore.permissions import ModifyPortalContent
00015 from Products.CMFCore.utils import getToolByName
00016 
00017 from plone.app.iterate.util import get_storage
00018 from plone.app.iterate.interfaces import keys
00019 
00020 from plone.app.iterate.relation import WorkingCopyRelation
00021 
00022 from plone.memoize.instance import memoize
00023 
00024 class BaseInfoViewlet( BrowserView ):
00025     
00026     implements( IViewlet )
00027     
00028     def __init__( self, context, request, view, manager ):
00029         super( BaseInfoViewlet, self ).__init__( context, request )
00030         self.__parent__ = view
00031         self.view = view
00032         self.manager = manager
00033         
00034     def update( self ):
00035         pass
00036     
00037     def render( self ):
00038         raise NotImplementedError
00039         
00040     @memoize
00041     def created( self ):
00042         time = self.properties.get( keys.checkout_time, DateTime() )
00043         util = getToolByName(self.context, 'translation_service')
00044         return util.ulocalized_time(time, None, self.context, domain='plonelocales')
00045 
00046     @memoize
00047     def creator( self ):
00048         user_id = self.properties.get( keys.checkout_user )
00049         membership = getToolByName(self.context, 'portal_membership')
00050         if not user_id:
00051             return membership.getAuthenticatedMember()
00052         return membership.getMemberById( user_id )
00053         
00054     @memoize
00055     def creator_url( self ):
00056         creator = self.creator()
00057         portal_url = getToolByName(self.context, 'portal_url')
00058         return "%s/author/%s" % ( portal_url(), creator.getId() )
00059         
00060     @memoize
00061     def creator_name( self ):
00062         creator = self.creator()
00063         return creator.getProperty('fullname') or creator.getId()
00064 
00065     @property
00066     @memoize
00067     def properties( self ):
00068         wc_ref = self._getReference()
00069         if wc_ref is not None:
00070             return get_storage( wc_ref )
00071         else:
00072             return {}
00073 
00074     def _getReference( self ):
00075         raise NotImplemented
00076         
00077 class BaselineInfoViewlet( BaseInfoViewlet ):
00078     
00079     template = ViewPageTemplateFile('info_baseline.pt')
00080 
00081     def render(self):
00082         if self.working_copy() is not None and \
00083             getSecurityManager().checkPermission(ModifyPortalContent, self.context):
00084             return self.template()
00085         else:
00086             return ""
00087 
00088     @memoize
00089     def working_copy( self ):
00090         refs = self.context.getBRefs( WorkingCopyRelation.relationship )
00091         if len( refs ) > 0:
00092             return refs[0]
00093         else:
00094             return None
00095 
00096     def _getReference( self ):
00097         refs = self.context.getBackReferenceImpl( WorkingCopyRelation.relationship )
00098         if len( refs ) > 0:
00099             return refs[0]
00100         else:
00101             return None
00102         
00103 class CheckoutInfoViewlet( BaseInfoViewlet ):
00104     
00105     template = ViewPageTemplateFile('info_checkout.pt')
00106     
00107     def render(self):
00108         if self.baseline() is not None and \
00109             getSecurityManager().checkPermission(ModifyPortalContent, self.context):
00110             return self.template()
00111         else:
00112             return ""
00113     
00114     @memoize
00115     def baseline( self ):
00116         refs = self.context.getReferences( WorkingCopyRelation.relationship )
00117         if len( refs ) > 0:
00118             return refs[0]
00119         else:
00120             return None
00121     
00122     def _getReference( self ):
00123         refs = self.context.getReferenceImpl( WorkingCopyRelation.relationship )
00124         if len( refs ) > 0:
00125             return refs[0]
00126         else:
00127             return None
00128