mirror of
https://github.com/django/django.git
synced 2025-07-24 13:44:32 +00:00
File storage refactoring, adding far more flexibility to Django's file handling. The new files.txt document has details of the new features.
This is a backwards-incompatible change; consult BackwardsIncompatibleChanges for details. Fixes #3567, #3621, #4345, #5361, #5655, #7415. Many thanks to Marty Alchin who did the vast majority of this work. git-svn-id: http://code.djangoproject.com/svn/django/trunk@8244 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
c49eac7d4f
commit
7899568e01
33 changed files with 1585 additions and 457 deletions
44
tests/regressiontests/file_storage/models.py
Normal file
44
tests/regressiontests/file_storage/models.py
Normal file
|
@ -0,0 +1,44 @@
|
|||
import os
|
||||
import tempfile
|
||||
from django.db import models
|
||||
from django.core.files.storage import FileSystemStorage
|
||||
from django.core.files.base import ContentFile
|
||||
|
||||
temp_storage = FileSystemStorage(tempfile.gettempdir())
|
||||
|
||||
# Test for correct behavior of width_field/height_field.
|
||||
# Of course, we can't run this without PIL.
|
||||
|
||||
try:
|
||||
# Checking for the existence of Image is enough for CPython, but
|
||||
# for PyPy, you need to check for the underlying modules
|
||||
import Image, _imaging
|
||||
except ImportError:
|
||||
Image = None
|
||||
|
||||
# If we have PIL, do these tests
|
||||
if Image:
|
||||
class Person(models.Model):
|
||||
name = models.CharField(max_length=50)
|
||||
mugshot = models.ImageField(storage=temp_storage, upload_to='tests',
|
||||
height_field='mug_height',
|
||||
width_field='mug_width')
|
||||
mug_height = models.PositiveSmallIntegerField()
|
||||
mug_width = models.PositiveSmallIntegerField()
|
||||
|
||||
__test__ = {'API_TESTS': """
|
||||
|
||||
>>> image_data = open(os.path.join(os.path.dirname(__file__), "test.png"), 'rb').read()
|
||||
>>> p = Person(name="Joe")
|
||||
>>> p.mugshot.save("mug", ContentFile(image_data))
|
||||
>>> p.mugshot.width
|
||||
16
|
||||
>>> p.mugshot.height
|
||||
16
|
||||
>>> p.mug_height
|
||||
16
|
||||
>>> p.mug_width
|
||||
16
|
||||
|
||||
"""}
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue