Exemple #1
0
    def get_properties(self, obj, context):
        if obj.many:
            return UNSET

        properties = {}

        for name, field in obj.fields.items():
            prop = compat.get_data_key(field)
            properties[prop] = context.convert(field, context)

        return properties
Exemple #2
0
    def get_required(self, obj, context):
        if obj.many:
            return UNSET

        required = []

        for name, field in obj.fields.items():
            if field.required:
                prop = compat.get_data_key(field)
                required.append(prop)

        return required if required else UNSET
def get_schema_fields(schema):
    """Retrieve all the names and field objects for a marshmallow Schema

    :param m.Schema schema:
    :returns: Yields tuples of the field name and the field itself
    :rtype: typing.Iterator[typing.Tuple[str, m.fields.Field]]
    """
    fields = []
    for name, field in schema.fields.items():
        prop = compat.get_data_key(field)
        fields.append((prop, field))
    return sorted(fields)
    def get_required(self, obj, context):
        if obj.many or obj.partial is True:
            return UNSET

        required = []
        obj_partial_is_collection = m.utils.is_collection(obj.partial)

        for name, field in obj.fields.items():
            if field.required:
                prop = compat.get_data_key(field)
                if obj_partial_is_collection and prop in obj.partial:
                    continue
                required.append(prop)

        if required and not obj.ordered:
            required = sorted(required)
        return required if required else UNSET