mirror of https://github.com/django/django.git
Fixed #13357 -- Minor changes to get Django running under PyPy. Thanks to Alex Gaynor for the patch.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@12991 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
a213599db7
commit
94a968cfc6
|
@ -73,7 +73,9 @@ class BaseModelAdmin(object):
|
|||
readonly_fields = ()
|
||||
|
||||
def __init__(self):
|
||||
self.formfield_overrides = dict(FORMFIELD_FOR_DBFIELD_DEFAULTS, **self.formfield_overrides)
|
||||
overrides = FORMFIELD_FOR_DBFIELD_DEFAULTS.copy()
|
||||
overrides.update(self.formfield_overrides)
|
||||
self.formfield_overrides = overrides
|
||||
|
||||
def formfield_for_dbfield(self, db_field, **kwargs):
|
||||
"""
|
||||
|
|
|
@ -42,13 +42,15 @@ class CacheClass(BaseCache):
|
|||
fname = self._key_to_file(key)
|
||||
try:
|
||||
f = open(fname, 'rb')
|
||||
exp = pickle.load(f)
|
||||
now = time.time()
|
||||
if exp < now:
|
||||
try:
|
||||
exp = pickle.load(f)
|
||||
now = time.time()
|
||||
if exp < now:
|
||||
self._delete(fname)
|
||||
else:
|
||||
return pickle.load(f)
|
||||
finally:
|
||||
f.close()
|
||||
self._delete(fname)
|
||||
else:
|
||||
return pickle.load(f)
|
||||
except (IOError, OSError, EOFError, pickle.PickleError):
|
||||
pass
|
||||
return default
|
||||
|
@ -67,9 +69,12 @@ class CacheClass(BaseCache):
|
|||
os.makedirs(dirname)
|
||||
|
||||
f = open(fname, 'wb')
|
||||
now = time.time()
|
||||
pickle.dump(now + timeout, f, pickle.HIGHEST_PROTOCOL)
|
||||
pickle.dump(value, f, pickle.HIGHEST_PROTOCOL)
|
||||
try:
|
||||
now = time.time()
|
||||
pickle.dump(now + timeout, f, pickle.HIGHEST_PROTOCOL)
|
||||
pickle.dump(value, f, pickle.HIGHEST_PROTOCOL)
|
||||
finally:
|
||||
f.close()
|
||||
except (IOError, OSError):
|
||||
pass
|
||||
|
||||
|
@ -93,14 +98,16 @@ class CacheClass(BaseCache):
|
|||
fname = self._key_to_file(key)
|
||||
try:
|
||||
f = open(fname, 'rb')
|
||||
exp = pickle.load(f)
|
||||
now = time.time()
|
||||
if exp < now:
|
||||
try:
|
||||
exp = pickle.load(f)
|
||||
now = time.time()
|
||||
if exp < now:
|
||||
self._delete(fname)
|
||||
return False
|
||||
else:
|
||||
return True
|
||||
finally:
|
||||
f.close()
|
||||
self._delete(fname)
|
||||
return False
|
||||
else:
|
||||
return True
|
||||
except (IOError, OSError, EOFError, pickle.PickleError):
|
||||
return False
|
||||
|
||||
|
|
|
@ -191,8 +191,8 @@ u'The Definitive Guide to Django: Web Development Done Right'
|
|||
|
||||
# Calling values on a queryset that has annotations returns the output
|
||||
# as a dictionary
|
||||
>>> Book.objects.filter(pk=1).annotate(mean_age=Avg('authors__age')).values()
|
||||
[{'rating': 4.5, 'isbn': u'159059725', 'name': u'The Definitive Guide to Django: Web Development Done Right', 'pubdate': datetime.date(2007, 12, 6), 'price': Decimal("30..."), 'contact_id': 1, 'id': 1, 'publisher_id': 1, 'pages': 447, 'mean_age': 34.5}]
|
||||
>>> [sorted(o.iteritems()) for o in Book.objects.filter(pk=1).annotate(mean_age=Avg('authors__age')).values()]
|
||||
[[('contact_id', 1), ('id', 1), ('isbn', u'159059725'), ('mean_age', 34.5), ('name', u'The Definitive Guide to Django: Web Development Done Right'), ('pages', 447), ('price', Decimal("30...")), ('pubdate', datetime.date(2007, 12, 6)), ('publisher_id', 1), ('rating', 4.5)]]
|
||||
|
||||
>>> Book.objects.filter(pk=1).annotate(mean_age=Avg('authors__age')).values('pk', 'isbn', 'mean_age')
|
||||
[{'pk': 1, 'isbn': u'159059725', 'mean_age': 34.5}]
|
||||
|
@ -203,8 +203,8 @@ u'The Definitive Guide to Django: Web Development Done Right'
|
|||
|
||||
# An empty values() call before annotating has the same effect as an
|
||||
# empty values() call after annotating
|
||||
>>> Book.objects.filter(pk=1).values().annotate(mean_age=Avg('authors__age'))
|
||||
[{'rating': 4.5, 'isbn': u'159059725', 'name': u'The Definitive Guide to Django: Web Development Done Right', 'pubdate': datetime.date(2007, 12, 6), 'price': Decimal("30..."), 'contact_id': 1, 'id': 1, 'publisher_id': 1, 'pages': 447, 'mean_age': 34.5}]
|
||||
>>> [sorted(o.iteritems()) for o in Book.objects.filter(pk=1).values().annotate(mean_age=Avg('authors__age'))]
|
||||
[[('contact_id', 1), ('id', 1), ('isbn', u'159059725'), ('mean_age', 34.5), ('name', u'The Definitive Guide to Django: Web Development Done Right'), ('pages', 447), ('price', Decimal("30...")), ('pubdate', datetime.date(2007, 12, 6)), ('publisher_id', 1), ('rating', 4.5)]]
|
||||
|
||||
# Calling annotate() on a ValuesQuerySet annotates over the groups of
|
||||
# fields to be selected by the ValuesQuerySet.
|
||||
|
|
|
@ -127,6 +127,6 @@ FieldError: Joined field references are not permitted in this query
|
|||
>>> acme.save()
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
TypeError: int() argument must be a string or a number...
|
||||
TypeError: ...
|
||||
|
||||
"""}
|
||||
|
|
|
@ -174,8 +174,8 @@ FieldError: Cannot resolve keyword 'foo' into field. Choices are: authors, conta
|
|||
{'number': 1132, 'select': 1132}
|
||||
|
||||
# Regression for #10064: select_related() plays nice with aggregates
|
||||
>>> Book.objects.select_related('publisher').annotate(num_authors=Count('authors')).values()[0]
|
||||
{'rating': 4.0, 'isbn': u'013790395', 'name': u'Artificial Intelligence: A Modern Approach', 'pubdate': datetime.date(1995, 1, 15), 'price': Decimal("82.8..."), 'contact_id': 8, 'id': 5, 'num_authors': 2, 'publisher_id': 3, 'pages': 1132}
|
||||
>>> sorted(Book.objects.select_related('publisher').annotate(num_authors=Count('authors')).values()[0].iteritems())
|
||||
[('contact_id', 8), ('id', 5), ('isbn', u'013790395'), ('name', u'Artificial Intelligence: A Modern Approach'), ('num_authors', 2), ('pages', 1132), ('price', Decimal("82.8...")), ('pubdate', datetime.date(1995, 1, 15)), ('publisher_id', 3), ('rating', 4.0)]
|
||||
|
||||
# Regression for #10010: exclude on an aggregate field is correctly negated
|
||||
>>> len(Book.objects.annotate(num_authors=Count('authors')))
|
||||
|
@ -219,8 +219,8 @@ FieldError: Cannot resolve keyword 'foo' into field. Choices are: authors, conta
|
|||
>>> Book.objects.filter(id__in=[]).aggregate(num_authors=Count('authors'), avg_authors=Avg('authors'), max_authors=Max('authors'), max_price=Max('price'), max_rating=Max('rating'))
|
||||
{'max_authors': None, 'max_rating': None, 'num_authors': 0, 'avg_authors': None, 'max_price': None}
|
||||
|
||||
>>> Publisher.objects.filter(pk=5).annotate(num_authors=Count('book__authors'), avg_authors=Avg('book__authors'), max_authors=Max('book__authors'), max_price=Max('book__price'), max_rating=Max('book__rating')).values()
|
||||
[{'max_authors': None, 'name': u"Jonno's House of Books", 'num_awards': 0, 'max_price': None, 'num_authors': 0, 'max_rating': None, 'id': 5, 'avg_authors': None}]
|
||||
>>> list(Publisher.objects.filter(pk=5).annotate(num_authors=Count('book__authors'), avg_authors=Avg('book__authors'), max_authors=Max('book__authors'), max_price=Max('book__price'), max_rating=Max('book__rating')).values()) == [{'max_authors': None, 'name': u"Jonno's House of Books", 'num_awards': 0, 'max_price': None, 'num_authors': 0, 'max_rating': None, 'id': 5, 'avg_authors': None}]
|
||||
True
|
||||
|
||||
# Regression for #10113 - Fields mentioned in order_by() must be included in the GROUP BY.
|
||||
# This only becomes a problem when the order_by introduces a new join.
|
||||
|
|
Loading…
Reference in New Issue