Ticket #10002: 10002.3.diff
File 10002.3.diff, 4.8 KB (added by , 16 years ago) |
---|
-
django/forms/forms.py
371 371 if callable(data): 372 372 data = data() 373 373 else: 374 data = self.data 374 if isinstance(self.field, FileField) and self.data is None: 375 data = self.form.initial.get(self.name, self.field.initial) 376 else: 377 data = self.data 375 378 if not only_initial: 376 379 name = self.html_name 377 380 else: -
tests/regressiontests/admin_views/tests.py
2 2 3 3 import re 4 4 import datetime 5 import os 5 6 7 from django.core.files import temp as tempfile 6 8 from django.test import TestCase 7 9 from django.contrib.auth.models import User, Permission 8 10 from django.contrib.contenttypes.models import ContentType … … 13 15 from django.utils.html import escape 14 16 15 17 # local test models 16 from models import Article, CustomArticle, Section, ModelWithStringPrimaryKey, Person, Persona, FooAccount, BarAccount, Subscriber, ExternalSubscriber, Podcast 18 from models import Article, CustomArticle, Section, ModelWithStringPrimaryKey, Person, Persona, FooAccount, BarAccount, Subscriber, ExternalSubscriber, Podcast, Picture, Gallery 17 19 18 20 try: 19 21 set … … 946 948 } 947 949 response = self.client.post('/test_admin/admin/admin_views/externalsubscriber/', action_data) 948 950 self.failUnlessEqual(response.status_code, 302) 951 952 class AdminInlineFileUploadTest(TestCase): 953 fixtures = ['admin-views-users.xml', 'admin-views-actions.xml'] 954 urlbit = 'admin' 955 956 def setUp(self): 957 self.client.login(username='super', password='secret') 958 959 # Set up test Picture and Gallery. 960 # These must be set up here instead of in fixtures in order to allow Picture 961 # to use a NamedTemporaryFile. 962 tdir = tempfile.gettempdir() 963 file1 = tempfile.NamedTemporaryFile(suffix=".file1", dir=tdir) 964 file1.write('a' * (2 ** 21)) 965 filename = file1.name 966 file1.close() 967 g = Gallery(name="Test Gallery") 968 g.save() 969 p = Picture(name="Test Picture", image=filename, gallery=g) 970 p.save() 971 972 def tearDown(self): 973 self.client.logout() 974 975 def testInlineFileUploadEditValidationErrorPost(self): 976 post_data = { 977 "name": u"Test Gallery", 978 "pictures-TOTAL_FORMS": u"2", 979 "pictures-INITIAL_FORMS": u"1", 980 "pictures-0-id": u"1", 981 "pictures-0-gallery": u"1", 982 "pictures-0-name": "Test Picture", 983 "pictures-0-image": "", 984 "pictures-1-id": "", 985 "pictures-1-gallery": "1", 986 "pictures-1-name": "Test Picture 2", 987 "pictures-1-image": "", 988 } 989 response = self.client.post('/test_admin/%s/admin_views/gallery/1/' % self.urlbit, post_data) 990 self.failUnless(response._container[0].find("Currently:") > -1) 991 -
tests/regressiontests/admin_views/models.py
1 1 # -*- coding: utf-8 -*- 2 import tempfile 3 import os 4 from django.core.files.storage import FileSystemStorage 2 5 from django.db import models 3 6 from django.contrib import admin 4 7 from django.core.mail import EmailMessage … … 248 251 249 252 ordering = ('name',) 250 253 254 temp_storage = FileSystemStorage(tempfile.mkdtemp()) 255 UPLOAD_TO = os.path.join(temp_storage.location, 'test_upload') 256 257 class Gallery(models.Model): 258 name = models.CharField(max_length=100) 259 260 class Picture(models.Model): 261 name = models.CharField(max_length=100) 262 image = models.FileField(storage=temp_storage, upload_to='test_upload') 263 gallery = models.ForeignKey(Gallery, related_name="pictures") 264 265 class PictureInline(admin.TabularInline): 266 model = Picture 267 extra = 1 268 269 class GalleryAdmin(admin.ModelAdmin): 270 inlines = [PictureInline] 271 272 class PictureAdmin(admin.ModelAdmin): 273 pass 274 251 275 admin.site.register(Article, ArticleAdmin) 252 276 admin.site.register(CustomArticle, CustomArticleAdmin) 253 277 admin.site.register(Section, inlines=[ArticleInline]) … … 259 283 admin.site.register(Subscriber, SubscriberAdmin) 260 284 admin.site.register(ExternalSubscriber, ExternalSubscriberAdmin) 261 285 admin.site.register(Podcast, PodcastAdmin) 286 admin.site.register(Gallery, GalleryAdmin) 287 admin.site.register(Picture, PictureAdmin) 262 288 263 289 # We intentionally register Promo and ChapterXtra1 but not Chapter nor ChapterXtra2. 264 290 # That way we cover all four cases: