Esempio n. 1
0
    def __call__(self):
        RESPONSE = self.request.RESPONSE
        pt = getToolByName(self.context, 'portal_types')

        items = self.request.selected.split(',')

        if len(items) == 1:
            # return a single XML file

            item = items[0]
            filename = '{0}.xml'.format(item)
            text = serializeModel(pt[item].lookupModel())

            RESPONSE.setHeader('Content-type', 'application/xml')
            RESPONSE.setHeader(
                'Content-disposition',
                'attachment; filename={0}'.format(filename)
            )

            return text

        elif len(items) > 1:
            # pack multiple items into a zip file

            timestamp = time.gmtime()
            archive_filename = ('dexterity_models-%4d%02d%02d%02d%02d%02d.zip'
                                % timestamp[:6])

            archive_stream = BytesIO()
            archive = ZipFile(archive_stream, 'w')

            for item in items:
                filename = 'models/{0}.xml'.format(item)
                text = serializeModel(pt[item].lookupModel())
                archive.writestr(filename, text)

            archive.close()

            RESPONSE.setHeader('Content-type', 'application/zip')
            RESPONSE.setHeader(
                'Content-disposition',
                'attachment; filename={0}'.format(archive_filename)
            )

            return archive_stream.getvalue()

        else:
            return ''
Esempio n. 2
0
    def __call__(self):
        RESPONSE = self.request.RESPONSE
        pt = getToolByName(self.context, 'portal_types')

        items = self.request.selected.split(',')

        if len(items) == 1:
            # return a single XML file

            item = items[0]
            filename = '{0}.xml'.format(item)
            text = serializeModel(pt[item].lookupModel())

            RESPONSE.setHeader('Content-type', 'application/xml')
            RESPONSE.setHeader(
                'Content-disposition',
                'attachment; filename={0}'.format(filename)
            )

            return text

        elif len(items) > 1:
            # pack multiple items into a zip file

            timestamp = time.gmtime()
            archive_filename = ('dexterity_models-%4d%02d%02d%02d%02d%02d.zip'
                                % timestamp[:6])

            archive_stream = StringIO()
            archive = ZipFile(archive_stream, 'w')

            for item in items:
                filename = 'models/{0}.xml'.format(item)
                text = serializeModel(pt[item].lookupModel())
                archive.writestr(filename, text)

            archive.close()

            RESPONSE.setHeader('Content-type', 'application/zip')
            RESPONSE.setHeader(
                'Content-disposition',
                'attachment; filename={0}'.format(archive_filename)
            )

            return archive_stream.getvalue()

        else:
            return ''
Esempio n. 3
0
def serializeSchema(schema):
    """ Finds the FTI and model associated with a schema, and synchronizes
        the schema to the FTI model_source attribute.

        This method only works for schemas that were created from an FTI's
        model_source property

        BBB - deprecated
    """

    # determine portal_type
    try:
        prefix, portal_type, schemaName = splitSchemaName(schema.__name__)
    except ValueError:
        # not a dexterity schema
        return

    # find the FTI and model
    fti = queryUtility(IDexterityFTI, name=portal_type)
    if fti.model_source:
        model = fti.lookupModel()

        # synchronize changes to the model
        syncSchema(schema, model.schemata[schemaName], overwrite=True)
        fti.model_source = serializeModel(model)
    else:
        raise TypeError("Changes to non-dynamic schemata not yet supported.")
Esempio n. 4
0
def serializeSchema(schema):
    """ Finds the FTI and model associated with a schema, and synchronizes
        the schema to the FTI model_source attribute.

        This method only works for schemas that were created from an FTI's
        model_source property

        BBB - deprecated
    """

    # determine portal_type
    try:
        prefix, portal_type, schemaName = splitSchemaName(schema.__name__)
    except ValueError:
        # not a dexterity schema
        return

    # find the FTI and model
    fti = queryUtility(IDexterityFTI, name=portal_type)
    if fti.model_source:
        model = fti.lookupModel()

        # synchronize changes to the model
        syncSchema(schema, model.schemata[schemaName], overwrite=True)
        fti.model_source = serializeModel(model)
    else:
        raise TypeError("Changes to non-dynamic schemata not yet supported.")
Esempio n. 5
0
def serializeSchemaContext(schema_context, event=None):
    """ Serializes the schema associated with a schema context.

    The serialized schema is saved to the model_source property of the FTI
    associated with the schema context.
    """
    # find the FTI and model
    fti = schema_context.fti
    schemaName = schema_context.schemaName
    schema = schema_context.schema
    model = fti.lookupModel()

    # synchronize changes to the model
    syncSchema(schema, model.schemata[schemaName], overwrite=True)
    fti.model_source = serializeModel(model)
Esempio n. 6
0
def serializeSchemaContext(schema_context, event=None):
    """ Serializes the schema associated with a schema context.

    The serialized schema is saved to the model_source property of the FTI
    associated with the schema context.
    """
    # find the FTI and model
    fti = schema_context.fti
    schemaName = schema_context.schemaName
    schema = schema_context.schema
    model = fti.lookupModel()

    # synchronize changes to the model
    syncSchema(schema, model.schemata[schemaName], overwrite=True)
    fti.model_source = serializeModel(model)
Esempio n. 7
0
def serializeSchema(schema):
    """Taken from plone.app.dexterity.serialize
    Finds the FTI and model associated with a schema, and synchronizes
    the schema to the FTI model_source attribute.
    """

    # determine portal_type
    try:
        prefix, portal_type, schemaName = splitSchemaName(schema.__name__)
    except ValueError:
        # not a dexterity schema
        return

    # find the FTI and model
    fti = queryUtility(IDexterityFTI, name=portal_type)
    model = fti.lookupModel()

    # synchronize changes to the model
    syncSchema(schema, model.schemata[schemaName], overwrite=True)
    fti.model_source = serializeModel(model)