(self, data, options=None, name=None, depth=0)
return element
Exact duplicate of tastypie.serializers.Serializer.to_etree with modification because
        it does not expose sufficient APIs to customize just at the bundle level while reusing
        all this same envelope code.
Exact duplicate of tastypie.serializers.Serializer.to_etree with modification because
        it does not expose sufficient APIs to customize just at the bundle level while reusing
        all this same envelope code.
Exact duplicate of tastypie . serializers . Serializer . to_etree with modification because it does not expose sufficient APIs to customize just at the bundle level while reusing all this same envelope code .
def to_etree(self, data, options=None, name=None, depth=0):
        '''
        Exact duplicate of tastypie.serializers.Serializer.to_etree with modification because
        it does not expose sufficient APIs to customize just at the bundle level while reusing
        all this same envelope code.
        '''
        if isinstance(data, (list, tuple)):
            element = Element(name or 'objects')
            if name:
                element = Element(name)
                element.set('type', 'list')
            else:
                element = Element('objects')
            for item in data:
                element.append(self.to_etree(item, options, depth=depth + 1))
        elif isinstance(data, dict):
            if depth == 0:
                element = Element(name or 'response')
            else:
                element = Element(name or 'object')
                element.set('type', 'hash')
            for (key, value) in data.items():
                element.append(self.to_etree(value, options, name=key, depth=depth + 1))
        elif isinstance(data, Bundle):
            # next line is the part that is changed from
            # https://github.com/toastdriven/django-tastypie/blob/master/tastypie/serializers.py
            element = self.bundle_to_etree(data)
        elif hasattr(data, 'dehydrated_type'):
            if getattr(data, 'dehydrated_type', None) == 'related' and data.is_m2m is False:
                if data.full:
                    return self.to_etree(data.fk_resource, options, name, depth + 1)
                else:
                    return self.to_etree(data.value, options, name, depth + 1)
            elif getattr(data, 'dehydrated_type', None) == 'related' and data.is_m2m is True:
                if data.full:
                    element = Element(name or 'objects')
                    for bundle in data.m2m_bundles:
                        element.append(self.to_etree(bundle, options, bundle.resource_name, depth + 1))
                else:
                    element = Element(name or 'objects')
                    for value in data.value:
                        element.append(self.to_etree(value, options, name, depth=depth + 1))
            else:
                return self.to_etree(data.value, options, name)
        else:
            element = Element(name or 'value')
            simple_data = self.to_simple(data, options)
            data_type = get_type_string(simple_data)

            if data_type != 'string':
                element.set('type', get_type_string(simple_data))

            if data_type != 'null':
                if isinstance(simple_data, str):
                    element.text = simple_data
                else:
                    element.text = force_text(simple_data)

        return element
def to_etree ( self , data , options = None , name = None , depth = 0 ) : if isinstance ( data , ( list , tuple ) ) : element = Element ( name or 'objects' ) if name : element = Element ( name ) element . set ( 'type' , 'list' ) else : element = Element ( 'objects' ) for item in data : element . append ( self . to_etree ( item , options , depth = depth + 1 ) ) elif isinstance ( data , dict ) : if depth == 0 : element = Element ( name or 'response' ) else : element = Element ( name or 'object' ) element . set ( 'type' , 'hash' ) for ( key , value ) in data . items ( ) : element . append ( self . to_etree ( value , options , name = key , depth = depth + 1 ) ) elif isinstance ( data , Bundle ) : # next line is the part that is changed from # https://github.com/toastdriven/django-tastypie/blob/master/tastypie/serializers.py element = self . bundle_to_etree ( data ) elif hasattr ( data , 'dehydrated_type' ) : if getattr ( data , 'dehydrated_type' , None ) == 'related' and data . is_m2m is False : if data . full : return self . to_etree ( data . fk_resource , options , name , depth + 1 ) else : return self . to_etree ( data . value , options , name , depth + 1 ) elif getattr ( data , 'dehydrated_type' , None ) == 'related' and data . is_m2m is True : if data . full : element = Element ( name or 'objects' ) for bundle in data . m2m_bundles : element . append ( self . to_etree ( bundle , options , bundle . resource_name , depth + 1 ) ) else : element = Element ( name or 'objects' ) for value in data . value : element . append ( self . to_etree ( value , options , name , depth = depth + 1 ) ) else : return self . to_etree ( data . value , options , name ) else : element = Element ( name or 'value' ) simple_data = self . to_simple ( data , options ) data_type = get_type_string ( simple_data ) if data_type != 'string' : element . set ( 'type' , get_type_string ( simple_data ) ) if data_type != 'null' : if isinstance ( simple_data , str ) : element . text = simple_data else : element . text = force_text ( simple_data ) return element