def test_serialize_custom_member_schema(self): from plone.app.users.browser.schemaeditor import applySchema member_schema = """ <model xmlns="http://namespaces.plone.org/supermodel/schema" xmlns:form="http://namespaces.plone.org/supermodel/form" xmlns:users="http://namespaces.plone.org/supermodel/users" xmlns:i18n="http://xml.zope.org/namespaces/i18n" i18n:domain="plone"> <schema name="member-fields"> <field name="twitter" type="zope.schema.TextLine" users:forms="In User Profile"> <description i18n:translate="help_twitter"> Twitter account </description> <required>False</required> <title i18n:translate="label_twitter">Twitter Account</title> </field> </schema> </model> """ applySchema(member_schema) user = api.user.create(email='*****@*****.**', username='******', properties={'twitter': 'TheRealDuck'}) res = self.serialize(user) self.assertIn('twitter', res) self.assertEqual(res['twitter'], 'TheRealDuck')
def import_schema(context): """Import TTW Schema """ data = context.readDataFile(FILE) if data is None: return ttw.applySchema(data) logger.info('Imported schema')
def import_schema(context): """Import TTW Schema """ data = context.readDataFile(FILE) if data is None: return if six.PY3 and isinstance(data, bytes): data = data.decode('utf-8') ttw.applySchema(data) logger.info('Imported schema')
def updateMemberSchema(): """ we need to manually add the schema in this way because otherwise old schema will be replaced by the new in userschema.xml """ new_xml = etree.fromstring(snew_schema) old_xml = etree.fromstring(get_schema()) new_fields = new_xml.findall( './/{http://namespaces.plone.org/supermodel/schema}field') old_schema = old_xml.findall( './/{http://namespaces.plone.org/supermodel/schema}schema')[0] for new_field in new_fields: old_schema.append(new_field) ttw.applySchema(etree.tostring(old_xml)) logger.info('Add personal_bookmarks in member-fields')
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')
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')