Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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
@adrianholovaty adrianholovaty authored
Showing with 3 additions and 21 deletions.
  1. +3 −21 django/core/meta.py
View
24 django/core/meta.py
@@ -1047,27 +1047,6 @@ def _get_cached_row(opts, row, index_start):
setattr(obj, f.rel.get_cache_name(), rel_obj)
return obj, index_end
-def function_get_list(opts, klass, **kwargs):
- # kwargs['select'] is a dictionary, and dictionaries' key order is
- # undefined, so we convert it to a list of tuples internally.
- kwargs['select'] = kwargs.get('select', {}).items()
-
- cursor = db.db.cursor()
- select, sql, params = function_get_sql_clause(opts, **kwargs)
- cursor.execute("SELECT " + (kwargs.get('distinct') and "DISTINCT " or "") + ",".join(select) + sql, params)
- obj_list = []
- fill_cache = kwargs.get('select_related')
- index_end = len(opts.fields)
- for row in cursor.fetchall():
- if fill_cache:
- obj, index_end = _get_cached_row(opts, row, 0)
- else:
- obj = klass(*row[:index_end])
- for i, k in enumerate(kwargs['select']):
- setattr(obj, k[0], row[index_end+i])
- obj_list.append(obj)
- return obj_list
-
def function_get_iterator(opts, klass, **kwargs):
# kwargs['select'] is a dictionary, and dictionaries' key order is
# undefined, so we convert it to a list of tuples internally.
@@ -1091,6 +1070,9 @@ def function_get_iterator(opts, klass, **kwargs):
setattr(obj, k[0], row[index_end+i])
yield obj
+def function_get_list(opts, klass, **kwargs):
+ return list(function_get_iterator(opts, klass, **kwargs))
+
def function_get_count(opts, **kwargs):
kwargs['order_by'] = []
kwargs['offset'] = None
Please sign in to comment.
Something went wrong with that request. Please try again.