#NEWLINE# def filter( self , * args , **kwargs ) : #NEWLINE# #INDENT# '\n        Adds WHERE arguments to the queryset, returning a new queryset\n\n        See :ref:`retrieving-objects-with-filters`\n\n        Returns a QuerySet filtered on the keyword arguments\n        ' #NEWLINE# if len ( [ x for x in kwargs . values ( ) if ( x is None ) ] ) : #NEWLINE# #INDENT# raise CQLEngineException ( 'None values on filter are not allowed' ) #NEWLINE# #UNINDENT# clone = copy . deepcopy ( self ) #NEWLINE# for operator in args : #NEWLINE# #INDENT# if ( not isinstance ( operator , WhereClause ) ) : #NEWLINE# #INDENT# raise QueryException ( '{0} is not a valid query operator' . format ( operator ) ) #NEWLINE# #UNINDENT# clone . _where . append ( operator ) #NEWLINE# #UNINDENT# for ( arg , val ) in kwargs . items ( ) : #NEWLINE# #INDENT# ( col_name , col_op ) = self . _parse_filter_arg ( arg ) #NEWLINE# quote_field = True #NEWLINE# if ( not isinstance ( val , Token ) ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# column = self . model . _get_column ( col_name ) #NEWLINE# #UNINDENT# except KeyError : #NEWLINE# #INDENT# raise QueryException ( "Can't resolve column name: '{0}'" . format ( v ) ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( col_name != 'pk__token' ) : #NEWLINE# #INDENT# raise QueryException ( "Token() values may only be compared to the 'pk__token' virtual column" ) #NEWLINE# #UNINDENT# column = columns . _PartitionKeysToken ( self . model ) #NEWLINE# quote_field = False #NEWLINE# partition_columns = column . partition_columns #NEWLINE# if ( len ( partition_columns ) != len ( val . value ) ) : #NEWLINE# #INDENT# raise QueryException ( 'Token() received {0} arguments but model has {1} partition keys' . format ( len ( val . value ) , len ( partition_columns ) ) ) #NEWLINE# #UNINDENT# val . set_columns ( partition_columns ) #NEWLINE# #UNINDENT# operator_class = BaseWhereOperator . get_operator ( ( col_op or 'EQ' ) ) #NEWLINE# operator = operator_class ( ) #NEWLINE# if isinstance ( operator , InOperator ) : #NEWLINE# #INDENT# if ( not isinstance ( val , ( list , tuple ) ) ) : #NEWLINE# #INDENT# raise QueryException ( 'IN queries must use a list/tuple value' ) #NEWLINE# #UNINDENT# query_val = [ column . to_database ( v ) for v in val ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if isinstance ( val , BaseQueryFunction ) : #NEWLINE# #INDENT# query_val = val #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( isinstance ( operator , ContainsOperator ) and isinstance ( column , ( columns . List , columns . Set , columns . Map ) ) ) : #NEWLINE# #INDENT# query_val = val #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# query_val = column . to_database ( val ) #NEWLINE# if ( not col_op ) : #NEWLINE# #INDENT# clone . _defer_fields . add ( col_name ) #NEWLINE# clone . _deferred_values [ column . db_field_name ] = val #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# clone . _where . append ( WhereClause ( column . db_field_name , operator , query_val , quote_field = quote_field ) ) #NEWLINE# #UNINDENT# return clone