Ticket #186: refactor-function-get-list.patch

File refactor-function-get-list.patch, 1.6 KB (added by rmunn@…, 19 years ago)

Proposed patch to refactor function_get_list

  • django/core/meta.py

     
    10451045            setattr(obj, f.rel.get_cache_name(), rel_obj)
    10461046    return obj, index_end
    10471047
    1048 def function_get_list(opts, klass, **kwargs):
    1049     # kwargs['select'] is a dictionary, and dictionaries' key order is
    1050     # undefined, so we convert it to a list of tuples internally.
    1051     kwargs['select'] = kwargs.get('select', {}).items()
    1052 
    1053     cursor = db.db.cursor()
    1054     select, sql, params = function_get_sql_clause(opts, **kwargs)
    1055     cursor.execute("SELECT " + (kwargs.get('distinct') and "DISTINCT " or "") + ",".join(select) + sql, params)
    1056     obj_list = []
    1057     fill_cache = kwargs.get('select_related')
    1058     index_end = len(opts.fields)
    1059     for row in cursor.fetchall():
    1060         if fill_cache:
    1061             obj, index_end = _get_cached_row(opts, row, 0)
    1062         else:
    1063             obj = klass(*row[:index_end])
    1064         for i, k in enumerate(kwargs['select']):
    1065             setattr(obj, k[0], row[index_end+i])
    1066         obj_list.append(obj)
    1067     return obj_list
    1068 
    10691048def function_get_iterator(opts, klass, **kwargs):
    10701049    # kwargs['select'] is a dictionary, and dictionaries' key order is
    10711050    # undefined, so we convert it to a list of tuples internally.
     
    10891068                setattr(obj, k[0], row[index_end+i])
    10901069            yield obj
    10911070
     1071def function_get_list(opts, klass, **kwargs):
     1072    return list(function_get_iterator(opts, klass, **kwargs))
     1073
    10921074def function_get_count(opts, **kwargs):
    10931075    kwargs['order_by'] = []
    10941076    kwargs['offset'] = None
Back to Top