Django

Code

Changeset 7881

Show
Ignore:
Timestamp:
07/10/08 15:47:18 (4 months ago)
Author:
brosner
Message:

newforms-admin: Merged from trunk up to [7877].

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/branches/newforms-admin

    • Property svnmerge-integrated changed from /django/trunk:1-4345,4350-4357,4359-4365,4371-4372,4374-4377,4380-4386,4388,4390-4391,4400-4402,4404-4408,4410,4412-4419,4426-4427,4430-4432,4434,4441,4443-4444,4446-4447,4450,4452-4453,4455-4458,4476,4503,4546,4564-4569,4580-4586,4617,4630,4641-6390,6392-7852 to /django/trunk:1-4345,4350-4357,4359-4365,4371-4372,4374-4377,4380-4386,4388,4390-4391,4400-4402,4404-4408,4410,4412-4419,4426-4427,4430-4432,4434,4441,4443-4444,4446-4447,4450,4452-4453,4455-4458,4476,4503,4546,4564-4569,4580-4586,4617,4630,4641-6390,6392-7880
  • django/branches/newforms-admin/AUTHORS

    r7853 r7881  
    288288    Todd O'Bryan <toddobryan@mac.com> 
    289289    oggie rob <oz.robharvey@gmail.com> 
     290    oggy <ognjen.maric@gmail.com> 
    290291    Jay Parlar <parlar@gmail.com> 
    291292    Carlos Eduardo de Paula <carlosedp@gmail.com> 
  • django/branches/newforms-admin/django/contrib/admin/views/main.py

    r7810 r7881  
    11from django.contrib.admin.filterspecs import FilterSpec 
    22from django.contrib.admin.options import IncorrectLookupParameters 
    3 from django.core.paginator import QuerySetPaginator, InvalidPage 
     3from django.core.paginator import Paginator, InvalidPage 
    44from django.db import models 
    55from django.db.models.query import QuerySet 
     
    110110 
    111111    def get_results(self, request): 
    112         paginator = QuerySetPaginator(self.query_set, self.list_per_page) 
    113  
     112        paginator = Paginator(self.query_set, self.list_per_page) 
    114113        # Get the number of objects, with admin filters applied. 
    115114        try: 
  • django/branches/newforms-admin/django/core/files/uploadedfile.py

    r7830 r7881  
    44 
    55import os 
     6import tempfile 
     7import warnings 
    68try: 
    79    from cStringIO import StringIO 
     
    911    from StringIO import StringIO 
    1012 
    11 __all__ = ('UploadedFile', 'TemporaryUploadedFile', 'InMemoryUploadedFile') 
     13from django.conf import settings 
     14 
     15__all__ = ('UploadedFile', 'TemporaryUploadedFile', 'InMemoryUploadedFile', 'SimpleUploadedFile') 
     16 
     17# Because we fooled around with it a bunch, UploadedFile has a bunch 
     18# of deprecated properties. This little shortcut helps define 'em 
     19# without too much code duplication. 
     20def deprecated_property(old, new, readonly=False): 
     21    def issue_warning(): 
     22        warnings.warn( 
     23            message = "UploadedFile.%s is deprecated; use UploadedFile.%s instead." % (old, new), 
     24            category = DeprecationWarning, 
     25            stacklevel = 3 
     26        ) 
     27     
     28    def getter(self): 
     29        issue_warning() 
     30        return getattr(self, new) 
     31         
     32    def setter(self, value): 
     33        issue_warning() 
     34        setattr(self, new, value) 
     35         
     36    if readonly: 
     37        return property(getter) 
     38    else: 
     39        return property(getter, setter) 
    1240 
    1341class UploadedFile(object): 
     
    2149    DEFAULT_CHUNK_SIZE = 64 * 2**10 
    2250 
    23     def __init__(self, file_name=None, content_type=None, file_size=None, charset=None): 
    24         self.file_name = file_name 
    25         self.file_size = file_size 
     51    def __init__(self, name=None, content_type=None, size=None, charset=None): 
     52        self.name = name 
     53        self.size = size 
    2654        self.content_type = content_type 
    2755        self.charset = charset 
    2856 
    2957    def __repr__(self): 
    30         return "<%s: %s (%s)>" % (self.__class__.__name__, self.file_name, self.content_type) 
    31  
    32     def _set_file_name(self, name): 
     58        return "<%s: %s (%s)>" % (self.__class__.__name__, self.name, self.content_type) 
     59 
     60    def _get_name(self): 
     61        return self._name 
     62 
     63    def _set_name(self, name): 
    3364        # Sanitize the file name so that it can't be dangerous. 
    3465        if name is not None: 
    3566            # Just use the basename of the file -- anything else is dangerous. 
    3667            name = os.path.basename(name) 
    37              
     68 
    3869            # File names longer than 255 characters can cause problems on older OSes. 
    3970            if len(name) > 255: 
    4071                name, ext = os.path.splitext(name) 
    4172                name = name[:255 - len(ext)] + ext 
    42                  
    43         self._file_name = name 
    44          
    45     def _get_file_name(self): 
    46         return self._file_name 
    47          
    48     file_name = property(_get_file_name, _set_file_name) 
    49  
    50     def chunk(self, chunk_size=None): 
     73 
     74        self._name = name 
     75 
     76    name = property(_get_name, _set_name) 
     77 
     78    def chunks(self, chunk_size=None): 
    5179        """ 
    5280        Read the file and yield chucks of ``chunk_size`` bytes (defaults to 
     
    5987            self.seek(0) 
    6088        # Assume the pointer is at zero... 
    61         counter = self.file_size 
     89        counter = self.size 
    6290 
    6391        while counter > 0: 
     
    6593            counter -= chunk_size 
    6694 
     95    # Deprecated properties 
     96    filename = deprecated_property(old="filename", new="name") 
     97    file_name = deprecated_property(old="file_name", new="name") 
     98    file_size = deprecated_property(old="file_size", new="size") 
     99    chunk = deprecated_property(old="chunk", new="chunks", readonly=True) 
     100 
     101    def _get_data(self): 
     102        warnings.warn( 
     103            message = "UploadedFile.data is deprecated; use UploadedFile.read() instead.", 
     104            category = DeprecationWarning, 
     105            stacklevel = 2 
     106        ) 
     107        return self.read() 
     108    data = property(_get_data) 
     109 
    67110    def multiple_chunks(self, chunk_size=None): 
    68111        """ 
     
    75118        if not chunk_size: 
    76119            chunk_size = UploadedFile.DEFAULT_CHUNK_SIZE 
    77         return self.file_size < chunk_size 
    78  
    79     # Abstract methods; subclasses *must* default read() and probably should 
     120        return self.size > chunk_size 
     121 
     122    # Abstract methods; subclasses *must* define read() and probably should 
    80123    # define open/close. 
    81124    def read(self, num_bytes=None): 
     
    88131        pass 
    89132 
     133    def xreadlines(self): 
     134        return self 
     135 
     136    def readlines(self): 
     137        return list(self.xreadlines()) 
     138 
     139    def __iter__(self): 
     140        # Iterate over this file-like object by newlines 
     141        buffer_ = None 
     142        for chunk in self.chunks(): 
     143            chunk_buffer = StringIO(chunk) 
     144 
     145            for line in chunk_buffer: 
     146                if buffer_: 
     147                    line = buffer_ + line 
     148                    buffer_ = None 
     149 
     150                # If this is the end of a line, yield 
     151                # otherwise, wait for the next round 
     152                if line[-1] in ('\n', '\r'): 
     153                    yield line 
     154                else: 
     155                    buffer_ = line 
     156 
     157        if buffer_ is not None: 
     158            yield buffer_ 
     159 
    90160    # Backwards-compatible support for uploaded-files-as-dictionaries. 
    91161    def __getitem__(self, key): 
    92         import warnings 
    93162        warnings.warn( 
    94163            message = "The dictionary access of uploaded file objects is deprecated. Use the new object interface instead.", 
     
    97166        ) 
    98167        backwards_translate = { 
    99             'filename': 'file_name', 
     168            'filename': 'name', 
    100169            'content-type': 'content_type', 
    101            
     170       
    102171 
    103172        if key == 'content': 
    104173            return self.read() 
    105174        elif key == 'filename': 
    106             return self.file_name 
     175            return self.name 
    107176        elif key == 'content-type': 
    108177            return self.content_type 
     
    114183    A file uploaded to a temporary location (i.e. stream-to-disk). 
    115184    """ 
    116  
    117     def __init__(self, file, file_name, content_type, file_size, charset): 
    118         super(TemporaryUploadedFile, self).__init__(file_name, content_type, file_size, charset) 
    119         self.file = file 
    120         self.path = file.name 
    121         self.file.seek(0
     185    def __init__(self, name, content_type, size, charset): 
     186        super(TemporaryUploadedFile, self).__init__(name, content_type, size, charset) 
     187        if settings.FILE_UPLOAD_TEMP_DIR: 
     188            self._file = tempfile.NamedTemporaryFile(suffix='.upload', dir=settings.FILE_UPLOAD_TEMP_DIR) 
     189        else: 
     190            self._file = tempfile.NamedTemporaryFile(suffix='.upload'
    122191 
    123192    def temporary_file_path(self): 
     
    125194        Returns the full path of this file. 
    126195        """ 
    127         return self.path 
    128  
    129     def read(self, *args, **kwargs): 
    130         return self.file.read(*args, **kwargs) 
    131  
    132     def open(self): 
    133         self.seek(0) 
    134  
    135     def seek(self, *args, **kwargs): 
    136         self.file.seek(*args, **kwargs) 
     196        return self.name 
     197     
     198    # Most methods on this object get proxied to NamedTemporaryFile. 
     199    # We can't directly subclass because NamedTemporaryFile is actually a 
     200    # factory function 
     201    def read(self, *args):          return self._file.read(*args) 
     202    def seek(self, offset):         return self._file.seek(offset) 
     203    def write(self, s):             return self._file.write(s) 
     204    def close(self):                return self._file.close() 
     205    def __iter__(self):             return iter(self._file) 
     206    def readlines(self, size=None): return self._file.readlines(size) 
     207    def xreadlines(self):           return self._file.xreadlines() 
    137208 
    138209class InMemoryUploadedFile(UploadedFile): 
     
    140211    A file uploaded into memory (i.e. stream-to-memory). 
    141212    """ 
    142     def __init__(self, file, field_name, file_name, content_type, file_size, charset): 
    143         super(InMemoryUploadedFile, self).__init__(file_name, content_type, file_size, charset) 
     213    def __init__(self, file, field_name, name, content_type, size, charset): 
     214        super(InMemoryUploadedFile, self).__init__(name, content_type, size, charset) 
    144215        self.file = file 
    145216        self.field_name = field_name 
     
    155226        return self.file.read(*args, **kwargs) 
    156227 
    157     def chunk(self, chunk_size=None): 
     228    def chunks(self, chunk_size=None): 
    158229        self.file.seek(0) 
    159230        yield self.read() 
     
    169240    def __init__(self, name, content, content_type='text/plain'): 
    170241        self.file = StringIO(content or '') 
    171         self.file_name = name 
     242        self.name = name 
    172243        self.field_name = None 
    173         self.file_size = len(content or '') 
     244        self.size = len(content or '') 
    174245        self.content_type = content_type 
    175246        self.charset = None 
  • django/branches/newforms-admin/django/core/files/uploadhandler.py

    r7830 r7881  
    133133        """ 
    134134        super(TemporaryFileUploadHandler, self).new_file(file_name, *args, **kwargs) 
    135         self.file = TemporaryFile(settings.FILE_UPLOAD_TEMP_DIR) 
    136         self.write = self.file.write 
     135        self.file = TemporaryUploadedFile(self.file_name, self.content_type, 0, self.charset) 
    137136 
    138137    def receive_data_chunk(self, raw_data, start): 
    139         self.write(raw_data) 
     138        self.file.write(raw_data) 
    140139 
    141140    def file_complete(self, file_size): 
    142141        self.file.seek(0) 
    143         return TemporaryUploadedFile( 
    144             file = self.file,  
    145             file_name = self.file_name,  
    146             content_type = self.content_type,  
    147             file_size = file_size,  
    148             charset = self.charset 
    149         ) 
     142        self.file.size = file_size 
     143        return self.file 
    150144 
    151145class MemoryFileUploadHandler(FileUploadHandler): 
     
    190184            file = self.file, 
    191185            field_name = self.field_name, 
    192             file_name = self.file_name, 
     186            name = self.file_name, 
    193187            content_type = self.content_type, 
    194             file_size = file_size, 
     188            size = file_size, 
    195189            charset = self.charset 
    196190        ) 
    197191 
    198 class TemporaryFile(object): 
    199     """ 
    200     A temporary file that tries to delete itself when garbage collected. 
    201     """ 
    202     def __init__(self, dir): 
    203         if not dir: 
    204             dir = tempfile.gettempdir() 
    205         try: 
    206             (fd, name) = tempfile.mkstemp(suffix='.upload', dir=dir) 
    207             self.file = os.fdopen(fd, 'w+b') 
    208         except (OSError, IOError): 
    209             raise OSError("Could not create temporary file for uploading, have you set settings.FILE_UPLOAD_TEMP_DIR correctly?") 
    210         self.name = name 
    211  
    212     def __getattr__(self, name): 
    213         a = getattr(self.__dict__['file'], name) 
    214         if type(a) != type(0): 
    215             setattr(self, name, a) 
    216         return a 
    217  
    218     def __del__(self): 
    219         try: 
    220             os.unlink(self.name) 
    221         except OSError: 
    222             pass 
    223192 
    224193def load_handler(path, *args, **kwargs): 
  • django/branches/newforms-admin/django/core/handlers/base.py

    r7544 r7881  
    77class BaseHandler(object): 
    88    # Changes that are always applied to a response (in this order). 
    9     response_fixes = [http.fix_location_header, 
    10             http.conditional_content_removal] 
     9    response_fixes = [ 
     10        http.fix_location_header, 
     11        http.conditional_content_removal, 
     12        http.fix_IE_for_attach, 
     13        http.fix_IE_for_vary, 
     14    ] 
    1115 
    1216    def __init__(self): 
  • django/branches/newforms-admin/django/core/mail.py

    r7351 r7881  
    206206        """ 
    207207        if to: 
     208            assert not isinstance(to, basestring), '"to" argument must be a list or tuple' 
    208209            self.to = list(to) 
    209210        else: 
    210211            self.to = [] 
    211212        if bcc: 
     213            assert not isinstance(bcc, basestring), '"bcc" argument must be a list or tuple' 
    212214            self.bcc = list(bcc) 
    213215        else: 
  • django/branches/newforms-admin/django/core/paginator.py

    r7830 r7881  
    11class InvalidPage(Exception): 
     2    pass 
     3 
     4class PageNotAnInteger(InvalidPage): 
     5    pass 
     6 
     7class EmptyPage(InvalidPage): 
    28    pass 
    39 
     
    1521            number = int(number) 
    1622        except ValueError: 
    17             raise InvalidPage('That page number is not an integer') 
     23            raise PageNotAnInteger('That page number is not an integer') 
    1824        if number < 1: 
    19             raise InvalidPage('That page number is less than 1') 
     25            raise EmptyPage('That page number is less than 1') 
    2026        if number > self.num_pages: 
    2127            if number == 1 and self.allow_empty_first_page: 
    2228                pass 
    2329            else: 
    24                 raise InvalidPage('That page contains no results') 
     30                raise EmptyPage('That page contains no results') 
    2531        return number 
    2632 
     
    3743        "Returns the total number of objects, across all pages." 
    3844        if self._count is None: 
    39             self._count = len(self.object_list) 
     45            from django.db.models.query import QuerySet 
     46            if isinstance(self.object_list, QuerySet): 
     47                self._count = self.object_list.count() 
     48            else: 
     49                self._count = len(self.object_list) 
    4050        return self._count 
    4151    count = property(_get_count) 
     
    6272    page_range = property(_get_page_range) 
    6373 
    64 class QuerySetPaginator(Paginator): 
    65     """ 
    66     Like Paginator, but works on QuerySets. 
    67     """ 
    68     def _get_count(self): 
    69         if self._count is None: 
    70             self._count = self.object_list.count() 
    71         return self._count 
    72     count = property(_get_count) 
     74QuerySetPaginator = Paginator # For backwards-compatibility. 
    7375 
    7476class Page(object): 
     
    134136            page_number = int(page_number) + 1 
    135137        except ValueError: 
    136             raise InvalidPage 
     138            raise PageNotAnInteger 
    137139        return self.validate_number(page_number) 
    138140 
     
    141143            page_number = int(page_number) + 1 
    142144        except ValueError: 
    143             raise InvalidPage 
     145            raise PageNotAnInteger 
    144146        return self.page(page_number).object_list 
    145147 
  • django/branches/newforms-admin/django/db/models/base.py

    r7853 r7881  
    44import os 
    55from itertools import izip 
     6try: 
     7    set 
     8except NameError: 
     9    from sets import Set as set     # Python 2.3 fallback. 
    610 
    711import django.db.models.manipulators    # Imported to register signal handler. 
     
    2428from django.conf import settings 
    2529 
    26 try: 
    27     set 
    28 except NameError: 
    29     from sets import Set as set     # Python 2.3 fallback 
    3030 
    3131class ModelBase(type): 
    32     "Metaclass for all models" 
     32    """ 
     33    Metaclass for all models. 
     34    """ 
    3335    def __new__(cls, name, bases, attrs): 
    3436        super_new = super(ModelBase, cls).__new__ 
     
    142144 
    143145    def _prepare(cls): 
    144         # Creates some methods once self._meta has been populated. 
     146        """ 
     147        Creates some methods once self._meta has been populated. 
     148        """ 
    145149        opts = cls._meta 
    146150        opts._prepare(cls) 
     
    160164 
    161165        dispatcher.send(signal=signals.class_prepared, sender=cls) 
     166 
    162167 
    163168class Model(object): 
     
    265270    def save(self): 
    266271        """ 
    267         Save the current instance. Override this in a subclass if you want to 
     272        Saves the current instance. Override this in a subclass if you want to 
    268273        control the saving process. 
    269274        """ 
     
    291296        # If we are in a raw save, save the object exactly as presented. 
    292297        # That means that we don't try to be smart about saving attributes 
    293         # that might have come from the parent class - we just save the  
     298        # that might have come from the parent class - we just save the 
    294299        # attributes we have been given to the class we have been given. 
    295300        if not raw: 
     
    299304 
    300305        non_pks = [f for f in meta.local_fields if not f.primary_key] 
    301              
     306 
    302307        # First, try an UPDATE. If that doesn't update anything, do an INSERT. 
    303308        pk_val = self._get_pk_val(meta) 
     
    369374    def _collect_sub_objects(self, seen_objs, parent=None, nullable=False): 
    370375        """ 
    371         Recursively populates seen_objs with all objects related to this object. 
     376        Recursively populates seen_objs with all objects related to this 
     377        object. 
     378 
    372379        When done, seen_objs.items() will be in the format: 
    373380            [(model_class, {pk_val: obj, pk_val: obj, ...}), 
    374              (model_class, {pk_val: obj, pk_val: obj, ...}),...] 
     381             (model_class, {pk_val: obj, pk_val: obj, ...}), ...] 
    375382        """ 
    376383        pk_val = self._get_pk_val() 
     
    409416        assert self._get_pk_val() is not None, "%s object can't be deleted because its %s attribute is set to None." % (self._meta.object_name, self._meta.pk.attname) 
    410417 
    411         # Find all the objects than need to be deleted 
     418        # Find all the objects than need to be deleted. 
    412419        seen_objs = CollectedObjects() 
    413420        self._collect_sub_objects(seen_objs) 
    414421 
    415         # Actually delete the objects 
     422        # Actually delete the objects. 
    416423        delete_objects(seen_objs) 
    417424 
     
    452459 
    453460    def _get_FIELD_filename(self, field): 
    454         if getattr(self, field.attname): # value is not blank 
     461        if getattr(self, field.attname): # Value is not blank. 
    455462            return os.path.normpath(os.path.join(settings.MEDIA_ROOT, getattr(self, field.attname))) 
    456463        return '' 
    457464 
    458465    def _get_FIELD_url(self, field): 
    459         if getattr(self, field.attname): # value is not blank 
     466        if getattr(self, field.attname): # Value is not blank. 
    460467            import urlparse 
    461468            return urlparse.urljoin(settings.MEDIA_URL, getattr(self, field.attname)).replace('\\', '/') 
     
    472479            pass 
    473480 
    474         # 
    475481        # Check for old-style usage (files-as-dictionaries). Warn here first 
    476482        # since there are multiple locations where we need to support both new 
    477483        # and old usage. 
    478         # 
    479484        if isinstance(raw_field, dict): 
    480485            import warnings 
    481486            warnings.warn( 
    482487                message = "Representing uploaded files as dictionaries is"\ 
    483                           " deprected. Use django.core.files.SimpleUploadedFile"\ 
     488                          " deprecated. Use django.core.files.SimpleUploadedFile"\ 
    484489                          " instead.", 
    485490                category = DeprecationWarning, 
     
    506511        filename = field.get_filename(filename) 
    507512 
    508         # 
    509         # If the filename already exists, keep adding an underscore to the name of 
    510         # the file until the filename doesn't exist. 
    511         # 
     513        # If the filename already exists, keep adding an underscore to the name 
     514        # of the file until the filename doesn't exist. 
    512515        while os.path.exists(os.path.join(settings.MEDIA_ROOT, filename)): 
    513516            try: 
    514517                dot_index = filename.rindex('.') 
    515             except ValueError: # filename has no dot 
     518            except ValueError: # filename has no dot. 
    516519                filename += '_' 
    517520            else: 
    518521                filename = filename[:dot_index] + '_' + filename[dot_index:] 
    519         # 
    520         # Save the file name on the object and write the file to disk 
    521         # 
    522  
     522 
     523        # Save the file name on the object and write the file to disk. 
    523524        setattr(self, field.attname, filename) 
    524  
    525525        full_filename = self._get_FIELD_filename(field) 
    526  
    527526        if hasattr(raw_field, 'temporary_file_path'): 
    528527            # This file has a file path that we can move. 
    529528            raw_field.close() 
    530529            file_move_safe(raw_field.temporary_file_path(), full_filename) 
    531  
    532530        else: 
    533531            # This is a normal uploadedfile that we can stream. 
    534532            fp = open(full_filename, 'wb') 
    535533            locks.lock(fp, locks.LOCK_EX) 
    536             for chunk in raw_field.chunk(): 
     534            for chunk in raw_field.chunks(): 
    537535                fp.write(chunk) 
    538536            locks.unlock(fp) 
     
    540538 
    541539        # Save the width and/or height, if applicable. 
    542         if isinstance(field, ImageField) and (field.width_field or field.height_field): 
     540        if isinstance(field, ImageField) and \ 
     541                (field.width_field or field.height_field): 
    543542            from django.utils.images import get_image_dimensions 
    544543            width, height = get_image_dimensions(full_filename) 
     
    548547                setattr(self, field.height_field, height) 
    549548 
    550         # Save the object because it has changed unless save is False 
     549        # Save the object because it has changed, unless save is False. 
    551550        if save: 
    552551            self.save() 
     
    567566            setattr(self, cachename, get_image_dimensions(filename)) 
    568567        return getattr(self, cachename) 
     568 
    569569 
    570570############################################ 
     
    583583    transaction.commit_unless_managed() 
    584584 
     585 
    585586def method_get_order(ordered_obj, self): 
    586587    rel_val = getattr(self, ordered_obj._meta.order_with_respect_to.rel.field_name) 
     
    590591            ordered_obj.objects.filter(**{order_name: rel_val}).values(pk_name)] 
    591592 
     593 
    592594############################################## 
    593595# HELPER FUNCTIONS (CURRIED MODEL FUNCTIONS) # 
     
    596598def get_absolute_url(opts, func, self, *args, **kwargs): 
    597599    return settings.ABSOLUTE_URL_OVERRIDES.get('%s.%s' % (opts.app_label, opts.module_name), func)(self, *args, **kwargs) 
     600 
    598601 
    599602######## 
     
    608611    def subclass_exception(name, parent, unused): 
    609612        return types.ClassType(name, (parent,), {}) 
    610  
    611613else: 
    612614    def subclass_exception(name, parent, module): 
    613615        return type(name, (parent,), {'__module__': module}) 
    614  
  • django/branches/newforms-admin/django/db/models/fields/__init__.py

    r7815 r7881  
    752752        "Returns field's value prepared for saving into a database." 
    753753        # Need to convert UploadedFile objects provided via a form to unicode for database insertion 
    754         if value is None: 
     754        if hasattr(value, 'name'): 
     755            return value.name 
     756        elif value is None: 
    755757            return None 
    756         return unicode(value) 
     758        else: 
     759            return unicode(value) 
    757760 
    758761    def get_manipulator_fields(self, opts, manipulator, change, name_prefix='', rel=False, follow=True): 
     
    828831            # do so for us. 
    829832            try: 
    830                 file_name = file.file_name 
     833                file_name = file.name 
    831834            except AttributeError: 
    832835                file_name = file['filename'] 
     
    843846 
    844847    def save_form_data(self, instance, data): 
    845         from django.newforms.fields import UploadedFile 
     848        from django.core.files.uploadedfile import UploadedFile 
    846849        if data and isinstance(data, UploadedFile): 
    847             getattr(instance, "save_%s_file" % self.name)(data.filename, data.data, save=False) 
     850            getattr(instance, "save_%s_file" % self.name)(data.name, data, save=False) 
    848851 
    849852    def formfield(self, **kwargs): 
  • django/branches/newforms-admin/django/db/models/query.py

    r7809 r7881  
    1414ITER_CHUNK_SIZE = CHUNK_SIZE 
    1515 
    16 # Pull into this namespace for backwards compatibility 
     16# Pull into this namespace for backwards compatibility. 
    1717EmptyResultSet = sql.EmptyResultSet 
    1818 
     
    2020    pass 
    2121 
     22 
    2223class CollectedObjects(object): 
    2324    """ 
    24     A container that stores keys and lists of values along with 
    25     remembering the parent objects for all the keys. 
    26  
    27     This is used for the database object deletion routines so that we 
    28     can calculate the 'leaf' objects which should be deleted first. 
     25    A container that stores keys and lists of values along with remembering the 
     26    parent objects for all the keys. 
     27 
     28    This is used for the database object deletion routines so that we can 
     29    calculate the 'leaf' objects which should be deleted first. 
    2930    """ 
    3031 
     
    3536    def add(self, model, pk, obj, parent_model, nullable=False): 
    3637        """ 
    37         Adds an item. 
    38         model is the class of the object being added, 
    39         pk is the primary key, obj is the object itself, 
    40         parent_model is the model of the parent object 
    41         that this object was reached through, nullable should 
    42         be True if this relation is nullable. 
    43  
    44         If the item already existed in the structure, 
    45         returns true, otherwise false. 
     38        Adds an item to the container. 
     39 
     40        Arguments: 
     41        * model - the class of the object being added. 
     42        * pk - the primary key. 
     43        * obj - the object itself. 
     44        * parent_model - the model of the parent object that this object was 
     45          reached through. 
     46        * nullable - should be True if this relation is nullable. 
     47 
     48        Returns True if the item already existed in the structure and 
     49        False otherwise. 
    4650        """ 
    4751        d = self.data.setdefault(model, SortedDict()) 
    4852        retval = pk in d 
    4953        d[pk] = obj 
    50         # Nullable relationships can be ignored -- they 
    51         # are nulled out before deleting, and therefore 
    52         # do not affect the order in which objects have 
    53         # to be deleted. 
     54        # Nullable relationships can be ignored -- they are nulled out before 
     55        # deleting, and therefore do not affect the order in which objects 
     56        # have to be deleted. 
    5457        if parent_model is not None and not nullable: 
    5558            self.children.setdefault(parent_model, []).append(model) 
    56  
    5759        return retval 
    5860 
     
    7880    def ordered_keys(self): 
    7981        """ 
    80         Returns the models in the order that they should be 
    81         dealth with i.e. models with no dependencies first
     82        Returns the models in the order that they should be dealt with (i.e. 
     83        models with no dependencies first)
    8284        """ 
    8385        dealt_with = SortedDict() 
     
    9294                    found = True 
    9395            if not found: 
    94                 raise CyclicDependency("There is a cyclic dependency of items to be processed.") 
     96                raise CyclicDependency( 
     97                    "There is a cyclic dependency of items to be processed.") 
    9598 
    9699        return dealt_with.keys() 
     
    98101    def unordered_keys(self): 
    99102        """ 
    100 &nbs