Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #186 -- Refactored meta.py to remove duplicate code between fun…

…ction_get_list and function_get_iterator. Thanks, rmunn@pobox.com

git-svn-id: http://code.djangoproject.com/svn/django/trunk@329 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit d8ef66b17d5361c2c56b3ae04af82f3a619b69e6 1 parent f188d59
Adrian Holovaty authored July 26, 2005

Showing 1 changed file with 3 additions and 21 deletions. Show diff stats Hide diff stats

  1. 24  django/core/meta.py
24  django/core/meta.py
@@ -1047,27 +1047,6 @@ def _get_cached_row(opts, row, index_start):
1047 1047
             setattr(obj, f.rel.get_cache_name(), rel_obj)
1048 1048
     return obj, index_end
1049 1049
 
1050  
-def function_get_list(opts, klass, **kwargs):
1051  
-    # kwargs['select'] is a dictionary, and dictionaries' key order is
1052  
-    # undefined, so we convert it to a list of tuples internally.
1053  
-    kwargs['select'] = kwargs.get('select', {}).items()
1054  
-
1055  
-    cursor = db.db.cursor()
1056  
-    select, sql, params = function_get_sql_clause(opts, **kwargs)
1057  
-    cursor.execute("SELECT " + (kwargs.get('distinct') and "DISTINCT " or "") + ",".join(select) + sql, params)
1058  
-    obj_list = []
1059  
-    fill_cache = kwargs.get('select_related')
1060  
-    index_end = len(opts.fields)
1061  
-    for row in cursor.fetchall():
1062  
-        if fill_cache:
1063  
-            obj, index_end = _get_cached_row(opts, row, 0)
1064  
-        else:
1065  
-            obj = klass(*row[:index_end])
1066  
-        for i, k in enumerate(kwargs['select']):
1067  
-            setattr(obj, k[0], row[index_end+i])
1068  
-        obj_list.append(obj)
1069  
-    return obj_list
1070  
-
1071 1050
 def function_get_iterator(opts, klass, **kwargs):
1072 1051
     # kwargs['select'] is a dictionary, and dictionaries' key order is
1073 1052
     # undefined, so we convert it to a list of tuples internally.
@@ -1091,6 +1070,9 @@ def function_get_iterator(opts, klass, **kwargs):
1091 1070
                 setattr(obj, k[0], row[index_end+i])
1092 1071
             yield obj
1093 1072
 
  1073
+def function_get_list(opts, klass, **kwargs):
  1074
+    return list(function_get_iterator(opts, klass, **kwargs))
  1075
+
1094 1076
 def function_get_count(opts, **kwargs):
1095 1077
     kwargs['order_by'] = []
1096 1078
     kwargs['offset'] = None

0 notes on commit d8ef66b

Please sign in to comment.
Something went wrong with that request. Please try again.