Beispiel #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')
def getFromBaseSchema(baseSchema, form_name=None):
    attrs = copySchemaAttrs(baseSchema, form_name)
    ttwschema = get_ttw_edited_schema()
    if ttwschema:
        attrs.update(copySchemaAttrs(ttwschema, form_name))
    schema = SchemaClass(SCHEMATA_KEY, bases=(baseSchema, ), attrs=attrs)
    finalizeSchemas(schema)
    return schema
def getFromBaseSchema(baseSchema, form_name=None):
    attrs = copySchemaAttrs(baseSchema, form_name)
    ttwschema = get_ttw_edited_schema()
    if ttwschema:
        attrs.update(copySchemaAttrs(ttwschema, form_name))
    schema = SchemaClass(SCHEMATA_KEY,
                         bases=(baseSchema,),
                         attrs=attrs)
    finalizeSchemas(schema)
    return schema
def copy_schema(schema, filter_serializable=False):
    fields = {}
    for item in schema:
        if filter_serializable and not is_serialisable_field(schema[item]):
            continue
        fields[item] = schema[item]
    oschema = SchemaClass(SCHEMATA_KEY, attrs=fields)
    # copy base tagged values
    for i in schema.getTaggedValueTags():
        oschema.setTaggedValue(item, schema.queryTaggedValue(i))
    finalizeSchemas(oschema)
    return oschema
Beispiel #5
0
def copy_schema(schema, filter_serializable=False):
    fields = {}
    for item in schema:
        if (filter_serializable and not is_serialisable_field(schema[item])):
            continue
        fields[item] = schema[item]
    oschema = SchemaClass(SCHEMATA_KEY, attrs=fields)
    # copy base tagged values
    for i in schema.getTaggedValueTags():
        oschema.setTaggedValue(item, schema.queryTaggedValue(i))
    finalizeSchemas(oschema)
    return oschema
def serialize_ttw_schema(schema=None):
    if not schema:
        schema = get_ttw_edited_schema()
    bfields = [a for a in IUserDataSchema]
    attrs = {}
    for name in schema:
        f = schema[name]
        if is_serialisable_field(f) and name not in bfields:
            attrs[name] = f
    smember = SchemaClass(SCHEMATA_KEY, attrs=attrs)
    finalizeSchemas(smember)
    model = Model({SCHEMATA_KEY: smember})
    sschema = serialize(model)
    return sschema
def serialize_ttw_schema(schema=None):
    if not schema:
        schema = get_ttw_edited_schema()
    bfields = [a for a in IUserDataSchema]
    attrs = {}
    for name in schema:
        f = schema[name]
        if is_serialisable_field(f) and name not in bfields:
            attrs[name] = f
    smember = SchemaClass(SCHEMATA_KEY, attrs=attrs)
    finalizeSchemas(smember)
    model = Model({SCHEMATA_KEY: smember})
    sschema = serialize(model)
    return sschema
    def getSchema(self):
        """
        """
        def copySchemaAttrs(schema):
            return dict([(a, copy.deepcopy(schema[a])) for a in schema])

        attrs = copySchemaAttrs(self.baseSchema)
        ttwschema = get_ttw_edited_schema()
        if ttwschema:
            attrs.update(copySchemaAttrs(ttwschema))
        schema = SchemaClass(SCHEMATA_KEY,
                             bases=(self.baseSchema, ),
                             attrs=attrs)
        finalizeSchemas(schema)
        return schema
Beispiel #9
0
    def test_schema_directives_store_tagged_values(self):

        class IDummy(model.Schema):

            directives.read_permission(foo='zope2.View')
            directives.write_permission(foo='cmf.ModifyPortalContent')

            foo = zope.schema.TextLine(title=u"Foo")

        model.finalizeSchemas(IDummy)

        self.assertEqual({'foo': 'zope2.View'},
                         IDummy.queryTaggedValue(READ_PERMISSIONS_KEY))
        self.assertEqual({'foo': 'cmf.ModifyPortalContent'},
                         IDummy.queryTaggedValue(WRITE_PERMISSIONS_KEY))
Beispiel #10
0
    def test_schema_directives_store_tagged_values(self):
        class IDummy(model.Schema):

            form.omitted('foo', 'bar')
            form.omitted(model.Schema, 'qux')
            form.no_omit(model.Schema, 'bar')
            form.widget(foo='some.dummy.Widget', baz='other.Widget')
            form.mode(bar='hidden')
            form.mode(model.Schema, bar='input')
            form.order_before(baz='title')
            form.order_after(qux='title')
            form.read_permission(foo='zope2.View')
            form.write_permission(foo='cmf.ModifyPortalContent')

            foo = zope.schema.TextLine(title=u"Foo")
            bar = zope.schema.TextLine(title=u"Bar")
            baz = zope.schema.TextLine(title=u"Baz")
            qux = zope.schema.TextLine(title=u"Qux")

        model.finalizeSchemas(IDummy)

        self.assertEqual({
            'foo': 'some.dummy.Widget',
            'baz': 'other.Widget'
        }, IDummy.queryTaggedValue(WIDGETS_KEY))
        self.assertEqual([(Interface, 'foo', 'true'),
                          (Interface, 'bar', 'true'),
                          (model.Schema, 'qux', 'true'),
                          (model.Schema, 'bar', 'false')],
                         IDummy.queryTaggedValue(OMITTED_KEY))
        self.assertEqual([(Interface, 'bar', 'hidden'),
                          (model.Schema, 'bar', 'input')],
                         IDummy.queryTaggedValue(MODES_KEY))
        self.assertEqual([(
            'baz',
            'before',
            'title',
        ), ('qux', 'after', 'title')], IDummy.queryTaggedValue(ORDER_KEY))
        self.assertEqual({'foo': 'zope2.View'},
                         IDummy.queryTaggedValue(READ_PERMISSIONS_KEY))
        self.assertEqual({'foo': 'cmf.ModifyPortalContent'},
                         IDummy.queryTaggedValue(WRITE_PERMISSIONS_KEY))
Beispiel #11
0
    def test_schema_directives_store_tagged_values(self):

        class IDummy(model.Schema):

            form.omitted('foo', 'bar')
            form.omitted(model.Schema, 'qux')
            form.no_omit(model.Schema, 'bar')
            form.widget(foo='some.dummy.Widget', baz='other.Widget')
            form.mode(bar='hidden')
            form.mode(model.Schema, bar='input')
            form.order_before(baz='title')
            form.order_after(qux='title')
            form.read_permission(foo='zope2.View')
            form.write_permission(foo='cmf.ModifyPortalContent')

            foo = zope.schema.TextLine(title=u"Foo")
            bar = zope.schema.TextLine(title=u"Bar")
            baz = zope.schema.TextLine(title=u"Baz")
            qux = zope.schema.TextLine(title=u"Qux")

        model.finalizeSchemas(IDummy)

        self.assertEqual({'foo': 'some.dummy.Widget',
                          'baz': 'other.Widget'},
                         IDummy.queryTaggedValue(WIDGETS_KEY))
        self.assertEqual([(Interface, 'foo', 'true'),
                          (Interface, 'bar', 'true'),
                          (model.Schema, 'qux', 'true'),
                          (model.Schema, 'bar', 'false')],
                         IDummy.queryTaggedValue(OMITTED_KEY))
        self.assertEqual([(Interface, 'bar', 'hidden'),
                          (model.Schema, 'bar', 'input')],
                         IDummy.queryTaggedValue(MODES_KEY))
        self.assertEqual([('baz', 'before', 'title',),
                          ('qux', 'after', 'title')],
                         IDummy.queryTaggedValue(ORDER_KEY))
        self.assertEqual({'foo': 'zope2.View'},
                         IDummy.queryTaggedValue(READ_PERMISSIONS_KEY))
        self.assertEqual({'foo': 'cmf.ModifyPortalContent'},
                         IDummy.queryTaggedValue(WRITE_PERMISSIONS_KEY))
Beispiel #12
0
    def test_schema_directives_store_tagged_values(self):
        class IDummy(model.Schema):

            form.omitted("foo", "bar")
            form.omitted(model.Schema, "qux")
            form.no_omit(model.Schema, "bar")
            form.widget(foo="some.dummy.Widget", baz="other.Widget")
            form.mode(bar="hidden")
            form.mode(model.Schema, bar="input")
            form.order_before(baz="title")
            form.order_after(qux="title")
            form.read_permission(foo="zope2.View")
            form.write_permission(foo="cmf.ModifyPortalContent")

            foo = zope.schema.TextLine(title=u"Foo")
            bar = zope.schema.TextLine(title=u"Bar")
            baz = zope.schema.TextLine(title=u"Baz")
            qux = zope.schema.TextLine(title=u"Qux")

        model.finalizeSchemas(IDummy)

        self.assertEquals({"foo": "some.dummy.Widget", "baz": "other.Widget"}, IDummy.queryTaggedValue(WIDGETS_KEY))
        self.assertEquals(
            [
                (Interface, "foo", "true"),
                (Interface, "bar", "true"),
                (model.Schema, "qux", "true"),
                (model.Schema, "bar", "false"),
            ],
            IDummy.queryTaggedValue(OMITTED_KEY),
        )
        self.assertEquals(
            [(Interface, "bar", "hidden"), (model.Schema, "bar", "input")], IDummy.queryTaggedValue(MODES_KEY)
        )
        self.assertEquals([("baz", "before", "title"), ("qux", "after", "title")], IDummy.queryTaggedValue(ORDER_KEY))
        self.assertEquals({"foo": "zope2.View"}, IDummy.queryTaggedValue(READ_PERMISSIONS_KEY))
        self.assertEquals({"foo": "cmf.ModifyPortalContent"}, IDummy.queryTaggedValue(WRITE_PERMISSIONS_KEY))
Beispiel #13
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')