From: poe <svn...@pl...> - 2006-01-27 16:16:50
|
Author: poe Date: Fri Jan 27 16:16:09 2006 New Revision: 18588 Modified: ATSchemaEditorNG/trunk/SchemaEditor.py ATSchemaEditorNG/trunk/skins/atse_templates/atse_dump_schema.py Log: The schema dumper now dumps everything in the schema. Modified: ATSchemaEditorNG/trunk/SchemaEditor.py ============================================================================== --- ATSchemaEditorNG/trunk/SchemaEditor.py (original) +++ ATSchemaEditorNG/trunk/SchemaEditor.py Fri Jan 27 16:16:09 2006 @@ -825,6 +825,53 @@ field=name) ###################################################################### + # Hook for schema dumper + ###################################################################### + + security.declareProtected(ManageSchemaPermission, 'atse_dumpSchemata') + def atse_dumpSchemata(self,schema_id, schemata_name): + dontDump = ["_layers","__name__","widget","index_method","accessor","storage","edit_accessor","mutator","generateMode","mode","validators"] + hasNewLine = re.compile("\n") + sch = self.atse_getSchemata(schema_id,schemata_name) + schemaString = "" + for sFields in sch.fields(): + schemaString += '\t%s("%s", \n' % (sch.atse_getFieldType(sFields), sFields.getName()) + for dFields in sFields.__dict__: + if dFields not in dontDump: + if getattr(sFields,dFields): + schemaString += '\t\t%s =' % dFields + fieldValue = getattr(sFields,dFields,'') + if isinstance(fieldValue,basestring): + schemaString += ' """%s""",\n' % fieldValue + else: + schemaString += ' %s,\n' % str(fieldValue) + schemaString += sch.atse_dumpWidget(sFields.widget) + schemaString += "\t),\n" + schemaString = re.sub(""","&quot;",schemaString) + schemaString = re.sub("\<","<",schemaString) + schemaString = re.sub("\>",">",schemaString) + return schemaString + + + security.declareProtected(ManageSchemaPermission, 'atse_dumpWidget') + def atse_dumpWidget(self,widget): + hasNewLine = re.compile("\n") + schemaString = "" + schemaString += '\t\twidget=%s(\n' % widget.getName() + + for wFields in widget.__dict__: + if getattr(widget,wFields): + schemaString += "\t\t\t%s =" % wFields + fieldValue = getattr(widget,wFields,'') + if isinstance(fieldValue,basestring): + schemaString += ' """%s""",\n' % fieldValue + else: + schemaString += ' %s,\n' % str(fieldValue) + schemaString += "\t\t),\n" + return schemaString + + + ###################################################################### # Hook for UI ###################################################################### Modified: ATSchemaEditorNG/trunk/skins/atse_templates/atse_dump_schema.py ============================================================================== --- ATSchemaEditorNG/trunk/skins/atse_templates/atse_dump_schema.py (original) +++ ATSchemaEditorNG/trunk/skins/atse_templates/atse_dump_schema.py Fri Jan 27 16:16:09 2006 @@ -2,8 +2,9 @@ # Dump schema # -# This code stinks but it works :-) +# This code stinks less and still works :-) +print "#<pre>" print "######################################################################" print "# Schema created by ATSchemaEditorNG #" print "# (C) 2004, ZOPYX Software Development and Consulting Andreas Jung #" @@ -20,38 +21,10 @@ for schemata_name in context.atse_getSchemataNames(schema_id): schemata = context.atse_getSchemata(schema_id, schemata_name) - for f in schemata.fields(): - widget = f.widget - s = '\t%s("%s", \n' % (context.atse_getFieldType(f), f.getName()) - s += '\t\tschemata="%s",\n' % schemata_name - s += '\t\trequired=%s,\n' % f.required - s += '\t\twidget=%s(\n' % widget.getName() - s += '\t\t\tlabel="%s",\n' % widget.label - s += '\t\t\tvisible=%s,\n' % widget.visible - s += '\t\t\tlabel_msgid="%s",\n' % getattr(widget, 'label_msgid', '') - s += '\t\t\tdescription="""%s""",\n' % getattr(widget, 'description', '') - s += '\t\t\ti18n_domain="%s",\n' % getattr(widget, 'i18n_domain', '') - - if widget.getName() == 'TextAreaWidget': - attrs = ('rows', 'cols', 'validators') - else: - attrs = ('size', 'validators') - - for attr in attrs: - if hasattr(widget, attr): - value = getattr(widget, attr) - if attr == 'validators' and isinstance(value, tuple): - value = filter(None, value) - if not value: value = () - if attr in ('rows', 'cols', 'size'): value = int(value) - if isinstance(value, int ) or isinstance(value, tuple): - s += '\t\t\t%s=%s,\n' % (attr, value) - else: - s += '\t\t\t%s="%s",\n' % (attr, value) - s += '\t\t), \n' - s += '\t), \n' - print s + schemataString = context.atse_dumpSchemata(schema_id, schemata_name) + print '%s' % schemataString print "))" +print "#</pre>" return printed |