Example #1
0
                if chain[0] == '(Default)':
                    chain = portal_workflow.getDefaultChain()

                workflow = portal_workflow[chain]
                portal_workflow.setStatusOf(chain[0], obj, status)
                auto_transition = workflow._findAutomaticTransition(obj,
                    workflow._getWorkflowStateOf(obj))
                if auto_transition is not None:
                    workflow._changeStateOf(obj, auto_transition)
                else:
                    workflow.updateRoleMappingsFor(obj)

    def set(self, state, action):
        return self._set(self.obj, state, action)
addMigrator(WorkflowStateMigrator)


class WorkflowHistoryMigrator(BaseMigrator):
    title = 'Workflow History'
    _type = 'object'

    @classmethod
    def _get(kls, obj):
        return getattr(obj, 'workflow_history', None)

    @classmethod
    def _set(kls, obj, data):
        if data:
            obj.workflow_history = PersistentDict(data)
addMigrator(WorkflowHistoryMigrator)
        fields = {}
        for field in obj.Schema().fields():
            if field.__name__ in _skipped_fields:
                continue
            fields[field.__name__] = FieldMigrator._get(obj, field.__name__)
        return fields

    @classmethod
    def _set(kls, obj, values):
        for name, value in values.items():
            if name in _skipped_fields:
                continue
            value = FieldMigrator._set(obj, value, name)


addMigrator(FieldsMigrator)


class FieldMigrator(BaseMigrator):
    title = "Field"
    _type = "object"

    def __init__(self, site, obj, fieldname, safe=True):
        self.site = site
        self.obj = obj
        self.fieldname = fieldname
        self.safe = safe

    def get(self):
        return self._get(self.obj, self.fieldname, self.safe)
        values = obj.propertyItems()
        return {"structure": structure, "values": values}

    @classmethod
    def _set(kls, obj, value):
        structure = value["structure"]
        values = value["values"]

        if not structure or not values:
            return
        existing_structure = convertListOfDicts(obj._properties)
        for id, struct in structure.items():
            if id not in existing_structure:
                existing_structure[id] = struct
            else:
                existing_structure[id].update(struct)

        obj._properties = tuple(existing_structure.values())

        for key, value in values:
            if existing_structure[key]["type"] == "string":
                # try to convert to string if possible
                try:
                    value = str(value)
                except:
                    pass
            setattr(obj, key, value)


addMigrator(ObjectPropertiesMigrator)
Example #4
0
        values = obj.propertyItems()
        return {'structure': structure, 'values': values}

    @classmethod
    def _set(kls, obj, value):
        structure = value['structure']
        values = value['values']

        if not structure or not values:
            return
        existing_structure = convertListOfDicts(obj._properties)
        for id, struct in structure.items():
            if id not in existing_structure:
                existing_structure[id] = struct
            else:
                existing_structure[id].update(struct)

        obj._properties = tuple(existing_structure.values())

        for key, value in values:
            if existing_structure[key]['type'] == 'string':
                # try to convert to string if possible
                try:
                    value = str(value)
                except:
                    pass
            setattr(obj, key, value)


addMigrator(ObjectPropertiesMigrator)
        fields = {}
        for field in obj.Schema().fields():
            if field.__name__ in _skipped_fields:
                continue
            fields[field.__name__] = FieldMigrator._get(obj, field.__name__)
        return fields

    @classmethod
    def _set(kls, obj, values):
        for name, value in values.items():
            if name in _skipped_fields:
                continue
            value = FieldMigrator._set(obj, value, name)


addMigrator(FieldsMigrator)


class FieldMigrator(BaseMigrator):
    title = 'Field'
    _type = 'object'

    def __init__(self, site, obj, fieldname, safe=True):
        self.site = site
        self.obj = obj
        self.fieldname = fieldname
        self.safe = safe

    def get(self):
        return self._get(self.obj, self.fieldname, self.safe)
Example #6
0
    def __init__(self, object):
        self.object = object
        self.site = getSite()
        import logging
        self._logger = logging.getLogger('wildcard.migrator')
        self._doc = PrettyDocument()
        self.sitepath = '/'.join(getSite().getPhysicalPath())
        self.objectpath = '/'.join(
            object.getPhysicalPath())[len(self.sitepath):]


class PortletsMigrator(BaseMigrator):
    """
    Get information about content in order to
    create stubs or "touch" the content.
    """
    title = "Content's Portlet"
    _type = "object"

    @classmethod
    def _get(kls, obj):
        exporter = PortletsXMLAdapter(obj)
        return exporter.body

    @classmethod
    def _set(self, obj, xml):
        if xml:
            exporter = PortletsXMLAdapter(obj)
            exporter.body = xml.encode('utf-8')
addMigrator(PortletsMigrator)
Example #7
0
    _type = 'site'

    def get(self):
        from wildcard.migrator import getMigratorsOfType
        data = {}
        for migrator in getMigratorsOfType('gs'):
            migrator = migrator(self.site, self.obj)
            data[migrator.title] = migrator.get()
        return data

    def set(self, data):
        from wildcard.migrator import getMigratorsOfType
        for migrator in getMigratorsOfType('gs'):
            migrator = migrator(self.site, self.obj)
            migrator.set(data[migrator.title])
addMigrator(SiteSettings)


def GSMigratorGenerator(title, _import, _export):
    class Migrator(GSMigrator):
        pass
    Migrator.title = title
    Migrator.funcs = {
        'import': _import,
        'export': _export
    }
    return Migrator


SitePropertiesMigrator = GSMigratorGenerator(
    'Site Properties', importSiteProperties, exportSiteProperties)
Example #8
0
                        'portal_type': getPT(o),
                        'modified': o.ModificationDate()
                    })
            except KeyError:
                pass
        return values

    def set(self, values):
        for data in values:
            id = str(data['id'])
            portal_type = str(data['portal_type'])
            if id not in self.obj.objectIds():
                yield createObject(self.obj, portal_type, id)
            else:
                yield self.obj[id]
addMigrator(FolderContentsMigrator)


class SiteContentsMigrator(FolderContentsMigrator):
    title = "Site Contents"
    _type = 'site'

    def __init__(self, site, obj=None):
        self.site = site
        self.obj = site
addMigrator(SiteContentsMigrator)


_skipped_annotations = (
    'plone.folder.ordered.order',  # handled manually
    'plone.folder.ordered.pos',  # handled manually
Example #9
0
        self.site = getSite()
        import logging
        self._logger = logging.getLogger('wildcard.migrator')
        self._doc = PrettyDocument()
        self.sitepath = '/'.join(getSite().getPhysicalPath())
        self.objectpath = '/'.join(
            object.getPhysicalPath())[len(self.sitepath):]


class PortletsMigrator(BaseMigrator):
    """
    Get information about content in order to
    create stubs or "touch" the content.
    """
    title = "Content's Portlet"
    _type = "object"

    @classmethod
    def _get(kls, obj):
        exporter = PortletsXMLAdapter(obj)
        return exporter.body

    @classmethod
    def _set(self, obj, xml):
        if xml:
            exporter = PortletsXMLAdapter(obj)
            exporter.body = xml.encode('utf-8')


addMigrator(PortletsMigrator)
Example #10
0
                    })
            except KeyError:
                pass
        return values

    def set(self, values):
        for data in values:
            id = str(data['id'])
            portal_type = str(data['portal_type'])
            if id not in self.obj.objectIds():
                yield createObject(self.obj, portal_type, id)
            else:
                yield self.obj[id]


addMigrator(FolderContentsMigrator)


class SiteContentsMigrator(FolderContentsMigrator):
    title = "Site Contents"
    _type = 'site'

    def __init__(self, site, obj=None):
        self.site = site
        self.obj = site


addMigrator(SiteContentsMigrator)

_skipped_annotations = (
    'plone.folder.ordered.order',  # handled manually