Ticket #5619: patch-5619-with-tests.diff
File patch-5619-with-tests.diff, 2.7 KB (added by , 16 years ago) |
---|
-
django/db/models/base.py
462 462 463 463 def _get_FIELD_filename(self, field): 464 464 if getattr(self, field.attname): # Value is not blank. 465 return os.path.normpath(os.path.join(settings.MEDIA_ROOT, getattr(self, field.attname)))465 return os.path.normpath(os.path.join(settings.MEDIA_ROOT, field.get_filename(getattr(self, field.attname)))) 466 466 return '' 467 467 468 468 def _get_FIELD_url(self, field): 469 469 if getattr(self, field.attname): # Value is not blank. 470 470 import urlparse 471 return urlparse.urljoin(settings.MEDIA_URL, getattr(self, field.attname)).replace('\\', '/')471 return urlparse.urljoin(settings.MEDIA_URL, field.get_filename(getattr(self, field.attname))).replace('\\', '/') 472 472 return '' 473 473 474 474 def _get_FIELD_size(self, field): -
tests/modeltests/model_forms/models.py
12 12 13 13 from django.db import models 14 14 15 TEMP_DIR = tempfile.gettempdir() 16 15 17 ARTICLE_STATUS = ( 16 18 (1, 'Draft'), 17 19 (2, 'Pending'), … … 60 62 61 63 class TextFile(models.Model): 62 64 description = models.CharField(max_length=20) 63 file = models.FileField(upload_to= tempfile.gettempdir())65 file = models.FileField(upload_to=TEMP_DIR) 64 66 65 67 def __unicode__(self): 66 68 return self.description … … 71 73 # If PIL is available, try testing PIL. 72 74 # Otherwise, it's equivalent to TextFile above. 73 75 import Image 74 image = models.ImageField(upload_to= tempfile.gettempdir())76 image = models.ImageField(upload_to=TEMP_DIR) 75 77 except ImportError: 76 image = models.FileField(upload_to= tempfile.gettempdir())78 image = models.FileField(upload_to=TEMP_DIR) 77 79 78 80 def __unicode__(self): 79 81 return self.description … … 784 786 785 787 # FileField ################################################################### 786 788 789 # File instance methods. Tests fix for #5619. 790 791 >>> instance = TextFile(description='nothing', file='name') 792 >>> expected = '%s/name' % TEMP_DIR 793 >>> instance.get_file_filename() == expected 794 True 795 >>> instance.get_file_url() == expected 796 True 797 >>> instance.save_file_file(instance.file, 'some text') 798 >>> instance.get_file_filename() == expected 799 True 800 >>> instance.get_file_url() == expected 801 True 802 803 >>> os.unlink(instance.get_file_filename()) 804 805 # File forms. 806 787 807 >>> class TextFileForm(ModelForm): 788 808 ... class Meta: 789 809 ... model = TextFile