Changes to ImageFileDescriptor and ImageField to fix a few cases of setting image dimension fields.

* Moved dimension field update logic out of `ImageFileDescriptor.__set__` and into its own method on `ImageField`.
 * New `ImageField.update_dimension_fields` method is attached to model instance's `post_init` signal so that:
   * Dimension fields are set when defined before the ImageField.
   * Dimension fields are set when the field is assigned in the model constructor (fixes #11196), but only if the dimension fields don't already have values, so we avoid updating the dimensions every time an object is loaded from the database (fixes #11084).
 * Clear dimension fields when the ImageField is set to None, which also causes dimension fields to be cleared when `ImageFieldFile.delete()` is used.
 * Added many more tests for ImageField that test edge cases we weren't testing before, and moved the ImageField tests out of `file_storage` and into their own module within `model_fields`.


git-svn-id: http://code.djangoproject.com/svn/django/trunk@10858 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Gary Wilson Jr 2009-05-28 05:46:09 +00:00
parent 7638651cc3
commit d89ba464dd
8 changed files with 621 additions and 152 deletions

View file

@ -6,13 +6,26 @@ from django import forms
from django.db import models
from django.core.exceptions import ValidationError
from models import Foo, Bar, Whiz, BigD, BigS
from models import Foo, Bar, Whiz, BigD, BigS, Image
try:
from decimal import Decimal
except ImportError:
from django.utils._decimal import Decimal
# If PIL available, do these tests.
if Image:
from imagefield import \
ImageFieldTests, \
ImageFieldTwoDimensionsTests, \
ImageFieldNoDimensionsTests, \
ImageFieldOneDimensionTests, \
ImageFieldDimensionsFirstTests, \
ImageFieldUsingFileTests, \
TwoImageFieldTests
class DecimalFieldTests(django.test.TestCase):
def test_to_python(self):
f = models.DecimalField(max_digits=4, decimal_places=2)
@ -131,4 +144,3 @@ class SlugFieldTests(django.test.TestCase):
bs = BigS.objects.create(s = 'slug'*50)
bs = BigS.objects.get(pk=bs.pk)
self.assertEqual(bs.s, 'slug'*50)