Commits

Anonymous committed df84407

moved last bit of compiler code into backends

Comments (0)

Files changed (3)

dbindexer/backends.py

 from django.db.models.fields import FieldDoesNotExist
 from django.db.models.sql.constants import JOIN_TYPE, LHS_ALIAS, LHS_JOIN_COL, \
     TABLE_NAME, RHS_JOIN_COL
+from django.utils.tree import Node
 from djangotoolbox.fields import ListField
 from dbindexer.lookups import StandardLookup
 
             value = self.get_value(lookup.model, lookup.field_name, query)
             value = lookup.convert_value(value)
             query.values[position] = (self.get_index(lookup), value)
-            
+    
+    def convert_filters(self, query, filters):
+        model = query.model
+        for index, child in enumerate(filters.children[:]):
+            if isinstance(child, Node):
+                self.convert_filters(query, child)
+                continue
+
+            self.convert_filter(query, filters, child, index)
     
     def convert_filter(self, query, filters, child, index):
         constraint, lookup_type, annotation, value = child
         
         for model, field_name in reversed(zip(model_chain[1:-1], field_names[1:-1])):
             lookup = {'%s__%s' %(field_name, 'in'):(pk for pk in pks)}
-            # TODO: what if pks is empty?
+            # TODO: what haens if pks is empty?
             pks = model.objects.all().filter(**lookup)
         return pks

dbindexer/compiler.py

-from django.utils.tree import Node
 from resolver import resolver
 
 def __repr__(self):
 
 class BaseCompiler(object):
     def convert_filters(self, filters):
-        model = self.query.model
-        for index, child in enumerate(filters.children[:]):
-            if isinstance(child, Node):
-                self.convert_filters(child)
-                continue
-
-            constraint, lookup_type, annotation, value = child
-            resolver.convert_filter(self.query, filters, child, index)
+        resolver.convert_filters(self.query, filters)
 
 class SQLCompiler(BaseCompiler):
     def execute_sql(self, *args, **kwargs):

dbindexer/resolver.py

 	        return cls()
 	    except AttributeError:
 	        raise ImproperlyConfigured('Module "%s" does not define a "%s" backend' % (module_name, attr_name))
-		
-	def convert_filter(self, query, filters, child, index):
+	
+	def convert_filters(self, query, filters):
 		for backend in self.backends:
-			backend.convert_filter(query, filters, child, index)
+			backend.convert_filters(query, filters)
 			
 	def create_index(self, lookup):
 		for backend in self.backends: