Back to index

plone3  3.1.7
Public Member Functions | Private Member Functions | Private Attributes
CMFPlone.browser.ploneview.Plone Class Reference
Inheritance diagram for CMFPlone.browser.ploneview.Plone:
Inheritance graph
[legend]
Collaboration diagram for CMFPlone.browser.ploneview.Plone:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def globalize
def __init__
def hide_columns
def toLocalizedTime
def visibleIdsEnabled
def prepareObjectTabs
def showEditableBorder
def displayContentsTab
def icons_visible
def getIcon
def normalizeString
def cropText
def keyFilteredActions
def getCurrentUrl
def isRightToLeft
def isDefaultPageInFolder
def isStructuralFolder
def navigationRootPath
def navigationRootUrl
def getParentObject
def getCurrentFolder
def getCurrentFolderUrl
def getCurrentObjectUrl
def isFolderOrFolderDefaultPage
def isPortalOrPortalDefaultPage
def getViewTemplateId
def have_portlets

Private Member Functions

def _initializeData

Private Attributes

 _data

Detailed Description

Definition at line 46 of file ploneview.py.


Constructor & Destructor Documentation

def CMFPlone.browser.ploneview.Plone.__init__ (   self,
  context,
  request 
)

Definition at line 72 of file ploneview.py.

00072 
00073     def __init__(self, context, request):
00074         super(Plone, self).__init__(context, request)
00075         self._data = {}


Member Function Documentation

def CMFPlone.browser.ploneview.Plone._initializeData (   self,
  options = None,
  view = None,
  template = None 
) [private]

Definition at line 76 of file ploneview.py.

00076 
00077     def _initializeData(self, options=None, view=None, template=None):
00078         # We don't want to do this in __init__ because the view provides
00079         # methods which are useful outside of globals.  Also, performing
00080         # actions during __init__ is dangerous because instances are usually
00081         # created during traversal, which means authentication hasn't yet
00082         # happened.
00083         context = aq_inner(self.context)
00084         if options is None:
00085             options = {}
00086         if view is None:
00087             view = self
00088 
00089         show_portlets = not options.get('no_portlets', False)
00090         def_actions = options.get('actions', None)
00091 
00092         # XXX: Can't store data as attributes directly because it will
00093         # insert the view into the acquisition chain. Someone should
00094         # come up with a way to prevent this or get rid of the globals
00095         # view altogether
00096 
00097         tools = getMultiAdapter((context, self.request), name=u'plone_tools')
00098         portal_state = getMultiAdapter((context, self.request), name=u'plone_portal_state')
00099         context_state = getMultiAdapter((context, self.request), name=u'plone_context_state')
00100 
00101         self._data['utool'] = utool = tools.url()
00102         self._data['portal'] = portal = portal_state.portal()
00103         self._data['portal_url'] =  portal_state.portal_url()
00104         self._data['mtool'] = mtool = tools.membership()
00105         self._data['atool'] = atool = tools.actions()
00106         self._data['putils'] = putils = getToolByName(context, "plone_utils")
00107         self._data['acl_users'] = getToolByName(context, 'acl_users')
00108         self._data['wtool'] = wtool = tools.workflow()
00109         self._data['ifacetool'] = tools.interface()
00110         self._data['syntool'] = tools.syndication()
00111         self._data['portal_title'] = portal_state.portal_title()
00112         self._data['object_title'] = context_state.object_title()
00113         self._data['checkPermission'] = checkPermission = mtool.checkPermission
00114         self._data['member'] = portal_state.member()
00115         self._data['membersfolder'] =  mtool.getMembersFolder()
00116         self._data['isAnon'] =  portal_state.anonymous()
00117         self._data['actions'] = actions = def_actions or context_state.actions()
00118         self._data['keyed_actions'] =  def_actions or context_state.keyed_actions()
00119         self._data['user_actions'] =  actions['user']
00120         self._data['workflow_actions'] =  actions['workflow']
00121         self._data['folder_actions'] =  actions['folder']
00122         self._data['global_actions'] =  actions['global']
00123 
00124         portal_tabs_view = getMultiAdapter((context, context.REQUEST), name='portal_tabs_view')
00125         self._data['portal_tabs'] =  portal_tabs_view.topLevelTabs(actions=actions)
00126 
00127         self._data['wf_state'] =  context_state.workflow_state()
00128         self._data['portal_properties'] = props = tools.properties()
00129         self._data['site_properties'] = site_props = props.site_properties
00130         self._data['ztu'] =  ZTUtils
00131         self._data['isFolderish'] =  context_state.is_folderish()
00132         
00133         self._data['sl'] = have_left_portlets = show_portlets and self.have_portlets('plone.leftcolumn', view)
00134         self._data['sr'] = have_right_portlets = show_portlets and self.have_portlets('plone.rightcolumn', view)
00135         self._data['hidecolumns'] =  self.hide_columns(have_left_portlets, have_right_portlets)
00136         
00137         self._data['here_url'] =  context_state.object_url()
00138         self._data['default_language'] = portal_state.default_language()
00139         self._data['language'] =  portal_state.language()
00140         self._data['is_editable'] = context_state.is_editable()
00141         self._data['isLocked'] = context_state.is_locked()
00142         self._data['isRTL'] =  portal_state.is_rtl()
00143         self._data['visible_ids'] =  self.visibleIdsEnabled() or None
00144         self._data['current_page_url'] =  context_state.current_page_url()
00145         self._data['normalizeString'] = putils.normalizeString
00146         self._data['toLocalizedTime'] = self.toLocalizedTime
00147         self._data['isStructuralFolder'] = context_state.is_structural_folder()
00148         self._data['isContextDefaultPage'] = context_state.is_default_page()
00149 
00150         self._data['navigation_root_url'] = portal_state.navigation_root_url()
00151         self._data['Iterator'] = utils.IndexIterator
00152         self._data['tabindex'] = utils.IndexIterator(pos=30000, mainSlot=False)
00153         self._data['uniqueItemIndex'] = utils.RealIndexIterator(pos=0)
00154 
00155         template_id = options.get('template_id', None)
00156         if template_id is None and template is not None:
00157             template_id = template.getId()
00158         self._data['template_id'] = template_id
00159         
00160         isViewTemplate = context_state.is_view_template()
00161         if isViewTemplate and not IViewView.providedBy(view):
00162             # Mark the view as being "the" view
00163             alsoProvides(view, IViewView)
00164             
00165         self._data['isViewTemplate'] = isViewTemplate

Here is the call graph for this function:

Here is the caller graph for this function:

def CMFPlone.browser.ploneview.Plone.cropText (   self,
  text,
  length,
  ellipsis = '...' 
)
Crop text on a word boundary

Definition at line 417 of file ploneview.py.

00417 
00418     def cropText(self, text, length, ellipsis='...'):
00419         """Crop text on a word boundary
00420         """
00421         converted = False
00422         if not isinstance(text, unicode):
00423             encoding = utils.getSiteEncoding(aq_inner(self.context))
00424             text = unicode(text, encoding)
00425             converted = True
00426         if len(text)>length:
00427             text = text[:length]
00428             l = text.rfind(' ')
00429             if l > length/2:
00430                 text = text[:l+1]
00431             text += ellipsis
00432         if converted:
00433             # encode back from unicode
00434             text = text.encode(encoding)
00435         return text

Here is the call graph for this function:

Whether or not the contents tabs should be displayed

Definition at line 340 of file ploneview.py.

00340 
00341     def displayContentsTab(self):
00342         """Whether or not the contents tabs should be displayed
00343         """
00344         context = aq_inner(self.context)
00345         modification_permissions = (ModifyPortalContent,
00346                                     AddPortalContent,
00347                                     DeleteObjects,
00348                                     ReviewPortalContent)
00349 
00350         contents_object = context
00351         # If this object is the parent folder's default page, then the
00352         # folder_contents action is for the parent, we check permissions
00353         # there. Otherwise, if the object is not folderish, we don not display
00354         # the tab.
00355         if self.isDefaultPageInFolder():
00356             contents_object = self.getCurrentFolder()
00357         elif not self.isStructuralFolder():
00358             return 0
00359 
00360         # If this is not a structural folder, stop.
00361         plone_view = getMultiAdapter((contents_object, self.request),
00362                                      name='plone')
00363         if not plone_view.isStructuralFolder():
00364             return 0
00365 
00366         show = 0
00367         # We only want to show the 'contents' action under the following
00368         # conditions:
00369         # - If you have permission to list the contents of the relavant
00370         #   object, and you can DO SOMETHING in a folder_contents view. i.e.
00371         #   Copy or Move, or Modify portal content, Add portal content,
00372         #   or Delete objects.
00373 
00374         # Require 'List folder contents' on the current object
00375         if _checkPermission(ListFolderContents, contents_object):
00376             # If any modifications are allowed on object show the tab.
00377             for permission in modification_permissions:
00378                 if _checkPermission(permission, contents_object):
00379                     show = 1
00380                     break
00381 
00382         return show

Here is the call graph for this function:

Definition at line 477 of file ploneview.py.

00477 
00478     def getCurrentFolder(self):
00479         context_state = getMultiAdapter((aq_inner(self.context), self.request), name=u'plone_context_state')
00480         return context_state.folder()

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 481 of file ploneview.py.

00481 
00482     def getCurrentFolderUrl(self):
00483         context_state = getMultiAdapter((aq_inner(self.context), self.request), name=u'plone_context_state')
00484         return context_state.folder().absolute_url()

Here is the call graph for this function:

Definition at line 486 of file ploneview.py.

00486 
00487     def getCurrentObjectUrl(self):
00488         context_state = getMultiAdapter((aq_inner(self.context), self.request), name=u'plone_context_state')
00489         return context_state.canonical_object_url()

Here is the call graph for this function:

Definition at line 446 of file ploneview.py.

00446 
00447     def getCurrentUrl(self):
00448         context_state = getMultiAdapter((aq_inner(self.context), self.request), name=u'plone_context_state')
00449         return context_state.current_page_url()

Here is the call graph for this function:

def CMFPlone.browser.ploneview.Plone.getIcon (   self,
  item 
)
Returns an object which implements the IContentIcon interface and
   provides the informations necessary to render an icon.
   The item parameter needs to be adaptable to IContentIcon.
   Icons can be disabled globally or just for anonymous users with
   the icon_visibility property in site_properties.

Definition at line 399 of file ploneview.py.

00399 
00400     def getIcon(self, item):
00401         """Returns an object which implements the IContentIcon interface and
00402            provides the informations necessary to render an icon.
00403            The item parameter needs to be adaptable to IContentIcon.
00404            Icons can be disabled globally or just for anonymous users with
00405            the icon_visibility property in site_properties."""
00406         context = aq_inner(self.context)
00407         if not self.icons_visible():
00408             icon = getMultiAdapter((context, self.request, None), IContentIcon)
00409         else:
00410             icon = getMultiAdapter((context, self.request, item), IContentIcon)
00411         return icon

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 473 of file ploneview.py.

00473 
00474     def getParentObject(self):
00475         context_state = getMultiAdapter((aq_inner(self.context), self.request), name=u'plone_context_state')
00476         return context_state.parent()

Here is the call graph for this function:

Definition at line 501 of file ploneview.py.

00501 
00502     def getViewTemplateId(self):
00503         context_state = getMultiAdapter((aq_inner(self.context), self.request), name=u'plone_context_state')
00504         return context_state.view_template_id()

Here is the call graph for this function:

Pure optimization hack, globalizes entire view for speed. Yes
it's evil, but this hack will eventually be removed after
globals are officially deprecated.

YOU CAN ONLY CALL THIS METHOD FROM A PAGE TEMPLATE AND EVEN
THEN IT MIGHT DESTROY YOU!

Definition at line 49 of file ploneview.py.

00049 
00050     def globalize(self):
00051         """
00052         Pure optimization hack, globalizes entire view for speed. Yes
00053         it's evil, but this hack will eventually be removed after
00054         globals are officially deprecated.
00055 
00056         YOU CAN ONLY CALL THIS METHOD FROM A PAGE TEMPLATE AND EVEN
00057         THEN IT MIGHT DESTROY YOU!
00058         """
00059         context = sys._getframe(2).f_locals['econtext']
00060         # Some of the original global_defines used 'options' to get parameters
00061         # passed in through the template call, so we need this to support
00062         # products which may have used this little hack
00063         options = context.vars.get('options',{})
00064         view = context.vars.get('view', None)
00065         template = context.vars.get('template', None)
00066 
00067         state = {}
00068         self._initializeData(options=options, view=view, template=template)
00069         for name, v in self._data.items():
00070             state[name] = v
00071             context.setGlobal(name, v)

Here is the call graph for this function:

def CMFPlone.browser.ploneview.Plone.have_portlets (   self,
  manager_name,
  view = None 
)
Determine whether a column should be shown.
The left column is called plone.leftcolumn; the right column is called
plone.rightcolumn. Custom skins may have more portlet managers defined
(see portlets.xml).

Definition at line 506 of file ploneview.py.

00506 
00507     def have_portlets(self, manager_name, view=None):
00508         """Determine whether a column should be shown.
00509         The left column is called plone.leftcolumn; the right column is called
00510         plone.rightcolumn. Custom skins may have more portlet managers defined
00511         (see portlets.xml).
00512         """
00513         
00514         context = aq_inner(self.context)
00515         if view is None:
00516             view = self
00517 
00518         manager = getUtility(IPortletManager, name=manager_name)
00519         renderer = queryMultiAdapter((context, self.request, view, manager), IPortletManagerRenderer)
00520         if renderer is None:
00521             renderer = getMultiAdapter((context, self.request, self, manager), IPortletManagerRenderer)
00522 
00523         return renderer.visible

Here is the call graph for this function:

Here is the caller graph for this function:

def CMFPlone.browser.ploneview.Plone.hide_columns (   self,
  column_left,
  column_right 
)

Definition at line 167 of file ploneview.py.

00167 
00168     def hide_columns(self, column_left, column_right):
00169         if not column_right and not column_left:
00170             return "visualColumnHideOneTwo"
00171         if column_right and not column_left:
00172             return "visualColumnHideOne"
00173         if not column_right and column_left:
00174             return "visualColumnHideTwo"
00175         return "visualColumnHideNone"

Here is the caller graph for this function:

Definition at line 384 of file ploneview.py.

00384 
00385     def icons_visible(self):
00386         context = aq_inner(self.context)
00387         membership = getToolByName(context, "portal_membership")
00388         properties = getToolByName(context, "portal_properties")
00389 
00390         site_properties = getattr(properties, 'site_properties')
00391         icon_visibility = site_properties.getProperty('icon_visibility', 'enabled')
00392 
00393         if icon_visibility == 'enabled':
00394             return True
00395         elif icon_visibility == 'authenticated' and not membership.isAnonymousUser():
00396             return True
00397         else:
00398             return False

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 457 of file ploneview.py.

00457 
00458     def isDefaultPageInFolder(self):
00459         context_state = getMultiAdapter((aq_inner(self.context), self.request), name=u'plone_context_state')
00460         return context_state.is_default_page()

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 491 of file ploneview.py.

00491 
00492     def isFolderOrFolderDefaultPage(self):
00493         context_state = getMultiAdapter((aq_inner(self.context), self.request), name=u'plone_context_state')
00494         return context_state.is_structural_folder() or context_state.is_default_page()

Here is the call graph for this function:

Definition at line 496 of file ploneview.py.

00496 
00497     def isPortalOrPortalDefaultPage(self):
00498         context_state = getMultiAdapter((aq_inner(self.context), self.request), name=u'plone_context_state')
00499         return context_state.is_portal_root()
        

Here is the call graph for this function:

def CMFPlone.browser.ploneview.Plone.isRightToLeft (   self,
  domain = 'plone' 
)

Definition at line 453 of file ploneview.py.

00453 
00454     def isRightToLeft(self, domain='plone'):
00455         portal_state = getMultiAdapter((aq_inner(self.context), self.request), name=u'plone_portal_state')
00456         return portal_state.is_rtl()

Here is the call graph for this function:

Definition at line 461 of file ploneview.py.

00461 
00462     def isStructuralFolder(self):
00463         context_state = getMultiAdapter((aq_inner(self.context), self.request), name=u'plone_context_state')
00464         return context_state.is_structural_folder()

Here is the call graph for this function:

Here is the caller graph for this function:

def CMFPlone.browser.ploneview.Plone.keyFilteredActions (   self,
  actions = None 
)

Definition at line 442 of file ploneview.py.

00442 
00443     def keyFilteredActions(self, actions=None):
00444         context_state = getMultiAdapter((aq_inner(self.context), self.request), name=u'plone_context_state')
00445         return context_state.keyed_actions()

Here is the call graph for this function:

Definition at line 465 of file ploneview.py.

00465 
00466     def navigationRootPath(self):
00467         portal_state = getMultiAdapter((aq_inner(self.context), self.request), name=u'plone_portal_state')
00468         return portal_state.navigation_root_path()

Here is the call graph for this function:

Definition at line 469 of file ploneview.py.

00469 
00470     def navigationRootUrl(self):
00471         portal_state = getMultiAdapter((aq_inner(self.context), self.request), name=u'plone_portal_state')
00472         return portal_state.navigation_root_url()

Here is the call graph for this function:

def CMFPlone.browser.ploneview.Plone.normalizeString (   self,
  text,
  relaxed = False 
)
Normalizes a title to an id.

Definition at line 412 of file ploneview.py.

00412 
00413     def normalizeString(self, text, relaxed=False):
00414         """Normalizes a title to an id.
00415         """
00416         return utils.normalizeString(text, context=self, relaxed=relaxed)

def CMFPlone.browser.ploneview.Plone.prepareObjectTabs (   self,
  default_tab = 'view',
  sort_first = ['folderContents'] 
)
Prepare the object tabs by determining their order and working
out which tab is selected. Used in global_contentviews.pt

Definition at line 205 of file ploneview.py.

00205 
00206     def prepareObjectTabs(self, default_tab='view', sort_first=['folderContents']):
00207         """Prepare the object tabs by determining their order and working
00208         out which tab is selected. Used in global_contentviews.pt
00209         """
00210         context = aq_inner(self.context)
00211         context_url = context.absolute_url()
00212         context_fti = context.getTypeInfo()
00213         
00214         site_properties = getToolByName(context, "portal_properties").site_properties
00215 
00216         context_state = getMultiAdapter((context, self.request), name=u'plone_context_state')
00217         actions = context_state.actions()
00218 
00219         action_list = []
00220         if context_state.is_structural_folder():
00221             action_list = actions['folder'] + actions['object']
00222         else:
00223             action_list = actions['object']
00224 
00225         tabs = []
00226         
00227         found_selected = False
00228         fallback_action = None
00229 
00230         request_url = self.request['ACTUAL_URL']
00231         request_url_path = request_url[len(context_url):]
00232         
00233         if request_url_path.startswith('/'):
00234             request_url_path = request_url_path[1:]
00235 
00236         for action in action_list:
00237             
00238             item = {'title'    : action['title'],
00239                     'id'       : action['id'],
00240                     'url'      : '',
00241                     'selected' : False}
00242 
00243             action_url = action['url'].strip()
00244             if action_url.startswith('http') or action_url.startswith('javascript'):
00245                 item['url'] = action_url
00246             else:
00247                 item['url'] = '%s/%s'%(context_url, action_url)
00248 
00249             action_method = item['url'].split('/')[-1]
00250 
00251             # Action method may be a method alias: Attempt to resolve to a template.
00252             action_method = context_fti.queryMethodID(action_method, default=action_method)
00253             if action_method:
00254                 request_action = unquote(request_url_path)
00255                 request_action = context_fti.queryMethodID(request_action, default=request_action)
00256     
00257                 if action_method == request_action:
00258                     item['selected'] = True
00259                     found_selected = True
00260 
00261             current_id = item['id']
00262             if current_id == default_tab:
00263                 fallback_action = item
00264 
00265             tabs.append(item)
00266 
00267         if not found_selected and fallback_action is not None:
00268             fallback_action['selected'] = True
00269 
00270         def sortOrder(tab):
00271             try:
00272                 return sort_first.index(tab['id'])
00273             except ValueError:
00274                 return 255
00275 
00276         tabs.sort(key=sortOrder)
00277         return tabs

Here is the call graph for this function:

Determine if the editable border should be shown

Definition at line 283 of file ploneview.py.

00283 
00284     def showEditableBorder(self):
00285         """Determine if the editable border should be shown
00286         """
00287         request = self.request
00288         
00289         if request.has_key('disable_border'): #short circuit
00290             return False
00291         if request.has_key('enable_border'): #short circuit
00292             return True
00293         
00294         context = aq_inner(self.context)
00295         
00296         portal_membership = getToolByName(context, 'portal_membership')
00297         checkPerm = portal_membership.checkPermission
00298 
00299         if checkPerm('Modify portal content', context) or \
00300                checkPerm('Add portal content', context)  or \
00301                checkPerm('Review portal content', context):
00302             return True
00303 
00304         if portal_membership.isAnonymousUser():
00305             return False
00306 
00307         context_state = getMultiAdapter((context, request), name="plone_context_state")
00308         actions = context_state.actions()
00309             
00310         if actions.get('workflow', ()):
00311             return True
00312 
00313         if actions.get('batch', []):
00314             return True
00315             
00316         for action in actions.get('object', []):
00317             if action.get('id', '') != 'view':
00318                 return True
00319 
00320         template_id = self._data.get('template_id', None)
00321         if template_id is None and 'PUBLISHED' in request:
00322             if hasattr(request['PUBLISHED'], 'getId'):
00323                 template_id=request['PUBLISHED'].getId()
00324 
00325         idActions = {}
00326         for obj in actions.get('object', ()) + actions.get('folder', ()):
00327             idActions[obj.get('id', '')] = 1
00328 
00329         if idActions.has_key('edit'):
00330             if (idActions.has_key(template_id) or \
00331                 template_id in ['synPropertiesForm', 'folder_contents', 'folder_listing']) :
00332                 return True
00333 
00334         # Check to see if the user is able to add content or change workflow state
00335         if _allowedTypes(request, context):
00336             return True
00337 
00338         return False
    

Here is the call graph for this function:

def CMFPlone.browser.ploneview.Plone.toLocalizedTime (   self,
  time,
  long_format = None 
)
Convert time to localized time

Definition at line 178 of file ploneview.py.

00178 
00179     def toLocalizedTime(self, time, long_format=None):
00180         """Convert time to localized time
00181         """
00182         context = aq_inner(self.context)
00183         util = getToolByName(context, 'translation_service')
00184         return util.ulocalized_time(time, long_format, context=context,
00185                                     domain='plonelocales', request=self.request)
    

Here is the call graph for this function:

Here is the caller graph for this function:

Determine if visible ids are enabled

Definition at line 187 of file ploneview.py.

00187 
00188     def visibleIdsEnabled(self):
00189         """Determine if visible ids are enabled
00190         """
00191         context = aq_inner(self.context)
00192         props = getToolByName(context, "portal_properties").site_properties
00193         if not props.getProperty('visible_ids', False):
00194             return False
00195 
00196         pm = getToolByName(context, "portal_membership")
00197         if pm.isAnonymousUser():
00198             return False
00199 
00200         user = pm.getAuthenticatedMember()
00201         if user is not None:
00202             return user.getProperty('visible_ids', False)
00203         return False
    

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 74 of file ploneview.py.


The documentation for this class was generated from the following file: