Пример #1
0
 def test_splitSchemaName(self):
     self.assertEqual(
         ('prefix', 'type', 'schema',),
         schema.splitSchemaName('prefix_0_type_0_schema')
     )
     self.assertEqual(
         ('prefix', 'type', '',),
         schema.splitSchemaName('prefix_0_type')
     )
     self.assertEqual(
         ('prefix', 'type one.two', '',),
         schema.splitSchemaName('prefix_0_type_1_one_2_two')
     )
Пример #2
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.")
Пример #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.')
Пример #4
0
 def test_splitSchemaName(self):
     self.assertEqual((
         'prefix',
         'type',
         'schema',
     ), schema.splitSchemaName('prefix_0_type_0_schema'))
     self.assertEqual((
         'prefix',
         'type',
         '',
     ), schema.splitSchemaName('prefix_0_type'))
     self.assertEqual((
         'prefix',
         'type one.two',
         '',
     ), schema.splitSchemaName('prefix_0_type_1_one_2_two'))
Пример #5
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)
Пример #6
0
 def test_splitSchemaName(self):
     self.assertEqual(("prefix", "type", "schema"), schema.splitSchemaName("prefix_0_type_0_schema"))
     self.assertEqual(("prefix", "type", ""), schema.splitSchemaName("prefix_0_type"))
     self.assertEqual(("prefix", "type one.two", ""), schema.splitSchemaName("prefix_0_type_1_one_2_two"))