(form_id, form_data)
return found_old
Cleans up old format metadata to our current standard.

    Does NOT save the doc, but returns whether the doc needs to be saved.
Cleans up old format metadata to our current standard.
Cleans up old format metadata to our current standard .
def scrub_form_meta(form_id, form_data):
    """
    Cleans up old format metadata to our current standard.

    Does NOT save the doc, but returns whether the doc needs to be saved.
    """
    property_map = {'TimeStart': 'timeStart',
                    'TimeEnd': 'timeEnd',
                    'chw_id': 'userID',
                    'DeviceID': 'deviceID',
                    'uid': 'instanceID'}

    # hack to make sure uppercase meta still ends up in the right place
    found_old = False
    if 'Meta' in form_data:
        form_data['meta'] = form_data['Meta']
        del form_data['Meta']
        found_old = True
    if 'meta' in form_data:
        meta_block = form_data['meta']
        # scrub values from 0.9 to 1.0
        if isinstance(meta_block, list):
            if isinstance(meta_block[0], dict):
                # if it's a list of dictionaries, arbitrarily pick the first one
                # this is a pretty serious error, but it's also recoverable
                form_data['meta'] = meta_block = meta_block[0]
                logging.error((
                    'form %s contains multiple meta blocks. '
                    'this is not correct but we picked one abitrarily'
                ) % form_id)
            else:
                # if it's a list of something other than dictionaries.
                # don't bother scrubbing.
                logging.error('form %s contains a poorly structured meta block.'
                              'this might cause data display problems.')
        if isinstance(meta_block, dict):
            for key in list(meta_block):
                if key in property_map and property_map[key] not in meta_block:
                    meta_block[property_map[key]] = meta_block[key]
                    del meta_block[key]
                    found_old = True

    return found_old
def scrub_form_meta ( form_id , form_data ) : property_map = { 'TimeStart' : 'timeStart' , 'TimeEnd' : 'timeEnd' , 'chw_id' : 'userID' , 'DeviceID' : 'deviceID' , 'uid' : 'instanceID' } # hack to make sure uppercase meta still ends up in the right place found_old = False if 'Meta' in form_data : form_data [ 'meta' ] = form_data [ 'Meta' ] del form_data [ 'Meta' ] found_old = True if 'meta' in form_data : meta_block = form_data [ 'meta' ] # scrub values from 0.9 to 1.0 if isinstance ( meta_block , list ) : if isinstance ( meta_block [ 0 ] , dict ) : # if it's a list of dictionaries, arbitrarily pick the first one # this is a pretty serious error, but it's also recoverable form_data [ 'meta' ] = meta_block = meta_block [ 0 ] logging . error ( ( 'form %s contains multiple meta blocks. ' 'this is not correct but we picked one abitrarily' ) % form_id ) else : # if it's a list of something other than dictionaries. # don't bother scrubbing. logging . error ( 'form %s contains a poorly structured meta block.' 'this might cause data display problems.' ) if isinstance ( meta_block , dict ) : for key in list ( meta_block ) : if key in property_map and property_map [ key ] not in meta_block : meta_block [ property_map [ key ] ] = meta_block [ key ] del meta_block [ key ] found_old = True return found_old