1
0
mirror of https://github.com/django/django.git synced 2025-10-31 09:41:08 +00:00

A large number of stylistic cleanups across django/db/

This commit is contained in:
Alex Gaynor
2013-07-08 10:39:54 +10:00
parent 0b69a75502
commit 03d9566e0d
48 changed files with 383 additions and 195 deletions

View File

@@ -351,7 +351,7 @@ class QuerySet(object):
if objs_with_pk:
self._batched_insert(objs_with_pk, fields, batch_size)
if objs_without_pk:
fields= [f for f in fields if not isinstance(f, AutoField)]
fields = [f for f in fields if not isinstance(f, AutoField)]
self._batched_insert(objs_without_pk, fields, batch_size)
return objs
@@ -818,7 +818,7 @@ class QuerySet(object):
return
ops = connections[self.db].ops
batch_size = (batch_size or max(ops.bulk_batch_size(fields, objs), 1))
for batch in [objs[i:i+batch_size]
for batch in [objs[i:i + batch_size]
for i in range(0, len(objs), batch_size)]:
self.model._base_manager._insert(batch, fields=fields,
using=self.db)
@@ -899,10 +899,12 @@ class QuerySet(object):
# empty" result.
value_annotation = True
class InstanceCheckMeta(type):
def __instancecheck__(self, instance):
return instance.query.is_empty()
class EmptyQuerySet(six.with_metaclass(InstanceCheckMeta)):
"""
Marker class usable for checking if a queryset is empty by .none():
@@ -912,6 +914,7 @@ class EmptyQuerySet(six.with_metaclass(InstanceCheckMeta)):
def __init__(self, *args, **kwargs):
raise TypeError("EmptyQuerySet can't be instantiated")
class ValuesQuerySet(QuerySet):
def __init__(self, *args, **kwargs):
super(ValuesQuerySet, self).__init__(*args, **kwargs)
@@ -1240,7 +1243,7 @@ def get_klass_info(klass, max_depth=0, cur_depth=0, requested=None,
only_load.get(o.model), reverse=True):
next = requested[o.field.related_query_name()]
parent = klass if issubclass(o.model, klass) else None
klass_info = get_klass_info(o.model, max_depth=max_depth, cur_depth=cur_depth+1,
klass_info = get_klass_info(o.model, max_depth=max_depth, cur_depth=cur_depth + 1,
requested=next, only_load=only_load, from_parent=parent)
reverse_related_fields.append((o.field, klass_info))
if field_names:
@@ -1251,7 +1254,7 @@ def get_klass_info(klass, max_depth=0, cur_depth=0, requested=None,
return klass, field_names, field_count, related_fields, reverse_related_fields, pk_idx
def get_cached_row(row, index_start, using, klass_info, offset=0,
def get_cached_row(row, index_start, using, klass_info, offset=0,
parent_data=()):
"""
Helper function that recursively returns an object with the specified
@@ -1276,11 +1279,10 @@ def get_cached_row(row, index_start, using, klass_info, offset=0,
return None
klass, field_names, field_count, related_fields, reverse_related_fields, pk_idx = klass_info
fields = row[index_start : index_start + field_count]
fields = row[index_start:index_start + field_count]
# If the pk column is None (or the Oracle equivalent ''), then the related
# object must be non-existent - set the relation to None.
if fields[pk_idx] == None or fields[pk_idx] == '':
if fields[pk_idx] is None or fields[pk_idx] == '':
obj = None
elif field_names:
fields = list(fields)
@@ -1510,8 +1512,6 @@ def prefetch_related_objects(result_cache, related_lookups):
if len(result_cache) == 0:
return # nothing to do
model = result_cache[0].__class__
# We need to be able to dynamically add to the list of prefetch_related
# lookups that we look up (see below). So we need some book keeping to
# ensure we don't do duplicate work.
@@ -1538,7 +1538,7 @@ def prefetch_related_objects(result_cache, related_lookups):
if len(obj_list) == 0:
break
current_lookup = LOOKUP_SEP.join(attrs[0:level+1])
current_lookup = LOOKUP_SEP.join(attrs[:level + 1])
if current_lookup in done_queries:
# Skip any prefetching, and any object preparation
obj_list = done_queries[current_lookup]