Beispiel #1
0
def installType(self,
                typeName,
                package,
                portal_type=None,
                global_allow=False,
                dynamic=False):

    typesTool = getToolByName(self, 'portal_types')

    typeDesc = getType(typeName, package)
    klass = typeDesc['klass']
    typeinfo_name = "%s: %s (%s)" % (package, klass.__name__, klass.meta_type)

    if not portal_type:
        portal_type = typeDesc['portal_type']

    try:
        typesTool._delObject(portal_type)
    except:
        pass

    ft = FactoryTypeInformation
    if dynamic:
        ft = DynamicViewTypeInformation

    typesTool.manage_addTypeInformation(ft.meta_type,
                                        id=portal_type,
                                        typeinfo_name=typeinfo_name)
def installType(self, typeName, package, 
                portal_type=None, global_allow=False,
                dynamic=False):

    typesTool = getToolByName(self, 'portal_types')

    typeDesc = getType(typeName, package)
    klass = typeDesc['klass']
    typeinfo_name = "%s: %s (%s)" % (package, klass.__name__,
                                     klass.meta_type)

    if not portal_type:
        portal_type = typeDesc['portal_type']

    try:
        typesTool._delObject(portal_type)
    except:
        pass

    ft = FactoryTypeInformation
    if dynamic:
        ft = DynamicViewTypeInformation

    typesTool.manage_addTypeInformation(
        ft.meta_type,
        id=portal_type,
        typeinfo_name=typeinfo_name)
    def beforeChange_schema(self):
        """Load the values of fields according to fields_map if present.

        Each key in fields_map is a field in the old schema and each
        value is a field in the new schema.  If fields_map isn't a
        mapping, each field in the old schema will be migrated into
        the new schema.  Obeys field modes for readable and writable
        fields.  These values are then passed in as field kwargs into
        the constructor in the createNew method."""

        old_schema = self.old.Schema()

        typesTool = getToolByName(self.parent, 'portal_types')
        fti = typesTool.getTypeInfo(self.dst_portal_type)
        archetype = getType(self.dst_meta_type, fti.product)
        new_schema = archetype['klass'].schema

        if self.only_fields_map:
            old_field_names = self.fields_map.keys()
        else:
            old_field_names = old_schema.keys()

        # Let the migrator handle the id and dates
        for omit_field_name in ['id', 'creation_date',
                                'modification_date']:
            if omit_field_name in old_field_names:
                old_field_names.remove(omit_field_name)

        kwargs = getattr(self, 'schema', {})
        for old_field_name in old_field_names:
            old_field = self.old.getField(old_field_name)
            new_field_name = self.fields_map.get(old_field_name,
                                                 old_field_name)

            if new_field_name is None:
                continue

            new_field = new_schema.get(new_field_name, None)
            if new_field is None:
                continue

            if ('r' in old_field.mode and 'w' in new_field.mode):
                accessor = (
                    getattr(old_field, self.accessor_getter)(self.old)
                    or old_field.getAccessor(self.old))
                value = accessor()
                kwargs[new_field_name] = value
        self.schema = kwargs
    def beforeChange_schema(self):
        """Load the values of fields according to fields_map if present.

        Each key in fields_map is a field in the old schema and each
        value is a field in the new schema.  If fields_map isn't a
        mapping, each field in the old schema will be migrated into
        the new schema.  Obeys field modes for readable and writable
        fields.  These values are then passed in as field kwargs into
        the constructor in the createNew method."""

        old_schema = self.old.Schema()

        typesTool = getToolByName(self.parent, 'portal_types')
        fti = typesTool.getTypeInfo(self.dst_portal_type)
        archetype = getType(self.dst_meta_type, fti.product)
        new_schema = archetype['klass'].schema

        if self.only_fields_map:
            old_field_names = self.fields_map.keys()
        else:
            old_field_names = old_schema.keys()

        # Let the migrator handle the id and dates
        for omit_field_name in ['id', 'creation_date', 'modification_date']:
            if omit_field_name in old_field_names:
                old_field_names.remove(omit_field_name)

        kwargs = getattr(self, 'schema', {})
        for old_field_name in old_field_names:
            old_field = self.old.getField(old_field_name)
            new_field_name = self.fields_map.get(old_field_name,
                                                 old_field_name)

            if new_field_name is None:
                continue

            new_field = new_schema.get(new_field_name, None)
            if new_field is None:
                continue

            if ('r' in old_field.mode and 'w' in new_field.mode):
                accessor = (getattr(old_field, self.accessor_getter)(self.old)
                            or old_field.getAccessor(self.old))
                value = accessor()
                kwargs[new_field_name] = value
        self.schema = kwargs
 def get_types(self):
     types_ = []
     pt = getToolByName(self.context, "portal_types")
     for type_ in pt.listTypeInfo():
         meta_type = type_.Metatype()
         product = type_.product
         try:
             t = getType(meta_type, product)
         except KeyError:
             continue
         if "schema" in t:
             for f in t["schema"].fields():
                 if IAWSField.providedBy(f):
                     tid = type_.id
                     if tid not in types_:
                         types_.append(tid)
     return types_
    def migrate_extension_fields(self):
        """Migrate extension fields.

        In the beforeChange_schema method only standard fields of the
        schema are taken care of.  Extension fields from
        archetypes.schemaextender are not handled.  This can only
        really be done after the new object has been created.
        """

        old_schema = self.old.Schema()
        typesTool = getToolByName(self.parent, 'portal_types')
        fti = typesTool.getTypeInfo(self.dst_portal_type)
        archetype = getType(self.dst_meta_type, fti.product)
        plain_new_schema = archetype['klass'].schema
        new_schema = self.new.Schema()

        if self.only_fields_map:
            old_field_names = self.fields_map.keys()
        else:
            old_field_names = old_schema.keys()

        kwargs = {}
        for old_field_name in old_field_names:
            old_field = self.old.getField(old_field_name)
            new_field_name = self.fields_map.get(old_field_name,
                                                 old_field_name)

            if new_field_name is None:
                continue
            if new_field_name in plain_new_schema.keys():
                # Already migrated.
                continue

            new_field = new_schema.get(new_field_name, None)
            if new_field is None:
                continue

            if ('r' in old_field.mode and 'w' in new_field.mode):
                accessor = (
                    getattr(old_field, self.accessor_getter)(self.old)
                    or old_field.getAccessor(self.old))
                value = accessor()
                kwargs[new_field_name] = value
        # Apply the changes.
        self.new.update(**kwargs)
    def migrate_extension_fields(self):
        """Migrate extension fields.

        In the beforeChange_schema method only standard fields of the
        schema are taken care of.  Extension fields from
        archetypes.schemaextender are not handled.  This can only
        really be done after the new object has been created.
        """

        old_schema = self.old.Schema()
        typesTool = getToolByName(self.parent, 'portal_types')
        fti = typesTool.getTypeInfo(self.dst_portal_type)
        archetype = getType(self.dst_meta_type, fti.product)
        plain_new_schema = archetype['klass'].schema
        new_schema = self.new.Schema()

        if self.only_fields_map:
            old_field_names = self.fields_map.keys()
        else:
            old_field_names = old_schema.keys()

        kwargs = {}
        for old_field_name in old_field_names:
            old_field = self.old.getField(old_field_name)
            new_field_name = self.fields_map.get(old_field_name,
                                                 old_field_name)

            if new_field_name is None:
                continue
            if new_field_name in plain_new_schema.keys():
                # Already migrated.
                continue

            new_field = new_schema.get(new_field_name, None)
            if new_field is None:
                continue

            if ('r' in old_field.mode and 'w' in new_field.mode):
                accessor = (getattr(old_field, self.accessor_getter)(self.old)
                            or old_field.getAccessor(self.old))
                value = accessor()
                kwargs[new_field_name] = value
        # Apply the changes.
        self.new.update(**kwargs)
 def get_types(self):
     types_ = []
     pt = getToolByName(self.context, 'portal_types')
     for type_ in pt.listTypeInfo():
         meta_type = type_.Metatype()
         product = type_.product
         try:
             t = getType(meta_type, product)
         except KeyError:
             continue
         if 'schema' in t:
             for f in t['schema'].fields():
                 #if 'File' in t['name']:
                     #import pdb; pdb.set_trace()
                 if IAWSField.providedBy(f):
                     print t, f
                     tid = type_.id
                     if tid not in types_:
                         types_.append(tid)
     return types_
Beispiel #9
0
    def migrateCMFMemberType(portal, out):
        """Run the actual migration."""

        src_portal_type = klass._atct_newTypeFor['portal_type']
        dst_portal_type = klass.portal_type

        # store the workflow(s) associated w/ the old type so we can
        # associate the new one when we're done
        wftool = getToolByName(portal, 'portal_workflow')
        chain = wftool.getChainForPortalType(src_portal_type)

        # portal_quickinstaller won't work before the membrane_tool is
        # in place because some remember fields are indexed in the
        # membrane_tool but it isn't installed before migration.  So
        # we use Archetypes to install the type here.
        ttool = getToolByName(portal, 'portal_types')
        dst = ttool.getTypeInfo(dst_portal_type)
        if dst is None:
            print >> out, ("...installing %s type"
                           % dst_portal_type)
            at_type = getType(klass.meta_type, project_name)
            types = filterTypes(portal, out, [at_type], project_name)
            install_types(portal, out, types, project_name)

        mt = getToolByName(portal, 'membrane_tool')
        if dst_portal_type not in mt.listMembraneTypes():
            print >> out, ("...registering %s with membrane_tool"
                           % dst_portal_type)
            mt.registerMembraneType(dst_portal_type)

        print >> out, "...migrating %s to %s" % (src_portal_type,
                                                 dst_portal_type)
        migratePortalType(portal,
                          src_portal_type=src_portal_type,
                          dst_portal_type=dst_portal_type,
                          migrator=migrator,
                          use_catalog_patch=False)

        # associate the appropriate workflow
        wftool.setChainForPortalTypes((dst_portal_type,),
                                      chain)
Beispiel #10
0
    def migrateCMFMemberType(portal, out):
        """Run the actual migration."""

        src_portal_type = klass._atct_newTypeFor['portal_type']
        dst_portal_type = klass.portal_type

        # store the workflow(s) associated w/ the old type so we can
        # associate the new one when we're done
        wftool = getToolByName(portal, 'portal_workflow')
        chain = wftool.getChainForPortalType(src_portal_type)

        # portal_quickinstaller won't work before the membrane_tool is
        # in place because some remember fields are indexed in the
        # membrane_tool but it isn't installed before migration.  So
        # we use Archetypes to install the type here.
        ttool = getToolByName(portal, 'portal_types')
        dst = ttool.getTypeInfo(dst_portal_type)
        if dst is None:
            print >> out, ("...installing %s type" % dst_portal_type)
            at_type = getType(klass.meta_type, project_name)
            types = filterTypes(portal, out, [at_type], project_name)
            install_types(portal, out, types, project_name)

        mt = getToolByName(portal, 'membrane_tool')
        if dst_portal_type not in mt.listMembraneTypes():
            print >> out, ("...registering %s with membrane_tool" %
                           dst_portal_type)
            mt.registerMembraneType(dst_portal_type)

        print >> out, "...migrating %s to %s" % (src_portal_type,
                                                 dst_portal_type)
        migratePortalType(portal,
                          src_portal_type=src_portal_type,
                          dst_portal_type=dst_portal_type,
                          migrator=migrator,
                          use_catalog_patch=False)

        # associate the appropriate workflow
        wftool.setChainForPortalTypes((dst_portal_type, ), chain)