Ticket #5386: newforms.content_type.diff
File newforms.content_type.diff, 1.8 KB (added by , 17 years ago) |
---|
-
django/newforms/fields.py
416 416 417 417 class UploadedFile(StrAndUnicode): 418 418 "A wrapper for files uploaded in a FileField" 419 def __init__(self, filename, content ):419 def __init__(self, filename, content, content_type): 420 420 self.filename = filename 421 421 self.content = content 422 self.content_type = content_type 422 423 423 424 def __unicode__(self): 424 425 """ … … 445 446 elif not data and initial: 446 447 return initial 447 448 try: 448 f = UploadedFile(data['filename'], data['content'] )449 f = UploadedFile(data['filename'], data['content'], data['content-type']) 449 450 except TypeError: 450 451 raise ValidationError(self.error_messages['invalid']) 451 452 except KeyError: -
docs/newforms.txt
1340 1340 client. 1341 1341 1342 1342 ``content`` The array of bytes comprising the file content. 1343 1344 ``content_type`` The Content-Type of the file as submitted by the 1345 browser. 1343 1346 ====================== ==================================================== 1344 1347 1345 1348 The string representation of an ``UploadedFile`` is the same as the filename 1346 1349 attribute. 1347 1350 1351 You can perform basic validation against the ``content_type`` if you need to 1352 allow only uploads of specific files. Note that this is however unreliable, 1353 since the data is submitted by the browser. 1354 1348 1355 When you use a ``FileField`` on a form, you must also remember to 1349 1356 `bind the file data to the form`_. 1350 1357