def _fix_related_fields(srv, data, service_ids):
 if (srv[0] not in RELATED_FIELDS):
  return data
 for field in RELATED_FIELDS[srv[0]]:
  if (field[0] not in data):
   data[field[1]] = None
   continue
  old_value = data[field[0]]
  if (type(old_value) == list):
   ls = []
   for i in old_value:
    old_id = i['id']
    new_id = service_ids[field[2]][old_id]
    ls += [new_id]
   del data[field[0]]
   data[field[1]] = ls
  else:
   if (type(old_value) == dict):
    old_id = old_value['id']
   else:
    old_id = old_value
   del data[field[0]]
   if (old_id is None):
    data[field[1]] = None
   else:
    data[field[1]] = service_ids[field[2]][old_id]
 return data

def _fix_related_fields ( srv , data , service_ids ) : if ( srv [ 0 ] not in RELATED_FIELDS ) : return data for field in RELATED_FIELDS [ srv [ 0 ] ] : if ( field [ 0 ] not in data ) : data [ field [ 1 ] ] = None continue old_value = data [ field [ 0 ] ] if ( type ( old_value ) == list ) : ls = [ ] for i in old_value : old_id = i [ 'id' ] new_id = service_ids [ field [ 2 ] ] [ old_id ] ls += [ new_id ] del data [ field [ 0 ] ] data [ field [ 1 ] ] = ls else : if ( type ( old_value ) == dict ) : old_id = old_value [ 'id' ] else : old_id = old_value del data [ field [ 0 ] ] if ( old_id is None ) : data [ field [ 1 ] ] = None else : data [ field [ 1 ] ] = service_ids [ field [ 2 ] ] [ old_id ] return data
fixes the ids services which are related to others .