def install_additional_templates(self, out, types): """Registers additionals templates for TemplateMixin classes. """ at = getToolByName(self, 'archetype_tool') for t in types: klass = t['klass'] if ITemplateMixin.implementedBy(klass): portal_type = klass.portal_type default_view = getattr(klass, 'default_view', 'base_view') suppl_views = getattr(klass, 'suppl_views', ()) views = [] if not default_view: default_view = 'base_view' at.registerTemplate(default_view) views.append(default_view) for view in suppl_views: at.registerTemplate(view) views.append(view) at.bindTemplate(portal_type, views)
def modify_fti(fti, klass, pkg_name): fti[0]['id'] = klass.__name__ fti[0]['meta_type'] = klass.meta_type fti[0]['description'] = klass.__doc__ fti[0]['factory'] = 'add%s' % klass.__name__ fti[0]['product'] = pkg_name if hasattr(klass, 'content_icon'): fti[0]['content_icon'] = klass.content_icon if hasattr(klass, 'global_allow'): fti[0]['global_allow'] = klass.global_allow if hasattr(klass, 'allow_discussion'): fti[0]['allow_discussion'] = klass.allow_discussion if hasattr(klass, 'allowed_content_types'): allowed = klass.allowed_content_types fti[0]['allowed_content_types'] = allowed fti[0]['filter_content_types'] = allowed and True or False if hasattr(klass, 'filter_content_types'): fti[0]['filter_content_types'] = klass.filter_content_types if hasattr(klass, 'immediate_view'): fti[0]['immediate_view'] = klass.immediate_view if not IExtensibleMetadata.implementedBy(klass): refs = findDict(fti[0]['actions'], 'id', 'metadata') refs['visible'] = False # Set folder_listing to 'view' if the class implements ITemplateMixin if not ITemplateMixin.implementedBy(klass): actions = [] for action in fti[0]['actions']: if action['id'] != 'folderlisting': actions.append(action) else: action['action'] = 'string:${folder_url}/view' actions.append(action) fti[0]['actions'] = tuple(actions) # Remove folderlisting action from non folderish content types if not getattr(klass, 'isPrincipiaFolderish', None): actions = [] for action in fti[0]['actions']: if action['id'] != 'folderlisting': actions.append(action) fti[0]['actions'] = tuple(actions) # CMF 1.5 method aliases if getattr(klass, 'aliases', None): aliases = klass.aliases if not isinstance(aliases, dict): raise TypeError, "Invalid type for method aliases in class %s" % klass for required in ( '(Default)', 'view', ): if required not in aliases: raise ValueError, "Alias %s is required but not provied by %s" % ( required, klass) fti[0]['aliases'] = aliases # Dynamic View FTI support if getattr(klass, 'default_view', False): default_view = klass.default_view if not isinstance(default_view, basestring): raise TypeError, "Invalid type for default view in class %s" % klass fti[0]['default_view'] = default_view fti[0]['view_methods'] = (default_view, ) if getattr(klass, 'suppl_views', False): suppl_views = klass.suppl_views if not isinstance(suppl_views, (list, tuple)): raise TypeError, "Invalid type for suppl views in class %s" % klass if not default_view in suppl_views: suppl_views = suppl_views + (default_view, ) fti[0]['view_methods'] = suppl_views if getattr(klass, '_at_fti_meta_type', False): fti[0]['fti_meta_type'] = klass._at_fti_meta_type else: if fti[0].get('fti_meta_type', False): klass._at_fti_meta_type = fti[0]['fti_meta_type'] else: fti[0]['fti_meta_type'] = FactoryTypeInformation.meta_type
def modify_fti(fti, klass, pkg_name): fti[0]['id'] = klass.__name__ fti[0]['meta_type'] = klass.meta_type fti[0]['description'] = klass.__doc__ fti[0]['factory'] = 'add%s' % klass.__name__ fti[0]['product'] = pkg_name if hasattr(klass, 'content_icon'): fti[0]['content_icon'] = klass.content_icon if hasattr(klass, 'global_allow'): fti[0]['global_allow'] = klass.global_allow if hasattr(klass, 'allow_discussion'): fti[0]['allow_discussion'] = klass.allow_discussion if hasattr(klass, 'allowed_content_types'): allowed = klass.allowed_content_types fti[0]['allowed_content_types'] = allowed fti[0]['filter_content_types'] = allowed and True or False if hasattr(klass, 'filter_content_types'): fti[0]['filter_content_types'] = klass.filter_content_types if hasattr(klass, 'immediate_view'): fti[0]['immediate_view'] = klass.immediate_view if not IExtensibleMetadata.implementedBy(klass): refs = findDict(fti[0]['actions'], 'id', 'metadata') refs['visible'] = False # Set folder_listing to 'view' if the class implements ITemplateMixin if not ITemplateMixin.implementedBy(klass): actions = [] for action in fti[0]['actions']: if action['id'] != 'folderlisting': actions.append(action) else: action['action'] = 'string:${folder_url}/view' actions.append(action) fti[0]['actions'] = tuple(actions) # Remove folderlisting action from non folderish content types if not getattr(klass, 'isPrincipiaFolderish', None): actions = [] for action in fti[0]['actions']: if action['id'] != 'folderlisting': actions.append(action) fti[0]['actions'] = tuple(actions) # CMF 1.5 method aliases if getattr(klass, 'aliases', None): aliases = klass.aliases if not isinstance(aliases, dict): raise TypeError, "Invalid type for method aliases in class %s" % klass for required in ('(Default)', 'view',): if required not in aliases: raise ValueError, "Alias %s is required but not provied by %s" % ( required, klass) fti[0]['aliases'] = aliases # Dynamic View FTI support if getattr(klass, 'default_view', False): default_view = klass.default_view if not isinstance(default_view, basestring): raise TypeError, "Invalid type for default view in class %s" % klass fti[0]['default_view'] = default_view fti[0]['view_methods'] = (default_view, ) if getattr(klass, 'suppl_views', False): suppl_views = klass.suppl_views if not isinstance(suppl_views, (list, tuple)): raise TypeError, "Invalid type for suppl views in class %s" % klass if not default_view in suppl_views: suppl_views = suppl_views + (default_view, ) fti[0]['view_methods'] = suppl_views if getattr(klass, '_at_fti_meta_type', False): fti[0]['fti_meta_type'] = klass._at_fti_meta_type else: if fti[0].get('fti_meta_type', False): klass._at_fti_meta_type = fti[0]['fti_meta_type'] else: fti[0]['fti_meta_type'] = FactoryTypeInformation.meta_type