(self, value, doc, transform_dates)
return value
Transform the given value with the transform specified in self.item.transform.
        Also transform dates if the transform_dates flag is true.
Transform the given value with the transform specified in self.item.transform.
        Also transform dates if the transform_dates flag is true.
Transform the given value with the transform specified in self . item . transform . Also transform dates if the transform_dates flag is true .
def _transform(self, value, doc, transform_dates):
        """
        Transform the given value with the transform specified in self.item.transform.
        Also transform dates if the transform_dates flag is true.
        """

        # When XML elements have additional attributes in them, the text node is
        # put inside of the #text key. For example:
        #
        # <element id="123">value</element>  -> {'#text': 'value', 'id':'123'}
        #
        # Whereas elements without additional attributes just take on the string value:
        #
        # <element>value</element>  -> 'value'
        #
        # This line ensures that we grab the actual value instead of the dictionary
        if isinstance(value, dict):
            if '#text' in value:
                value = value.get('#text')
            else:
                return EMPTY_VALUE

        if transform_dates:
            value = couch_to_excel_datetime(value, doc)
        if self.item.transform:
            value = TRANSFORM_FUNCTIONS[self.item.transform](value, doc)
        if self.deid_transform:
            try:
                value = DEID_TRANSFORM_FUNCTIONS[self.deid_transform](value, doc)
            except ValueError:
                # Unable to convert the string to a date
                pass
        if value is None:
            value = MISSING_VALUE

        if isinstance(value, list):
            def _serialize(str_or_dict):
                """
                Serialize old data for scalar questions that were previously a repeat

                This is a total edge case. See https://manage.dimagi.com/default.asp?280549.
                """
                if isinstance(str_or_dict, dict):
                    return ','.join('{}={}'.format(k, v) for k, v in str_or_dict.items())
                else:
                    return str_or_dict

            value = ' '.join(_serialize(elem) for elem in value)
        return value
def _transform ( self , value , doc , transform_dates ) : # When XML elements have additional attributes in them, the text node is # put inside of the #text key. For example: # # <element id="123">value</element>  -> {'#text': 'value', 'id':'123'} # # Whereas elements without additional attributes just take on the string value: # # <element>value</element>  -> 'value' # # This line ensures that we grab the actual value instead of the dictionary if isinstance ( value , dict ) : if '#text' in value : value = value . get ( '#text' ) else : return EMPTY_VALUE if transform_dates : value = couch_to_excel_datetime ( value , doc ) if self . item . transform : value = TRANSFORM_FUNCTIONS [ self . item . transform ] ( value , doc ) if self . deid_transform : try : value = DEID_TRANSFORM_FUNCTIONS [ self . deid_transform ] ( value , doc ) except ValueError : # Unable to convert the string to a date pass if value is None : value = MISSING_VALUE if isinstance ( value , list ) : def _serialize ( str_or_dict ) : """
                Serialize old data for scalar questions that were previously a repeat

                This is a total edge case. See https://manage.dimagi.com/default.asp?280549.
                """ if isinstance ( str_or_dict , dict ) : return ',' . join ( '{}={}' . format ( k , v ) for k , v in str_or_dict . items ( ) ) else : return str_or_dict value = ' ' . join ( _serialize ( elem ) for elem in value ) return value