Ticket #10002: 10002.2.diff
File 10002.2.diff, 5.1 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/fixtures/admin-views-users.xml
88 88 <field type="DateTimeField" name="date">2009-03-18 11:54:58</field> 89 89 <field to="admin_views.section" name="section" rel="ManyToOneRel">1</field> 90 90 </object> 91 <object pk="1" model="admin_views.gallery"> 92 <field type="CharField" name="name">Test gallery</field> 93 </object> 94 <object pk="1" model="admin_views.picture"> 95 <field type="CharField" name="name">Test picture</field> 96 <field type="FileField" name="image">test.jpg</field> 97 <field to="admin_views.gallery" name="gallery" rel="ManyToOneRel">1</field> 98 </object> 91 99 92 100 93 101 </django-objects> 102 No newline at end of file -
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 … … 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 # upload test file for Picture fixture 960 tdir = tempfile.gettempdir() 961 image = open(os.path.join(tdir, u'test.jpg'.encode('utf-8')), 'w+b') 962 image.write('b' * (2 ** 10)) 963 image.close() 964 965 def tearDown(self): 966 self.client.logout() 967 968 def testInlineFileUploadEditValidationErrorPost(self): 969 post_data = { 970 "name": u"Test Gallery", 971 "pictures-TOTAL_FORMS": u"2", 972 "pictures-INITIAL_FORMS": u"1", 973 "pictures-0-id": u"1", 974 "pictures-0-gallery": u"1", 975 "pictures-0-name": "Test Picture", 976 "pictures-0-image": "", 977 "pictures-1-id": "", 978 "pictures-1-gallery": "1", 979 "pictures-1-name": "Test Picture 2", 980 "pictures-1-image": "", 981 } 982 response = self.client.post('/test_admin/%s/admin_views/gallery/1/' % self.urlbit, post_data) 983 self.failUnless(response._container[0].find("Currently:") > -1) 984 -
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: