source: cmfdeployment/branches/kenw-p4-wip/ExpressionContainer.py @ 2380

Last change on this file since 2380 was 2380, checked in by kenw, 8 years ago

Committing new branch intended for Plone 4 compatibility; mostly required imports of new zope packages

File size: 3.3 KB
Line 
1##################################################################
2#
3# (C) Copyright 2002-2006 Kapil Thangavelu <k_vertigo@objectrealms.net>
4# All Rights Reserved
5#
6# This file is part of CMFDeployment.
7#
8# CMFDeployment is free software; you can redistribute it and/or modify
9# it under the terms of the GNU General Public License as published by
10# the Free Software Foundation; either version 2 of the License, or
11# (at your option) any later version.
12#
13# CMFDeployment is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16# GNU General Public License for more details.
17#
18# You should have received a copy of the GNU General Public License
19# along with CMFDeployment; if not, write to the Free Software
20# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21##################################################################
22"""
23Purpose: utilize ordered folder if available to provide for
24          explicit ordering of expressions (filter, mime).
25Author: kapil thangavelu <k_vertigo@objectrealms.net>
26$Id: ExpressionContainer.py 1955 2007-05-11 07:07:58Z hazmat $
27"""
28
29from OFS.OrderedFolder import OrderedFolder
30from Products.PageTemplates.Expressions import SecureModuleImporter, getEngine
31from Products.CMFCore.WorkflowCore import WorkflowException
32from Namespace import Implicit, ClassSecurityInfo, InitializeClass, getToolByName
33import utils
34
35class ExpressionContainer(OrderedFolder):
36    pass
37
38def getDeployExprContext(object, portal):
39   
40    data = {
41        'object':       object,
42        'portal':       portal,
43        'nothing':      None,
44        'request':      getattr( object, 'REQUEST', None ),
45        'modules':      SecureModuleImporter,
46        'deploy':       DeploymentMimeUtilities.__of__(object)
47        }
48
49    return getEngine().getContext(data)   
50   
51class MimeUtilities(Implicit):
52
53    security = ClassSecurityInfo()
54    security.declareObjectPublic()
55   
56    __allow_access_to_unprotected_subobjects__ = 1
57
58    def has_index(self, obj):
59        return not not getattr(aq_base(obj), 'index_html', None)
60
61    def match_state( self, obj, state):
62        wf_tool = getToolByName( obj, 'portal_workflow')
63        try:
64            wf_state = wf_tool.getInfoFor( obj, 'review_state')
65        except WorkflowException:
66            return False
67        return wf_state== state
68
69InitializeClass(MimeUtilities)
70DeploymentMimeUtilities = MimeUtilities()
71
72def registerDeploymentExprMethod(name, context_method):
73    assert isinstance(name, str)
74    assert not DeploymentMimeUtilities.__dict__.has_key(name),"duplicate registration %s"%name           
75    DeploymentMimeUtilities.__dict__[name]=context_method
76
77# allowing for binding rendering methods to particular args in tales
78registerDeploymentExprMethod( "bind", utils.bind )
79
80# allow for safely traversing in an expression even if something doesn't exist  (returns None)
81registerDeploymentExprMethod( "safe_traverse", utils.safe_traverse )
82
83# event util method  for plone 2.1, to work around bad apis in atct
84if utils.event_ics_view is not None:
85    registerDeploymentExprMethod( "event_ics_view", utils.event_ics_view )
86
87if utils.event_vcs_view is not None:
88    registerDeploymentExprMethod( "event_vcs_view", utils.event_vcs_view )
89
Note: See TracBrowser for help on using the repository browser.