Back to index

plone3  3.1.7
Classes | Functions | Variables
Archetypes.ArchetypeTool Namespace Reference

Classes

class  BoundPageTemplateFile
class  WidgetWrapper
class  ArchetypeTool

Functions

def getCMFVersion
def fixActionsForType
def modify_fti
def process_types
def _guessPackage
def registerType
def fixAfterRenameType
def registerClasses
def listTypes
def getType

Variables

tuple _www = os.path.join(os.path.dirname(__file__), 'www')
tuple _skins = os.path.join(os.path.dirname(__file__), 'skins')
tuple _zmi = os.path.join(_www, 'zmi')
tuple document_icon = os.path.join(_zmi, 'icons', 'document_icon.gif')
tuple folder_icon = os.path.join(_zmi, 'icons', 'folder_icon.gif')
tuple base_factory_type_information
dictionary _types = {}
tuple last_load = DateTime()

Function Documentation

def Archetypes.ArchetypeTool._guessPackage (   base) [private]

Definition at line 340 of file ArchetypeTool.py.

00340 
00341 def _guessPackage(base):
00342     if base.startswith('Products'):
00343         base = base[9:]
00344         idx = base.index('.')
00345         if idx != -1:
00346             base = base[:idx]
00347     return base

Here is the caller graph for this function:

def Archetypes.ArchetypeTool.fixActionsForType (   portal_type,
  typesTool 
)

Definition at line 138 of file ArchetypeTool.py.

00138 
00139 def fixActionsForType(portal_type, typesTool):
00140     if 'actions' in portal_type.installMode:
00141         typeInfo = getattr(typesTool, portal_type.portal_type, None)
00142         if typeInfo is None:
00143             return
00144         if hasattr(portal_type, 'actions'):
00145             # Look for each action we define in portal_type.actions in
00146             # typeInfo.action replacing it if its there and just
00147             # adding it if not
00148             ## rr: this is now trial-and-error programming
00149             ## I really don't know what's going on here
00150             ## most importantly I don't know why the default
00151             ## actions are not set in some cases :-(
00152             ## (maybe they are removed afterwards sometimes???)
00153             ## if getattr(portal_type,'include_default_actions', True):
00154             if True:
00155                 default = [ActionInformation(**action) for action in
00156                            base_factory_type_information[0]['actions']]
00157                 next = list(typeInfo._actions)
00158                 all = next + default
00159                 new = [a.clone() for a in all]
00160             else:
00161                 # If no standard actions are wished don't display them
00162                 new = []
00163             try:
00164                 cmfver = getCMFVersion()
00165             except ImportError:
00166                 cmfver = 'CMF-2.0'   ## rr: kind of a hack but all we
00167                                      ## need to know here for now
00168 
00169             for action in portal_type.actions:
00170                 # DM: "Expression" derives from "Persistent" and
00171                 # we must not put persistent objects into class attributes.
00172                 # Thus, copy "action"
00173                 action = action.copy()
00174 
00175                 if cmfver[:7] >= 'CMF-1.4' or cmfver == 'Unreleased':
00176                     # Then we know actions are defined new style as
00177                     # ActionInformations
00178                     hits = [a for a in new if a.id == action['id']]
00179 
00180                     # Change action and condition into expressions, if
00181                     # they are still strings
00182                     if action.has_key('action') and \
00183                            type(action['action']) in (type(''), type(u'')):
00184                         action['action'] = Expression(action['action'])
00185                     if action.has_key('condition') and \
00186                            type(action['condition']) in (type(''), type(u'')):
00187                         action['condition'] = Expression(action['condition'])
00188                     if action.has_key('name'):
00189                         action['title'] = action['name']
00190                         del action['name']
00191                     if hits:
00192                         hits[0].__dict__.update(action)
00193                     else:
00194                         new.append(ActionInformation(**action))
00195                 else:
00196                     hit = findDict(new, 'id', action['id'])
00197                     if hit:
00198                         hit.update(action)
00199                     else:
00200                         new.append(action)
00201 
00202             typeInfo._actions = tuple(new)
00203             typeInfo._p_changed = True
00204 
00205         if hasattr(portal_type, 'factory_type_information'):
00206             typeInfo.__dict__.update(portal_type.factory_type_information)
00207             typeInfo._p_changed = True
00208 

Here is the call graph for this function:

Here is the caller graph for this function:

def Archetypes.ArchetypeTool.fixAfterRenameType (   context,
  old_portal_type,
  new_portal_type 
)
Helper method to fix some vars after renaming a type in portal_types

It will raise an IndexError if called with a nonexisting old_portal_type.
If you like to swallow the error please use a try/except block in your own
code and do NOT 'fix' this method.

Definition at line 383 of file ArchetypeTool.py.

00383 
00384 def fixAfterRenameType(context, old_portal_type, new_portal_type):
00385     """Helper method to fix some vars after renaming a type in portal_types
00386 
00387     It will raise an IndexError if called with a nonexisting old_portal_type.
00388     If you like to swallow the error please use a try/except block in your own
00389     code and do NOT 'fix' this method.
00390     """
00391     at_tool = getToolByName(context, TOOL_NAME)
00392     __traceback_info__ = (context, old_portal_type, new_portal_type,
00393                           [t['portal_type'] for t in _types.values()])
00394     # Will fail if old portal type wasn't registered (DO 'FIX' THE INDEX ERROR!)
00395     old_type = [t for t in _types.values()
00396                 if t['portal_type'] == old_portal_type][0]
00397 
00398     # Rename portal type
00399     old_type['portal_type'] = new_portal_type
00400 
00401     # Copy old templates to new portal name without references
00402     old_templates = at_tool._templates.get(old_portal_type)
00403     at_tool._templates[new_portal_type] = deepcopy(old_templates)

Here is the call graph for this function:

Definition at line 70 of file ArchetypeTool.py.

00070 
00071     def getCMFVersion():
00072         from os.path import join
00073         from Globals import package_home
00074         from Products.CMFCore import cmfcore_globals
00075         path = join(package_home(cmfcore_globals),'version.txt')
00076         file = open(path, 'r')
00077         _version = file.read()
00078         file.close()
00079         return _version.strip()

Here is the caller graph for this function:

def Archetypes.ArchetypeTool.getType (   name,
  package 
)

Definition at line 471 of file ArchetypeTool.py.

00471 
00472 def getType(name, package):
00473     key = '%s.%s' % (package, name)
00474     return _types[key]

Here is the caller graph for this function:

def Archetypes.ArchetypeTool.listTypes (   package = None)

Definition at line 464 of file ArchetypeTool.py.

00464 
00465 def listTypes(package=None):
00466     values = _types.values()
00467     if package:
00468         values = [v for v in values if v['package'] == package]
00469 
00470     return values

Here is the caller graph for this function:

def Archetypes.ArchetypeTool.modify_fti (   fti,
  klass,
  pkg_name 
)

Definition at line 209 of file ArchetypeTool.py.

00209 
00210 def modify_fti(fti, klass, pkg_name):
00211     fti[0]['id'] = klass.__name__
00212     fti[0]['meta_type'] = klass.meta_type
00213     fti[0]['description'] = klass.__doc__
00214     fti[0]['factory'] = 'add%s' % klass.__name__
00215     fti[0]['product'] = pkg_name
00216 
00217     if hasattr(klass, 'content_icon'):
00218         fti[0]['content_icon'] = klass.content_icon
00219 
00220     if hasattr(klass, 'global_allow'):
00221         fti[0]['global_allow'] = klass.global_allow
00222 
00223     if hasattr(klass, 'allow_discussion'):
00224         fti[0]['allow_discussion'] = klass.allow_discussion
00225 
00226     if hasattr(klass, 'allowed_content_types'):
00227         allowed = klass.allowed_content_types
00228         fti[0]['allowed_content_types'] = allowed
00229         fti[0]['filter_content_types'] = allowed and True or False
00230 
00231     if hasattr(klass, 'filter_content_types'):
00232         fti[0]['filter_content_types'] = klass.filter_content_types
00233 
00234     if hasattr(klass, 'immediate_view'):
00235         fti[0]['immediate_view'] = klass.immediate_view
00236 
00237     if not IReferenceable.isImplementedByInstancesOf(klass):
00238         refs = findDict(fti[0]['actions'], 'id', 'references')
00239         refs['visible'] = False
00240 
00241     if not IExtensibleMetadata.isImplementedByInstancesOf(klass):
00242         refs = findDict(fti[0]['actions'], 'id', 'metadata')
00243         refs['visible'] = False
00244 
00245     # Set folder_listing to 'view' if the class implements ITemplateMixin
00246     if not ITemplateMixin.isImplementedByInstancesOf(klass):
00247         actions = []
00248         for action in fti[0]['actions']:
00249             if action['id'] != 'folderlisting':
00250                 actions.append(action)
00251             else:
00252                 action['action'] = 'string:${folder_url}/view'
00253                 actions.append(action)
00254         fti[0]['actions'] = tuple(actions)
00255 
00256     # Remove folderlisting action from non folderish content types
00257     if not getattr(klass,'isPrincipiaFolderish', None):
00258         actions = []
00259         for action in fti[0]['actions']:
00260             if action['id'] != 'folderlisting':
00261                 actions.append(action)
00262         fti[0]['actions'] = tuple(actions)
00263         
00264     # CMF 1.5 method aliases
00265     if getattr(klass, 'aliases', None):
00266         aliases = klass.aliases
00267         if not isinstance(aliases, dict):
00268             raise TypeError, "Invalid type for method aliases in class %s" % klass
00269         for required in ('(Default)', 'view',):
00270             if required not in aliases:
00271                 raise ValueError, "Alias %s is required but not provied by %s" % (
00272                                   required, klass)
00273         fti[0]['aliases'] = aliases 
00274         
00275     # Dynamic View FTI support
00276     if getattr(klass, 'default_view', False):
00277         default_view = klass.default_view
00278         if not isinstance(default_view, basestring):
00279             raise TypeError, "Invalid type for default view in class %s" % klass
00280         fti[0]['default_view'] = default_view
00281         fti[0]['view_methods'] = (default_view, )
00282         
00283         if getattr(klass, 'suppl_views', False):
00284             suppl_views = klass.suppl_views
00285             if not isinstance(suppl_views, (list, tuple)):
00286                 raise TypeError, "Invalid type for suppl views in class %s" % klass
00287             if not default_view in suppl_views:
00288                 suppl_views = suppl_views + (default_view, )
00289             fti[0]['view_methods'] = suppl_views
00290     if getattr(klass, '_at_fti_meta_type', False):
00291         fti[0]['fti_meta_type'] = klass._at_fti_meta_type
00292     else:
00293         if fti[0].get('fti_meta_type', False):
00294             klass._at_fti_meta_type = fti[0]['fti_meta_type']
00295         else:
00296             fti[0]['fti_meta_type'] = FactoryTypeInformation.meta_type
00297 

Here is the call graph for this function:

Here is the caller graph for this function:

def Archetypes.ArchetypeTool.process_types (   types,
  pkg_name 
)

Definition at line 298 of file ArchetypeTool.py.

00298 
00299 def process_types(types, pkg_name):
00300     content_types = ()
00301     constructors = ()
00302     ftis = ()
00303 
00304     for rti in types:
00305         typeName = rti['name']
00306         klass = rti['klass']
00307         module = rti['module']
00308 
00309         if hasattr(module, 'factory_type_information'):
00310             fti = module.factory_type_information
00311         else:
00312             fti = deepcopy(base_factory_type_information)
00313             modify_fti(fti, klass, pkg_name)
00314 
00315         # Add a callback to modifty the fti
00316         if hasattr(module, 'modify_fti'):
00317             module.modify_fti(fti[0])
00318         else:
00319             m = None
00320             for k in klass.__bases__:
00321                 base_module = sys.modules[k.__module__]
00322                 if hasattr(base_module, 'modify_fti'):
00323                     m = base_module
00324                     break
00325             if m is not None:
00326                 m.modify_fti(fti[0])
00327 
00328         ctor = getattr(module, 'add%s' % typeName, None)
00329         if ctor is None:
00330             ctor = generateCtor(typeName, module)
00331 
00332         content_types += (klass,)
00333         constructors += (ctor,)
00334         ftis += fti
00335 
00336     return content_types, constructors, ftis
00337 

Here is the call graph for this function:

Here is the caller graph for this function:

def Archetypes.ArchetypeTool.registerClasses (   context,
  package,
  types = None 
)

Definition at line 404 of file ArchetypeTool.py.

00404 
00405 def registerClasses(context, package, types=None):
00406     registered = listTypes(package)
00407     if types is not None:
00408         registered = filter(lambda t: t['meta_type'] in types, registered)
00409     for t in registered:
00410         module = t['module']
00411         typeName = t['name']
00412         meta_type = t['meta_type']
00413         portal_type = t['portal_type']
00414         klass = t['klass']
00415         ctorName = 'manage_add%s' % typeName
00416         constructor = getattr(module, ctorName, None)
00417         if constructor is None:
00418             constructor = generateZMICtor(typeName, module)
00419         addFormName = 'manage_add%sForm' % typeName
00420         setattr(module, addFormName,
00421                 BoundPageTemplateFile('base_add.pt', _zmi,
00422                                       __name__=addFormName,
00423                                       extra={'constructor':ctorName,
00424                                              'type':meta_type,
00425                                              'package':package,
00426                                              'portal_type':portal_type}
00427                                       ))
00428         editFormName = 'manage_edit%sForm' % typeName
00429         setattr(klass, editFormName,
00430                 BoundPageTemplateFile('base_edit.pt', _zmi,
00431                                       __name__=editFormName,
00432                                       extra={'handler':'processForm',
00433                                              'type':meta_type,
00434                                              'package':package,
00435                                              'portal_type':portal_type}
00436                                       ))
00437 
00438         position = False
00439         for item in klass.manage_options:
00440             if item['label'] != 'Contents':
00441                 continue
00442             position += 1
00443         folderish = getattr(klass, 'isPrincipiaFolderish', position)
00444         options = list(klass.manage_options)
00445         options.insert(position, {'label' : 'Edit',
00446                                   'action' : editFormName
00447                                   })
00448         klass.manage_options = tuple(options)
00449         generatedForm = getattr(module, addFormName)
00450         icon = folderish and folder_icon or document_icon
00451         if klass.__dict__.has_key('content_icon'):
00452             icon = klass.content_icon
00453         elif hasattr(klass, 'factory_type_information'):
00454             factory_type_information = klass.factory_type_information
00455             if factory_type_information.has_key('content_icon'):
00456                 icon = factory_type_information['content_icon']
00457 
00458         context.registerClass(
00459             t['klass'],
00460             constructors=(generatedForm, constructor),
00461             visibility=None,
00462             icon=icon
00463             )

Here is the call graph for this function:

def Archetypes.ArchetypeTool.registerType (   klass,
  package = None 
)

Definition at line 348 of file ArchetypeTool.py.

00348 
00349 def registerType(klass, package=None):
00350     if not package:
00351         deprecated("registerType without a package name is deprecated. "
00352                    "Please apply a package name for class %s" % repr(klass),
00353                    level=2)
00354         package = _guessPackage(klass.__module__)
00355 
00356     # Registering a class results in classgen doing its thing
00357     # Set up accessor/mutators and sane meta/portal_type
00358     generateClass(klass)
00359 
00360     data = {
00361         'klass' : klass,
00362         'name' : klass.__name__,
00363         'identifier': klass.meta_type.capitalize().replace(' ', '_'),
00364         'meta_type': klass.meta_type,
00365         'portal_type': klass.portal_type,
00366         'package' : package,
00367         'module' : sys.modules[klass.__module__],
00368         'schema' : klass.schema,
00369         'signature' : klass.schema.signature(),
00370         # backward compatibility, remove later
00371         'type' : klass.schema,
00372         }
00373 
00374     key = '%s.%s' % (package, data['meta_type'])
00375     if key in _types.keys():
00376         existing = _types[key]
00377         existing_name = '%s.%s' % (existing['module'].__name__, existing['name'])
00378         override_name = '%s.%s' % (data['module'].__name__, data['name'])
00379         log('ArchetypesTool: Trying to register "%s" which ' \
00380             'has already been registered.  The new type %s ' \
00381             'is going to override %s' % (key, override_name, existing_name))
00382     _types[key] = data

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

tuple Archetypes.ArchetypeTool._skins = os.path.join(os.path.dirname(__file__), 'skins')

Definition at line 81 of file ArchetypeTool.py.

Definition at line 338 of file ArchetypeTool.py.

tuple Archetypes.ArchetypeTool._www = os.path.join(os.path.dirname(__file__), 'www')

Definition at line 80 of file ArchetypeTool.py.

tuple Archetypes.ArchetypeTool._zmi = os.path.join(_www, 'zmi')

Definition at line 82 of file ArchetypeTool.py.

Definition at line 87 of file ArchetypeTool.py.

tuple Archetypes.ArchetypeTool.document_icon = os.path.join(_zmi, 'icons', 'document_icon.gif')

Definition at line 83 of file ArchetypeTool.py.

tuple Archetypes.ArchetypeTool.folder_icon = os.path.join(_zmi, 'icons', 'folder_icon.gif')

Definition at line 84 of file ArchetypeTool.py.

Definition at line 489 of file ArchetypeTool.py.