def model_query(context, model, *args, **kwargs):
 session = (kwargs.get('session') or get_session())
 read_deleted = (kwargs.get('read_deleted') or context.read_deleted)
 project_only = kwargs.get('project_only', False)
 def issubclassof_nova_base(obj):
  return (isinstance(obj, type) and issubclass(obj, models.NovaBase))
 base_model = model
 if (not issubclassof_nova_base(base_model)):
  base_model = kwargs.get('base_model', None)
  if (not issubclassof_nova_base(base_model)):
   raise Exception(_('model or base_model parameter should be subclass of NovaBase'))
 query = session.query(model, *args)
 default_deleted_value = base_model.__mapper__.c.deleted.default.arg
 if (read_deleted == 'no'):
  query = query.filter((base_model.deleted == default_deleted_value))
 elif (read_deleted == 'yes'):
  pass
 elif (read_deleted == 'only'):
  query = query.filter((base_model.deleted != default_deleted_value))
 else:
  raise Exception((_("Unrecognized read_deleted value '%s'") % read_deleted))
 if (nova.context.is_user_context(context) and project_only):
  if (project_only == 'allow_none'):
   query = query.filter(or_((base_model.project_id == context.project_id), (base_model.project_id == None)))
  else:
   query = query.filter_by(project_id=context.project_id)
 return query

def model_query ( context , model , * args , ** kwargs ) : session = ( kwargs . get ( 'session' ) or get_session ( ) ) read_deleted = ( kwargs . get ( 'read_deleted' ) or context . read_deleted ) project_only = kwargs . get ( 'project_only' , False ) def issubclassof_nova_base ( obj ) : return ( isinstance ( obj , type ) and issubclass ( obj , models . NovaBase ) ) base_model = model if ( not issubclassof_nova_base ( base_model ) ) : base_model = kwargs . get ( 'base_model' , None ) if ( not issubclassof_nova_base ( base_model ) ) : raise Exception ( _ ( 'model or base_model parameter should be subclass of NovaBase' ) ) query = session . query ( model , * args ) default_deleted_value = base_model . __mapper__ . c . deleted . default . arg if ( read_deleted == 'no' ) : query = query . filter ( ( base_model . deleted == default_deleted_value ) ) elif ( read_deleted == 'yes' ) : pass elif ( read_deleted == 'only' ) : query = query . filter ( ( base_model . deleted != default_deleted_value ) ) else : raise Exception ( ( _ ( "Unrecognized read_deleted value '%s'" ) % read_deleted ) ) if ( nova . context . is_user_context ( context ) and project_only ) : if ( project_only == 'allow_none' ) : query = query . filter ( or_ ( ( base_model . project_id == context . project_id ) , ( base_model . project_id == None ) ) ) else : query = query . filter_by ( project_id = context . project_id ) return query
query helper that accounts for contexts read_deleted field .