def table_dict_save(table_dict, ModelClass, context):
 model = context['model']
 session = context['session']
 table = class_mapper(ModelClass).mapped_table
 obj = None
 unique_constraints = get_unique_constraints(table, context)
 id = table_dict.get('id')
 if id:
  obj = session.query(ModelClass).get(id)
 if (not obj):
  unique_constraints = get_unique_constraints(table, context)
  for constraint in unique_constraints:
   params = dict(((key, table_dict.get(key)) for key in constraint))
   obj = session.query(ModelClass).filter_by(**params).first()
   if obj:
    break
 if (not obj):
  obj = ModelClass()
 for (key, value) in table_dict.iteritems():
  if isinstance(value, list):
   continue
  setattr(obj, key, value)
 session.add(obj)
 return obj

def table_dict_save ( table_dict , ModelClass , context ) : model = context [ 'model' ] session = context [ 'session' ] table = class_mapper ( ModelClass ) . mapped_table obj = None unique_constraints = get_unique_constraints ( table , context ) id = table_dict . get ( 'id' ) if id : obj = session . query ( ModelClass ) . get ( id ) if ( not obj ) : unique_constraints = get_unique_constraints ( table , context ) for constraint in unique_constraints : params = dict ( ( ( key , table_dict . get ( key ) ) for key in constraint ) ) obj = session . query ( ModelClass ) . filter_by ( ** params ) . first ( ) if obj : break if ( not obj ) : obj = ModelClass ( ) for ( key , value ) in table_dict . iteritems ( ) : if isinstance ( value , list ) : continue setattr ( obj , key , value ) session . add ( obj ) return obj
given a dict and a model class .