Esempio n. 1
0
def upgrade_to_ttw(context):
    # the new default schema only contains fullname and email fields
    # so we put the missing ones (home_page, description, location, portrait)
    # into the ttw schema
    if schemaeditor.get_schema() == '':
        finalizeSchemas(IEmpty)
        current_ttw = IEditableSchema(IEmpty)
    else:
        current_ttw = IEditableSchema(schemaeditor.load_ttw_schema())

    attrs = copySchemaAttrs(current_ttw.schema)
    current_fields = current_ttw.schema.names()
    pm = getToolByName(context, "portal_memberdata")
    existing = pm.propertyIds()

    if 'home_page' in existing and 'home_page' not in current_fields:
        attrs.update(copySchemaAttrs(IHomePageSchema))

    if 'description' in existing and 'description' not in current_fields:
        attrs.update(copySchemaAttrs(IDescriptionSchema))

    if 'location' in existing and 'location' not in current_fields:
        attrs.update(copySchemaAttrs(ILocationSchema))

    if 'portrait' in existing and 'portrait' not in current_fields:
        attrs.update(copySchemaAttrs(IPortraitSchema))

    sch = SchemaClass(schemaeditor.SCHEMATA_KEY,
                      bases=(current_ttw.schema, ),
                      attrs=attrs)
    finalizeSchemas(sch)

    xml_model = schemaeditor.serialize_ttw_schema(sch)
    schemaeditor.set_schema(xml_model)
    log.info('Old member fields migrated into TTW schema')
Esempio n. 2
0
def import_schema(context):
    """Import TTW Schema """
    data = context.readDataFile(FILE)
    if data is None:
        return
    model = ttw.load_ttw_schema(data)
    smodel = ttw.serialize_ttw_schema(model)

    # put imported field in user profile form by default
    ttw.set_schema(smodel)
    schema = ttw.get_ttw_edited_schema()
    for field_id in schema:
        schema[field_id].forms_selection = [u'In User Profile', ]
    new_model = ttw.serialize_ttw_schema(schema)
    ttw.applySchema(new_model)

    logger.info('Imported schema')
Esempio n. 3
0
def import_schema(context):
    """Import TTW Schema """
    data = context.readDataFile(FILE)
    if data is None:
        return
    model = ttw.load_ttw_schema(data)
    smodel = ttw.serialize_ttw_schema(model)

    # put imported field in user profile form by default
    ttw.set_schema(smodel)
    schema = ttw.get_ttw_edited_schema()
    for field_id in schema:
        schema[field_id].forms_selection = [
            u'In User Profile',
        ]
    new_model = ttw.serialize_ttw_schema(schema)
    ttw.applySchema(new_model)

    logger.info('Imported schema')
Esempio n. 4
0
def upgrade_to_ttw(context):
    # the new default schema only contains fullname and email fields
    # so we put the missing ones (home_page, description, location, portrait)
    # into the ttw schema
    if schemaeditor.get_schema() == '':
        finalizeSchemas(IEmpty)
        current_ttw = IEditableSchema(IEmpty)
    else:
        current_ttw = IEditableSchema(schemaeditor.load_ttw_schema())

    attrs = copySchemaAttrs(current_ttw.schema)
    current_fields = current_ttw.schema.names()
    pm = getToolByName(context, "portal_memberdata")
    existing = pm.propertyIds()

    if 'home_page' in existing and 'home_page' not in current_fields:
        attrs.update(copySchemaAttrs(IHomePageSchema))

    if 'description' in existing and 'description' not in current_fields:
        attrs.update(copySchemaAttrs(IDescriptionSchema))

    if 'location' in existing and 'location' not in current_fields:
        attrs.update(copySchemaAttrs(ILocationSchema))

    if 'portrait' in existing and 'portrait' not in current_fields:
        attrs.update(copySchemaAttrs(IPortraitSchema))

    sch = SchemaClass(schemaeditor.SCHEMATA_KEY,
        bases=(current_ttw.schema,),
        attrs=attrs
    )
    finalizeSchemas(sch)

    xml_model = schemaeditor.serialize_ttw_schema(sch)
    schemaeditor.set_schema(xml_model)
    log.info('Old member fields migrated into TTW schema')