コード例 #1
0
    def dump(self, portal_type):
        log.info("Dumping schemas for portal_type %r" % portal_type)
        fti = self._get_fti(portal_type)
        type_title = translate_de(fti.title, domain=fti.i18n_domain)

        schemas = []
        schema_dumper = SchemaDumper()

        for schema in iterSchemataForType(portal_type):
            schema_dump = schema_dumper.dump(schema)
            schemas.append(schema_dump)

        type_dump = OrderedDict((
            ('portal_type', portal_type),
            ('title', type_title),
            ('schemas', schemas),
        ))

        return type_dump
コード例 #2
0
    def dump(self, portal_type):
            log.info("Dumping schemas for portal_type %r" % portal_type)
            fti = self._get_fti(portal_type)
            type_title = translate_de(fti.title, domain=fti.i18n_domain)

            schemas = []
            schema_dumper = SchemaDumper()

            for schema in iterSchemataForType(portal_type):
                schema_dump = schema_dumper.dump(schema)
                schemas.append(schema_dump)

            type_dump = OrderedDict((
                ('portal_type', portal_type),
                ('title', type_title),
                ('schemas', schemas),
            ))

            return type_dump
コード例 #3
0
ファイル: field.py プロジェクト: braegelno5/opengever.core
    def dump(self, field):
        log.info("    Dumping field %r" % field.getName())

        field_title = translate_de(field.title)
        field_desc = translate_de(field.description)
        field_type = field.__class__.__name__

        field_dump = OrderedDict((
            ('name', field.getName()),
            ('type', field_type),
            ('title', field_title),
            ('description', field_desc),
            ('required', field.required),
        ))

        if field_dump['type'] in STRING_TYPES:
            field_dump['max_length'] = field.max_length

        # Determine the field's default value
        log.debug("      Determining default...")
        default_value = self._get_default(field)
        if default_value is not NO_DEFAULT_MARKER:
            field_dump['default'] = default_value
            # Also remove a potential `required` flag from the field if there
            # is a default. The field may be tagged as being required on a
            # zope.schema level, but functionally it's not actually required
            # if a default value is defined.
            field_dump['required'] = False

        # Determine vocabulary, if applicable
        log.debug("      Determining vocabulary...")
        field_vocab = self._get_vocabulary(field)
        if field_vocab:
            field_dump['vocabulary'] = field_vocab

        # Field omitted?
        omitted = self._get_omitted_for_field(field)
        if omitted:
            field_dump['omitted'] = omitted

        # Field modes
        modes_for_field = self._get_modes_for_field(field)
        if modes_for_field:
            field_dump['modes'] = modes_for_field

        if isinstance(field, Choice):
            # Include the value type of the field by looking at the
            # terms in the vocabulary
            vocab_type = type(field_vocab[0])
            assert all(isinstance(item, vocab_type) for item in field_vocab)
            value_type = PYTHON_TO_JS_TYPES[vocab_type]
            field_dump['value_type'] = value_type

        try:
            json.dumps(field_dump)
        except TypeError:
            msg = "Failed to convert dump for field {!r} to JSON!"
            log.error(msg.format(field.getName()))
            pprint(field_dump)
            raise

        return field_dump