Django

Code

Show
Ignore:
Timestamp:
07/07/08 18:16:00 (5 months ago)
Author:
jacob
Message:

Fixed #7614: the quickening has come, and there now is only one UploadedFile?. On top of that, UploadedFile?'s interface has been improved:

  • The API now more closely matches a proper file API. This unfortunately means a few backwards-incompatible renamings; see BackwardsIncompatibleChanges. This refs #7593.
  • While we were at it, renamed chunk() to chunks() to clarify that it's an iterator.
  • Temporary uploaded files now property use the tempfile library behind the scenes which should ensure better cleanup of tempfiles (refs #7593 again).

Thanks to Mike Axiak for the bulk of this patch.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/db/models/fields/__init__.py

    r7814 r7859  
    767767        "Returns field's value prepared for saving into a database." 
    768768        # Need to convert UploadedFile objects provided via a form to unicode for database insertion 
    769         if value is None: 
     769        if hasattr(value, 'name'): 
     770            return value.name 
     771        elif value is None: 
    770772            return None 
    771         return unicode(value) 
     773        else: 
     774            return unicode(value) 
    772775 
    773776    def get_manipulator_fields(self, opts, manipulator, change, name_prefix='', rel=False, follow=True): 
     
    843846            # do so for us. 
    844847            try: 
    845                 file_name = file.file_name 
     848                file_name = file.name 
    846849            except AttributeError: 
    847850                file_name = file['filename'] 
     
    858861 
    859862    def save_form_data(self, instance, data): 
    860         from django.newforms.fields import UploadedFile 
     863        from django.core.files.uploadedfile import UploadedFile 
    861864        if data and isinstance(data, UploadedFile): 
    862             getattr(instance, "save_%s_file" % self.name)(data.filename, data.data, save=False) 
     865            getattr(instance, "save_%s_file" % self.name)(data.name, data, save=False) 
    863866 
    864867    def formfield(self, **kwargs):