From d8ef66b17d5361c2c56b3ae04af82f3a619b69e6 Mon Sep 17 00:00:00 2001 From: Adrian Holovaty Date: Tue, 26 Jul 2005 23:04:50 +0000 Subject: [PATCH] Fixed #186 -- Refactored meta.py to remove duplicate code between function_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 --- django/core/meta.py | 24 +++--------------------- 1 file changed, 3 insertions(+), 21 deletions(-) diff --git a/django/core/meta.py b/django/core/meta.py index a8e0b181067..00e0bf9fad1 100644 --- a/django/core/meta.py +++ b/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