def migrate_drafts_metadata_key(schema):
 drafts = DraftRegistration.find(Q('registration_schema', 'eq', schema))
 total_drafts = drafts.count()
 logger.info('Examining {} drafts for improper key'.format(total_drafts))
 draft_count = 0
 for draft in drafts:
  draft_count += 1
  if draft.registration_metadata.get('recommended-methods', {}).get('value', {}).get('undefined', {}):
   draft.registration_metadata['recommended-methods']['value']['procedure'] = draft.registration_metadata['recommended-methods']['value'].pop('undefined')
   draft.save()
   logger.info('{}/{} Migrated key for {}'.format(draft_count, total_drafts, draft._id))
  else:
   logger.info('{}/{} Key already correct for {}. No change.'.format(draft_count, drafts.count(), draft._id))

def migrate_drafts_metadata_key ( schema ) : drafts = DraftRegistration . find ( Q ( 'registration_schema' , 'eq' , schema ) ) total_drafts = drafts . count ( ) logger . info ( 'Examining {} drafts for improper key' . format ( total_drafts ) ) draft_count = 0 for draft in drafts : draft_count += 1 if draft . registration_metadata . get ( 'recommended-methods' , { } ) . get ( 'value' , { } ) . get ( 'undefined' , { } ) : draft . registration_metadata [ 'recommended-methods' ] [ 'value' ] [ 'procedure' ] = draft . registration_metadata [ 'recommended-methods' ] [ 'value' ] . pop ( 'undefined' ) draft . save ( ) logger . info ( '{}/{} Migrated key for {}' . format ( draft_count , total_drafts , draft . _id ) ) else : logger . info ( '{}/{} Key already correct for {}. No change.' . format ( draft_count , drafts . count ( ) , draft . _id ) )
finds veer draft registrations whose registration_metadata has an undefined key and corrects .