0
0
mirror of https://github.com/django/django.git synced 2024-11-29 22:56:46 +01:00

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
This commit is contained in:
Adrian Holovaty 2005-07-26 23:04:50 +00:00
parent f188d5930d
commit d8ef66b17d

View File

@ -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