def __getattr__(self, name): # be sure to get a valid value reg = lookup_behavior_registration(name=name) iid = reg.interface.__identifier__ return ( iid in self.fti.behaviors or reg.name.encode('utf8') in self.fti.behaviors )
def __iter__(self): # iterate through the present behaviors for name in self.fti.behaviors: try: reg = lookup_behavior_registration(name=name) except BehaviorRegistrationNotFound: # ignore wrong names continue if reg.name: yield reg.name.encode('utf8') else: yield name
def __setattr__(self, name, value): # add or remove the behavior based on the value from the form behaviors = list(self.fti.behaviors) reg = lookup_behavior_registration(name=name) iid = reg.interface.__identifier__ if reg.name and iid in self.fti.behaviors: behaviors.remove(iid) bname = reg.name.encode('utf8') else: bname = iid if value and bname not in behaviors: behaviors.append(bname) elif not value and bname in behaviors: behaviors.remove(bname) self.fti.behaviors = behaviors
def move_dotted_to_named_behaviors(context): """named behaviors are better then dotted behaviors > let's move them.""" from plone import api from plone.behavior.registration import lookup_behavior_registration from plone.dexterity.interfaces import IDexterityFTI ptt = api.portal.get_tool('portal_types') ftis = [fti for fti in ptt.objectValues() if IDexterityFTI.providedBy(fti)] for fti in ftis: behaviors = [] for behavior in fti.behaviors: behavior_registration = lookup_behavior_registration(behavior) named_behavior = behavior_registration.name if named_behavior: behaviors.append(named_behavior) if named_behavior == behavior: logger.info( 'Behavior "{behavior}" already named.'.format( behavior=behavior, ), ) else: logger.info( 'Moved "{dotted}" to "{named}"'.format( dotted=behavior, named=named_behavior, ), ) else: behaviors.append(behavior) logger.info( '"{dotted}" has no name registered. ' 'kept it dotted.'.format( dotted=behavior, ), ) fti.behaviors = tuple(behaviors) logger.info( 'Converted dotted behaviors of {ct} to named behaviors.'.format( ct=fti.title, ), ) logger.info('Done moving dotted to named behaviors.')
def move_dotted_to_named_behaviors(context): """named behaviors are better then dotted behaviors > let's move them.""" from plone import api from plone.behavior.registration import lookup_behavior_registration from plone.dexterity.interfaces import IDexterityFTI ptt = api.portal.get_tool('portal_types') ftis = [fti for fti in ptt.objectValues() if IDexterityFTI.providedBy(fti)] for fti in ftis: behaviors = [] for behavior in fti.behaviors: behavior_registration = lookup_behavior_registration(behavior) named_behavior = behavior_registration.name if named_behavior: behaviors.append(named_behavior) if named_behavior == behavior: logger.info( 'Behavior "{behavior}" already named.'.format( behavior=behavior, ), ) else: logger.info( 'Moved "{dotted}" to "{named}"'.format( dotted=behavior, named=named_behavior, ), ) else: behaviors.append(behavior) logger.info( '"{dotted}" has no name registered. ' 'kept it dotted.'.format(dotted=behavior, ), ) fti.behaviors = tuple(behaviors) logger.info( 'Converted dotted behaviors of {ct} to named behaviors.'.format( ct=fti.title, ), ) logger.info('Done moving dotted to named behaviors.') # Make sure plone.staticresources is installed from Products.CMFPlone.utils import get_installer qi = get_installer(context) if not qi.is_product_installed('plone.staticresources'): qi.install_product('plone.staticresources')
def reattachReferencedAttributes(self, obj, attrs_dict): obj = aq_base(obj) for name, blob in six.iteritems(attrs_dict): iface_name, f_name = name.rsplit('.', 1) # In case the field is provided via a behavior: # Look up the behavior via dotted name. # If the behavior's dotted name was changed, we might still have # the old name in our attrs_dict. # Use the fallback of plone.behavior, provided via the field # former_dotted_names, so that the correct behavior can still # be found. try: behavior = lookup_behavior_registration(iface_name) iface = behavior.interface except BehaviorRegistrationNotFound: # Not a behavior - fetch the interface directly iface = resolveDottedName(iface_name) field = iface.get(f_name) if field is not None: # Field may have been removed from schema adapted_field = field.get(iface(obj)) if adapted_field: adapted_field._blob = blob
def __setattr__(self, name, value): # add or remove the behavior based on the value from the form behaviors = list(self.fti.behaviors) reg = lookup_behavior_registration(name=name) iid = reg.interface.__identifier__ if reg.name: # behavior has a name -> use it # but first remove the dotted behavior if present if iid in self.fti.behaviors: behaviors.remove(iid) # prepare named behavior for add/remove bname = reg.name.encode('utf8') else: # no name found -> prepare dotted behavior for add/remove instead bname = iid # add/remove bname if based on value True false if value and bname not in behaviors: behaviors.append(bname) elif not value and bname in behaviors: behaviors.remove(bname) self.fti.behaviors = behaviors
def __call__(self): portal = api.portal.get() tools = [ "portal_languages", "portal_tinymce", "kupu_library_tool", "portal_factory", "portal_atct", "uid_catalog", "archetype_tool", "reference_catalog", "portal_metadata", ] for tool in tools: try: portal.manage_delObjects([tool]) log.info("Deleted {}".format(tool)) except AttributeError: log.info("{} not found".format(tool)) # reapply uninstall to get rid of IATCTTool component try: loadMigrationProfile(portal, "profile-Products.ATContentTypes:uninstall") except KeyError: pass ptt = api.portal.get_tool("portal_types") ftis = [fti for fti in ptt.objectValues() if IDexterityFTI.providedBy(fti)] for fti in ftis: bad_behaviors = [] for behavior in fti.behaviors: try: lookup_behavior_registration(behavior) except Exception: bad_behaviors.append(behavior) if bad_behaviors: behaviors = [x for x in fti.behaviors if x not in bad_behaviors] fti.behaviors = behaviors log.warning("Removed {} for FTI {}".format(bad_behaviors, fti.id)) # Unregister persistent traces of collective.indexing try: from collective.indexing.indexer import IPortalCatalogQueueProcessor from collective.indexing.interfaces import IIndexingConfig except ImportError: pass else: cp = api.portal.get_tool("portal_controlpanel") cp.unregisterConfiglet("IndexingSettings") for iface, name in ( (IIndexingConfig, ""), (IPortalCatalogQueueProcessor, "portal-catalog"), ): unregisterUtility(portal, iface, name) # Remove yet more traces of c.indexing in the site manager sm = portal.getSiteManager() bad_ids = [ "collective.indexing.interfaces.IIndexingConfig", "collective.indexing.indexer.IPortalCatalogQueueProcessor-portal-catalog", ] for bad_id in bad_ids: if bad_id in sm.objectIds(): sm._delObject(bad_id) sm._p_changed = True # Also unregister collective.js.jquery util unregisterUtility(portal, ILocalBrowserLayerType, "collective.js.jqueryui")