Back to index

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

List of all members.

Public Member Functions

def docs
def getFactoryTypes
def manage_setPortalFactoryTypes
def doCreate
def isTemporary
def __before_publishing_traverse__
def __bobo_traverse__
def __call__

Static Public Attributes

string id = 'portal_factory'
string meta_type = 'Plone Factory Tool'
string toolicon = 'skins/plone_images/add_icon.gif'
tuple security = ClassSecurityInfo()
int isPrincipiaFolderish = 0
tuple manage_options
tuple manage_overview = PageTemplateFile('www/portal_factory_manage_overview', globals())
tuple manage_portal_factory_types = PageTemplateFile(os.path.join('www', 'portal_factory_manage_types'), globals())
 manage_main = manage_overview
tuple manage_docs = PageTemplateFile(os.path.join('www','portal_factory_manage_docs'), globals())
tuple wwwpath = os.path.join(Globals.package_home(cmfplone_globals), 'www')
tuple f = open(os.path.join(wwwpath, 'portal_factory_docs.stx'), 'r')
 index_html = None

Private Member Functions

def _fixRequest
def _getTempFolder

Private Attributes

 _factory_types
 _p_changed

Static Private Attributes

tuple __implements__ = (PloneBaseTool.__implements__, SimpleItem.__implements__, )
tuple _docs = f.read()

Detailed Description

Definition at line 180 of file FactoryTool.py.


Member Function Documentation

def CMFPlone.FactoryTool.FactoryTool.__before_publishing_traverse__ (   self,
  other,
  REQUEST 
)

Definition at line 303 of file FactoryTool.py.

00303 
00304     def __before_publishing_traverse__(self, other, REQUEST):
00305         if REQUEST.get(FACTORY_INFO, None):
00306             del REQUEST[FACTORY_INFO]
00307 
00308         stack = REQUEST.get('TraversalRequestNameStack')
00309         stack = [str(s) for s in stack]  # convert from unicode if necessary (happens in Epoz for some weird reason)
00310         # need 2 more things on the stack at least for portal_factory to kick in:
00311         #    (1) a type, and (2) an id
00312         if len(stack) < 2: # ignore
00313             return
00314         type_name = stack[-1]
00315         types_tool = getToolByName(self, 'portal_types')
00316         # make sure this is really a type name
00317         if not type_name in types_tool.listContentTypes():
00318             return # nope -- do nothing
00319 
00320         id = stack[-2]
00321         intended_parent = aq_parent(self)
00322         if hasattr(intended_parent, id):
00323             return # do normal traversal via __bobo_traverse__
00324 
00325         # about to create an object - further traversal will be prevented
00326         #
00327         # before halting traversal, check for method aliases
00328         # stack should be [...optional stuff..., id, type_name]
00329         key = stack and stack[-3] or '(Default)'
00330         ti = types_tool.getTypeInfo(type_name)
00331         method_id = ti and ti.queryMethodID(key)
00332         if method_id:
00333             if key != '(Default)':
00334                 del(stack[-3])
00335             if method_id != '(Default)':
00336                 stack.insert(-2, method_id)
00337             REQUEST._hacked_path = 1
00338         
00339         stack.reverse()
00340         factory_info = {'stack':stack}
00341         REQUEST.set(FACTORY_INFO, factory_info)
00342         REQUEST.set('TraversalRequestNameStack', [])

Here is the call graph for this function:

def CMFPlone.FactoryTool.FactoryTool.__bobo_traverse__ (   self,
  REQUEST,
  name 
)

Definition at line 343 of file FactoryTool.py.

00343 
00344     def __bobo_traverse__(self, REQUEST, name):
00345         # __bobo_traverse__ can be invoked directly by a restricted_traverse method call
00346         # in which case the traversal stack will not have been cleared by __before_publishing_traverse__
00347         name = str(name) # fix unicode weirdness
00348         types_tool = getToolByName(self, 'portal_types')
00349         if not name in types_tool.listContentTypes():
00350             return getattr(self, name) # not a type name -- do the standard thing
00351         return self._getTempFolder(str(name)) # a type name -- return a temp folder

Here is the call graph for this function:

def CMFPlone.FactoryTool.FactoryTool.__call__ (   self,
  args,
  kwargs 
)
call method

Definition at line 353 of file FactoryTool.py.

00353 
00354     def __call__(self, *args, **kwargs):
00355         """call method"""
00356         self._fixRequest()
00357         factory_info = self.REQUEST.get(FACTORY_INFO, {})
00358         stack = factory_info['stack']
00359         type_name = stack[0]
00360         id = stack[1]
00361 
00362         # do a passthrough if parent contains the id
00363         if id in aq_parent(self).objectIds():
00364             return aq_parent(self).restrictedTraverse('/'.join(stack[1:]))(*args, **kwargs)
00365 
00366         tempFolder = self._getTempFolder(type_name)
00367         # Mysterious hack that fixes some problematic interactions with SpeedPack:
00368         #   Get the first item in the stack by explicitly calling __getitem__
00369         temp_obj = tempFolder.__getitem__(id)
00370         stack = stack[2:]
00371         if stack:
00372             obj = temp_obj.restrictedTraverse('/'.join(stack))
00373         else:
00374             obj = temp_obj
00375         return mapply(obj, self.REQUEST.args, self.REQUEST,
00376                                call_object, 1, missing_name, dont_publish_class,
00377                                self.REQUEST, bind=1)

Here is the call graph for this function:

Here is the caller graph for this function:

Our before_publishing_traverse call mangles URL0.  This fixes up
the REQUEST.

Definition at line 274 of file FactoryTool.py.

00274 
00275     def _fixRequest(self):
00276         """Our before_publishing_traverse call mangles URL0.  This fixes up
00277         the REQUEST."""
00278         factory_info = self.REQUEST.get(FACTORY_INFO, None)
00279         if not factory_info:
00280             return
00281         stack = factory_info['stack']
00282         URL = self.REQUEST.URL0 + '/' + '/'.join(stack)
00283         self.REQUEST.set('URL', URL)
00284 
00285         url_list = URL.split('/')
00286         n = 0
00287         while len(url_list) > 0 and url_list[-1] != '':
00288             self.REQUEST.set('URL%d' % n, '/'.join(url_list))
00289             url_list = url_list[:-1]
00290             n = n + 1
00291 
00292         url_list = URL.split('/')
00293         m = 0
00294         while m < n:
00295             self.REQUEST.set('BASE%d' % m, '/'.join(url_list[0:len(url_list)-n+1+m]))
00296             m = m + 1
00297         # TODO fix URLPATHn, BASEPATHn here too

Here is the caller graph for this function:

def CMFPlone.FactoryTool.FactoryTool._getTempFolder (   self,
  type_name 
) [private]

Definition at line 380 of file FactoryTool.py.

00380 
00381     def _getTempFolder(self, type_name):
00382         
00383         factory_info = self.REQUEST.get(FACTORY_INFO, {})
00384         tempFolder = factory_info.get(type_name, None)
00385         if tempFolder:
00386             tempFolder = aq_inner(tempFolder).__of__(self)
00387             return tempFolder
00388         
00389         # make sure we can add an object of this type to the temp folder
00390         types_tool = getToolByName(self, 'portal_types')
00391         if not type_name in types_tool.TempFolder.allowed_content_types:
00392             # update allowed types for tempfolder
00393             types_tool.TempFolder.allowed_content_types=(types_tool.listContentTypes())
00394             
00395         tempFolder = TempFolder(type_name).__of__(self)
00396         intended_parent = aq_parent(self)
00397         portal = getToolByName(self, 'portal_url').getPortalObject()
00398         folder_roles = {} # mapping from permission name to list or tuple of roles
00399                           # list if perm is acquired; tuple if not
00400         n_acquired = 0    # number of permissions that are acquired
00401 
00402         # build initial folder_roles dictionary
00403         for p in intended_parent.ac_inherited_permissions(1):
00404             name, value = p[:2]
00405             p=Permission(name,value,intended_parent)
00406             roles = p.getRoles()
00407             folder_roles[name] = roles
00408             if isinstance(roles, list):
00409                 n_acquired += 1
00410 
00411         # If intended_parent is not the portal, walk up the acquisition hierarchy and
00412         # acquire permissions explicitly so we can assign the acquired version to the
00413         # temp_folder.  In addition to being cumbersome, this is undoubtedly very slow.
00414         if intended_parent != portal:
00415             parent = aq_parent(aq_inner(intended_parent))
00416             while(n_acquired and parent!=portal):
00417                 n_acquired = 0
00418                 for p in parent.ac_inherited_permissions(1):
00419                     name, value = p[:2]
00420                     roles = folder_roles[name]
00421                     if isinstance(roles, list):
00422                         p=Permission(name,value,parent)
00423                         aq_roles=p.getRoles()
00424                         for r in aq_roles:
00425                             if not r in roles:
00426                                 roles.append(r)
00427                         if isinstance(aq_roles, list):
00428                             n_acquired += 1
00429                         else:
00430                             roles = tuple(roles)
00431                         folder_roles[name] = roles
00432                 parent = aq_parent(aq_inner(parent))
00433         for name, roles in folder_roles.items():
00434             tempFolder.manage_permission(name, roles, acquire=isinstance(roles, list))
00435 
00436         factory_info[type_name] = tempFolder
00437         self.REQUEST.set(FACTORY_INFO, factory_info)
00438         return tempFolder
00439 
00440 Globals.InitializeClass(FactoryTool)

Here is the call graph for this function:

Here is the caller graph for this function:

def CMFPlone.FactoryTool.FactoryTool.doCreate (   self,
  obj,
  id = None,
  kw 
)
Create a real object from a temporary object.

Definition at line 249 of file FactoryTool.py.

00249 
00250     def doCreate(self, obj, id=None, **kw):
00251         """Create a real object from a temporary object."""
00252         if self.isTemporary(obj=obj):
00253             if id is not None:
00254                 id = id.strip()
00255             if not id:
00256                 if hasattr(obj, 'getId') and callable(getattr(obj, 'getId')):
00257                     id = obj.getId()
00258                 else:
00259                     id = getattr(obj, 'id', None)
00260             type_name = aq_parent(aq_inner(obj)).id  # get the ID of the TempFolder
00261             folder = aq_parent(aq_parent(aq_parent(aq_inner(obj))))
00262             folder.invokeFactory(id=id, type_name=type_name)
00263             obj = getattr(folder, id)
00264 
00265             # give ownership to currently authenticated member if not anonymous
00266             # TODO is this necessary?
00267             membership_tool = getToolByName(self, 'portal_membership')
00268             if not membership_tool.isAnonymousUser():
00269                 member = membership_tool.getAuthenticatedMember()
00270                 obj.changeOwnership(member.getUser(), 1)
00271             if hasattr(aq_base(obj), 'manage_afterPortalFactoryCreate'):
00272                 obj.manage_afterPortalFactoryCreate()
00273         return obj

Here is the call graph for this function:

Returns FactoryTool docs formatted as HTML

Definition at line 220 of file FactoryTool.py.

00220 
00221     def docs(self):
00222         """Returns FactoryTool docs formatted as HTML"""
00223         return self._docs

Definition at line 224 of file FactoryTool.py.

00224 
00225     def getFactoryTypes(self):
00226         if not hasattr(self, '_factory_types'):
00227             self._factory_types = {}
00228         return self._factory_types

Check to see if an object is temporary

Definition at line 298 of file FactoryTool.py.

00298 
00299     def isTemporary(self, obj):
00300         """Check to see if an object is temporary"""
00301         ob = aq_base(aq_parent(aq_inner(obj)))
00302         return hasattr(ob, 'meta_type') and ob.meta_type == TempFolder.meta_type

Here is the caller graph for this function:

def CMFPlone.FactoryTool.FactoryTool.manage_setPortalFactoryTypes (   self,
  REQUEST = None,
  listOfTypeIds = None 
)
Set the portal types that should use the factory.

Definition at line 230 of file FactoryTool.py.

00230 
00231     def manage_setPortalFactoryTypes(self, REQUEST=None, listOfTypeIds=None):
00232         """Set the portal types that should use the factory."""
00233         if listOfTypeIds is not None:
00234             dict = {}
00235             for l in listOfTypeIds:
00236                 dict[l] = 1
00237         elif REQUEST is not None:
00238             dict = REQUEST.form
00239         if dict is None:
00240             dict = {}
00241         self._factory_types = {}
00242         types_tool = getToolByName(self, 'portal_types')
00243         for t in types_tool.listContentTypes():
00244             if dict.has_key(t):
00245                 self._factory_types[t] = 1
00246         self._p_changed = 1
00247         if REQUEST:
00248             REQUEST.RESPONSE.redirect('manage_main')

Here is the call graph for this function:


Member Data Documentation

tuple CMFPlone.FactoryTool.FactoryTool.__implements__ = (PloneBaseTool.__implements__, SimpleItem.__implements__, ) [static, private]

Definition at line 190 of file FactoryTool.py.

tuple CMFPlone.FactoryTool.FactoryTool._docs = f.read() [static, private]

Definition at line 215 of file FactoryTool.py.

Definition at line 226 of file FactoryTool.py.

Definition at line 245 of file FactoryTool.py.

tuple CMFPlone.FactoryTool.FactoryTool.f = open(os.path.join(wwwpath, 'portal_factory_docs.stx'), 'r') [static]

Definition at line 214 of file FactoryTool.py.

string CMFPlone.FactoryTool.FactoryTool.id = 'portal_factory' [static]

Definition at line 182 of file FactoryTool.py.

Definition at line 378 of file FactoryTool.py.

Definition at line 186 of file FactoryTool.py.

tuple CMFPlone.FactoryTool.FactoryTool.manage_docs = PageTemplateFile(os.path.join('www','portal_factory_manage_docs'), globals()) [static]

Definition at line 210 of file FactoryTool.py.

Definition at line 207 of file FactoryTool.py.

Initial value:
( ({'label':'Overview', 'action':'manage_overview'}, \
                        {'label':'Documentation', 'action':'manage_docs'}, \
                        {'label':'Factory Types', 'action':'manage_portal_factory_types'},) +
                       SimpleItem.manage_options)

Definition at line 192 of file FactoryTool.py.

tuple CMFPlone.FactoryTool.FactoryTool.manage_overview = PageTemplateFile('www/portal_factory_manage_overview', globals()) [static]

Definition at line 198 of file FactoryTool.py.

tuple CMFPlone.FactoryTool.FactoryTool.manage_portal_factory_types = PageTemplateFile(os.path.join('www', 'portal_factory_manage_types'), globals()) [static]

Definition at line 203 of file FactoryTool.py.

string CMFPlone.FactoryTool.FactoryTool.meta_type = 'Plone Factory Tool' [static]

Definition at line 183 of file FactoryTool.py.

tuple CMFPlone.FactoryTool.FactoryTool.security = ClassSecurityInfo() [static]

Definition at line 185 of file FactoryTool.py.

string CMFPlone.FactoryTool.FactoryTool.toolicon = 'skins/plone_images/add_icon.gif' [static]

Definition at line 184 of file FactoryTool.py.

tuple CMFPlone.FactoryTool.FactoryTool.wwwpath = os.path.join(Globals.package_home(cmfplone_globals), 'www') [static]

Definition at line 213 of file FactoryTool.py.


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