def object_dict(objects, by_ref=False, error_message=None, error_dict=None):
 if by_ref:
  items = ((obj.ref, obj) for obj in objects)
 else:
  items = ((obj.name, obj) for obj in objects)
 ordered = OrderedDict()
 for (key, value) in items:
  if (key in ordered):
   error_message = (error_message or 'Duplicate key {key}')
   error_dict = (error_dict or {})
   raise ModelError(error_message.format(key=key, **error_dict))
  ordered[key] = value
 return ordered

def object_dict ( objects , by_ref = False , error_message = None , error_dict = None ) : if by_ref : items = ( ( obj . ref , obj ) for obj in objects ) else : items = ( ( obj . name , obj ) for obj in objects ) ordered = OrderedDict ( ) for ( key , value ) in items : if ( key in ordered ) : error_message = ( error_message or 'Duplicate key {key}' ) error_dict = ( error_dict or { } ) raise ModelError ( error_message . format ( key = key , ** error_dict ) ) ordered [ key ] = value return ordered
make an ordered dictionary from model objects objects where keys are object names .