Django

Code

Changeset 7815

Show
Ignore:
Timestamp:
07/01/08 10:49:08 (5 months ago)
Author:
brosner
Message:

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

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-7808 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-7814
  • django/branches/newforms-admin/AUTHORS

    r7809 r7815  
    6060    av0000@mail.ru 
    6161    David Avsajanishvili <avsd05@gmail.com> 
    62     axiak@mit.edu 
     62    Mike Axiak <axiak@mit.edu> 
    6363    Niran Babalola <niran@niran.org> 
    6464    Morten Bagai <m@bagai.com> 
     
    143143    Szilveszter Farkas <szilveszter.farkas@gmail.com> 
    144144    favo@exoweb.net 
     145    fdr <drfarina@gmail.com> 
    145146    Dmitri Fedortchenko <zeraien@gmail.com> 
     147    Jonathan Feignberg <jdf@pobox.com> 
    146148    Liang Feng <hutuworm@gmail.com> 
    147149    Bill Fenner <fenner@gmail.com> 
  • django/branches/newforms-admin/django/conf/global_settings.py

    r7707 r7815  
    232232MEDIA_URL = '' 
    233233 
     234# List of upload handler classes to be applied in order. 
     235FILE_UPLOAD_HANDLERS = ( 
     236    'django.core.files.uploadhandler.MemoryFileUploadHandler', 
     237    'django.core.files.uploadhandler.TemporaryFileUploadHandler', 
     238) 
     239 
     240# Maximum size, in bytes, of a request before it will be streamed to the 
     241# file system instead of into memory. 
     242FILE_UPLOAD_MAX_MEMORY_SIZE = 2621440 # i.e. 2.5 MB 
     243 
     244# Directory in which upload streamed files will be temporarily saved. A value of 
     245# `None` will make Django use the operating system's default temporary directory 
     246# (i.e. "/tmp" on *nix systems). 
     247FILE_UPLOAD_TEMP_DIR = None 
     248 
    234249# Default formatting for date objects. See all available format strings here: 
    235250# http://www.djangoproject.com/documentation/templates/#now 
  • django/branches/newforms-admin/django/core/handlers/modpython.py

    r7233 r7815  
    5454        "Populates self._post and self._files" 
    5555        if 'content-type' in self._req.headers_in and self._req.headers_in['content-type'].startswith('multipart'): 
    56             self._post, self._files = http.parse_file_upload(self._req.headers_in, self.raw_post_data) 
     56            self._raw_post_data = '' 
     57            self._post, self._files = self.parse_file_upload(self.META, self._req) 
    5758        else: 
    5859            self._post, self._files = http.QueryDict(self.raw_post_data, encoding=self._encoding), datastructures.MultiValueDict() 
  • django/branches/newforms-admin/django/core/handlers/wsgi.py

    r6864 r7815  
    113113        if self.method == 'POST': 
    114114            if self.environ.get('CONTENT_TYPE', '').startswith('multipart'): 
    115                 header_dict = dict([(k, v) for k, v in self.environ.items() if k.startswith('HTTP_')]) 
    116                 header_dict['Content-Type'] = self.environ.get('CONTENT_TYPE', '') 
    117                 self._post, self._files = http.parse_file_upload(header_dict, self.raw_post_data) 
     115                self._raw_post_data = '' 
     116                self._post, self._files = self.parse_file_upload(self.META, self.environ['wsgi.input']) 
    118117            else: 
    119118                self._post, self._files = http.QueryDict(self.raw_post_data, encoding=self._encoding), datastructures.MultiValueDict() 
  • django/branches/newforms-admin/django/db/models/base.py

    r7809 r7815  
    2020from django.utils.functional import curry 
    2121from django.utils.encoding import smart_str, force_unicode, smart_unicode 
     22from django.core.files.move import file_move_safe 
     23from django.core.files import locks 
    2224from django.conf import settings 
    2325 
     
    467469        return os.path.getsize(self._get_FIELD_filename(field)) 
    468470 
    469     def _save_FIELD_file(self, field, filename, raw_contents, save=True): 
     471    def _save_FIELD_file(self, field, filename, raw_field, save=True): 
    470472        directory = field.get_directory_name() 
    471473        try: # Create the date-based directory if it doesn't exist. 
     
    473475        except OSError: # Directory probably already exists. 
    474476            pass 
     477 
     478        # 
     479        # Check for old-style usage (files-as-dictionaries). Warn here first 
     480        # since there are multiple locations where we need to support both new 
     481        # and old usage. 
     482        # 
     483        if isinstance(raw_field, dict): 
     484            import warnings 
     485            warnings.warn( 
     486                message = "Representing uploaded files as dictionaries is"\ 
     487                          " deprected. Use django.core.files.SimpleUploadedFile"\ 
     488                          " instead.", 
     489                category = DeprecationWarning, 
     490                stacklevel = 2 
     491            ) 
     492            from django.core.files.uploadedfile import SimpleUploadedFile 
     493            raw_field = SimpleUploadedFile.from_dict(raw_field) 
     494 
     495        elif isinstance(raw_field, basestring): 
     496            import warnings 
     497            warnings.warn( 
     498                message = "Representing uploaded files as strings is "\ 
     499                          " deprecated. Use django.core.files.SimpleUploadedFile "\ 
     500                          " instead.", 
     501                category = DeprecationWarning, 
     502                stacklevel = 2 
     503            ) 
     504            from django.core.files.uploadedfile import SimpleUploadedFile 
     505            raw_field = SimpleUploadedFile(filename, raw_field) 
     506 
     507        if filename is None: 
     508            filename = raw_field.file_name 
     509 
    475510        filename = field.get_filename(filename) 
    476511 
     512        # 
    477513        # If the filename already exists, keep adding an underscore to the name of 
    478514        # the file until the filename doesn't exist. 
     515        # 
    479516        while os.path.exists(os.path.join(settings.MEDIA_ROOT, filename)): 
    480517            try: 
     
    484521            else: 
    485522                filename = filename[:dot_index] + '_' + filename[dot_index:] 
    486  
    487         # Write the file to disk. 
     523        # 
     524        # Save the file name on the object and write the file to disk 
     525        # 
     526 
    488527        setattr(self, field.attname, filename) 
    489528 
    490529        full_filename = self._get_FIELD_filename(field) 
    491         fp = open(full_filename, 'wb') 
    492         fp.write(raw_contents) 
    493         fp.close() 
     530 
     531        if hasattr(raw_field, 'temporary_file_path'): 
     532            # This file has a file path that we can move. 
     533            raw_field.close() 
     534            file_move_safe(raw_field.temporary_file_path(), full_filename) 
     535 
     536        else: 
     537            # This is a normal uploadedfile that we can stream. 
     538            fp = open(full_filename, 'wb') 
     539            locks.lock(fp, locks.LOCK_EX) 
     540            for chunk in raw_field.chunk(): 
     541                fp.write(chunk) 
     542            locks.unlock(fp) 
     543            fp.close() 
    494544 
    495545        # Save the width and/or height, if applicable. 
  • django/branches/newforms-admin/django/db/models/fields/__init__.py

    r7809 r7815  
    797797        setattr(cls, 'get_%s_url' % self.name, curry(cls._get_FIELD_url, field=self)) 
    798798        setattr(cls, 'get_%s_size' % self.name, curry(cls._get_FIELD_size, field=self)) 
    799         setattr(cls, 'save_%s_file' % self.name, lambda instance, filename, raw_contents, save=True: instance._save_FIELD_file(self, filename, raw_contents, save)) 
     799        setattr(cls, 'save_%s_file' % self.name, lambda instance, filename, raw_field, save=True: instance._save_FIELD_file(self, filename, raw_field, save)) 
    800800        dispatcher.connect(self.delete_file, signal=signals.post_delete, sender=cls) 
    801801 
     
    820820            func = getattr(new_object, 'save_%s_file' % self.name) 
    821821            if rel: 
    822                 func(new_data[upload_field_name][0]["filename"], new_data[upload_field_name][0]["content"], save) 
     822                file = new_data[upload_field_name][0] 
    823823            else: 
    824                 func(new_data[upload_field_name]["filename"], new_data[upload_field_name]["content"], save) 
     824                file = new_data[upload_field_name] 
     825 
     826            # Backwards-compatible support for files-as-dictionaries. 
     827            # We don't need to raise a warning because Model._save_FIELD_file will 
     828            # do so for us. 
     829            try: 
     830                file_name = file.file_name 
     831            except AttributeError: 
     832                file_name = file['filename'] 
     833 
     834            func(file_name, file, save) 
    825835 
    826836    def get_directory_name(self): 
     
    835845        from django.newforms.fields import UploadedFile 
    836846        if data and isinstance(data, UploadedFile): 
    837             getattr(instance, "save_%s_file" % self.name)(data.filename, data.content, save=False) 
     847            getattr(instance, "save_%s_file" % self.name)(data.filename, data.data, save=False) 
    838848 
    839849    def formfield(self, **kwargs): 
  • django/branches/newforms-admin/django/db/models/sql/query.py

    r7809 r7815  
    11321132                            self.where.add(entry, AND) 
    11331133                            break 
    1134                 elif not (lookup_type == 'in' and not value)
     1134                elif not (lookup_type == 'in' and not value) and field.null
    11351135                    # Leaky abstraction artifact: We have to specifically 
    11361136                    # exclude the "foo__in=[]" case from this handling, because 
  • django/branches/newforms-admin/django/http/__init__.py

    r7351 r7815  
    1010    from cgi import parse_qsl 
    1111 
    12 from django.utils.datastructures import MultiValueDict, FileDic
     12from django.utils.datastructures import MultiValueDict, ImmutableLis
    1313from django.utils.encoding import smart_str, iri_to_uri, force_unicode 
    14  
     14from django.http.multipartparser import MultiPartParser 
     15from django.conf import settings 
     16from django.core.files import uploadhandler 
    1517from utils import * 
    1618 
    1719RESERVED_CHARS="!*'();:@&=+$,/?%#[]" 
    18  
    1920 
    2021class Http404(Exception): 
     
    2627    # The encoding used in GET/POST dicts. None means use default setting. 
    2728    _encoding = None 
     29    _upload_handlers = [] 
    2830 
    2931    def __init__(self): 
     
    103105    encoding = property(_get_encoding, _set_encoding) 
    104106 
    105 def parse_file_upload(header_dict, post_data): 
    106     """Returns a tuple of (POST QueryDict, FILES MultiValueDict).""" 
    107     import email, email.Message 
    108     from cgi import parse_header 
    109     raw_message = '\r\n'.join(['%s:%s' % pair for pair in header_dict.items()]) 
    110     raw_message += '\r\n\r\n' + post_data 
    111     msg = email.message_from_string(raw_message) 
    112     POST = QueryDict('', mutable=True) 
    113     FILES = MultiValueDict() 
    114     for submessage in msg.get_payload(): 
    115         if submessage and isinstance(submessage, email.Message.Message): 
    116             name_dict = parse_header(submessage['Content-Disposition'])[1] 
    117             # name_dict is something like {'name': 'file', 'filename': 'test.txt'} for file uploads 
    118             # or {'name': 'blah'} for POST fields 
    119             # We assume all uploaded files have a 'filename' set. 
    120             if 'filename' in name_dict: 
    121                 assert type([]) != type(submessage.get_payload()), "Nested MIME messages are not supported" 
    122                 if not name_dict['filename'].strip(): 
    123                     continue 
    124                 # IE submits the full path, so trim everything but the basename. 
    125                 # (We can't use os.path.basename because that uses the server's 
    126                 # directory separator, which may not be the same as the 
    127                 # client's one.) 
    128                 filename = name_dict['filename'][name_dict['filename'].rfind("\\")+1:] 
    129                 FILES.appendlist(name_dict['name'], FileDict({ 
    130                     'filename': filename, 
    131                     'content-type': 'Content-Type' in submessage and submessage['Content-Type'] or None, 
    132                     'content': submessage.get_payload(), 
    133                 })) 
    134             else: 
    135                 POST.appendlist(name_dict['name'], submessage.get_payload()) 
    136     return POST, FILES 
    137  
     107    def _initialize_handlers(self): 
     108        self._upload_handlers = [uploadhandler.load_handler(handler, self) 
     109                                 for handler in settings.FILE_UPLOAD_HANDLERS] 
     110 
     111    def _set_upload_handlers(self, upload_handlers): 
     112        if hasattr(self, '_files'): 
     113            raise AttributeError("You cannot set the upload handlers after the upload has been processed.") 
     114        self._upload_handlers = upload_handlers 
     115 
     116    def _get_upload_handlers(self): 
     117        if not self._upload_handlers: 
     118            # If thre are no upload handlers defined, initialize them from settings. 
     119            self._initialize_handlers() 
     120        return self._upload_handlers 
     121 
     122    upload_handlers = property(_get_upload_handlers, _set_upload_handlers) 
     123 
     124    def parse_file_upload(self, META, post_data): 
     125        """Returns a tuple of (POST QueryDict, FILES MultiValueDict).""" 
     126        self.upload_handlers = ImmutableList( 
     127            self.upload_handlers, 
     128            warning = "You cannot alter upload handlers after the upload has been processed." 
     129        ) 
     130        parser = MultiPartParser(META, post_data, self.upload_handlers, self.encoding) 
     131        return parser.parse() 
    138132 
    139133class QueryDict(MultiValueDict): 
  • django/branches/newforms-admin/django/newforms/fields.py

    r7809 r7815  
    88import re 
    99import time 
     10try: 
     11    from cStringIO import StringIO 
     12except ImportError: 
     13    from StringIO import StringIO 
     14 
    1015# Python 2.3 fallbacks 
    1116try: 
     
    417422class UploadedFile(StrAndUnicode): 
    418423    "A wrapper for files uploaded in a FileField" 
    419     def __init__(self, filename, content): 
     424    def __init__(self, filename, data): 
    420425        self.filename = filename 
    421         self.content = content 
     426        self.data = data 
    422427 
    423428    def __unicode__(self): 
     
    445450        elif not data and initial: 
    446451            return initial 
     452 
     453        if isinstance(data, dict): 
     454            # We warn once, then support both ways below. 
     455            import warnings 
     456            warnings.warn( 
     457                message = "Representing uploaded files as dictionaries is"\ 
     458                          " deprecated. Use django.core.files.SimpleUploadedFile "\ 
     459                          " instead.", 
     460                category = DeprecationWarning, 
     461                stacklevel = 2 
     462            ) 
     463 
    447464        try: 
    448             f = UploadedFile(data['filename'], data['content']) 
    449         except TypeError: 
     465            file_name = data.file_name 
     466            file_size = data.file_size 
     467        except AttributeError: 
     468            try: 
     469                file_name = data.get('filename') 
     470                file_size = bool(data['content']) 
     471            except (AttributeError, KeyError): 
     472                raise ValidationError(self.error_messages['invalid']) 
     473 
     474        if not file_name: 
    450475            raise ValidationError(self.error_messages['invalid']) 
    451         except KeyError: 
    452             raise ValidationError(self.error_messages['missing']) 
    453         if not f.content: 
     476        if not file_size: 
    454477            raise ValidationError(self.error_messages['empty']) 
    455         return f 
     478 
     479        return UploadedFile(file_name, data) 
    456480 
    457481class ImageField(FileField): 
     
    471495            return initial 
    472496        from PIL import Image 
    473         from cStringIO import StringIO 
     497 
     498        # We need to get a file object for PIL. We might have a path or we might 
     499        # have to read the data into memory. 
     500        if hasattr(data, 'temporary_file_path'): 
     501            file = data.temporary_file_path() 
     502        else: 
     503            if hasattr(data, 'read'): 
     504                file = StringIO(data.read()) 
     505            else: 
     506                file = StringIO(data['content']) 
     507 
    474508        try: 
    475509            # load() is the only method that can spot a truncated JPEG, 
    476510            #  but it cannot be called sanely after verify() 
    477             trial_image = Image.open(StringIO(f.content)
     511            trial_image = Image.open(file
    478512            trial_image.load() 
     513 
     514            # Since we're about to use the file again we have to reset the 
     515            # file object if possible. 
     516            if hasattr(file, 'reset'): 
     517                file.reset() 
     518 
    479519            # verify() is the only method that can spot a corrupt PNG, 
    480520            #  but it must be called immediately after the constructor 
    481             trial_image = Image.open(StringIO(f.content)
     521            trial_image = Image.open(file
    482522            trial_image.verify() 
    483523        except Exception: # Python Imaging Library doesn't recognize it as an image 
  • django/branches/newforms-admin/django/oldforms/__init__.py

    r6776 r7815  
    681681        self.validator_list = [self.isNonEmptyFile] + validator_list 
    682682 
    683     def isNonEmptyFile(self, field_data, all_data): 
    684         try: 
    685             content = field_data['content'] 
    686         except TypeError: 
    687             raise validators.CriticalValidationError, ugettext("No file was submitted. Check the encoding type on the form.") 
    688         if not content: 
     683    def isNonEmptyFile(self, new_data, all_data): 
     684        if hasattr(new_data, 'upload_errors'): 
     685            upload_errors = new_data.upload_errors() 
     686            if upload_errors: 
     687                raise validators.CriticalValidationError, upload_errors 
     688        try: 
     689            file_size = new_data.file_size 
     690        except AttributeError: 
     691            file_size = len(new_data['content']) 
     692        if not file_size: 
    689693            raise validators.CriticalValidationError, ugettext("The submitted file is empty.") 
    690694 
     
    692696        return mark_safe(u'<input type="file" id="%s" class="v%s" name="%s" />' % \ 
    693697            (self.get_id(), self.__class__.__name__, self.field_name)) 
     698 
     699    def prepare(self, new_data): 
     700        if hasattr(new_data, 'upload_errors'): 
     701            upload_errors = new_data.upload_errors() 
     702            new_data[self.field_name] = { '_file_upload_error': upload_errors } 
    694703 
    695704    def html2python(data): 
  • django/branches/newforms-admin/django/test/client.py

    r7584 r7815  
    22import sys 
    33import os 
    4 from cStringIO import StringIO 
     4try: 
     5    from cStringIO import StringIO 
     6except ImportError: 
     7    from StringIO import StringIO 
    58from django.conf import settings 
    69from django.contrib.auth import authenticate, login 
     
    1922BOUNDARY = 'BoUnDaRyStRiNg' 
    2023MULTIPART_CONTENT = 'multipart/form-data; boundary=%s' % BOUNDARY 
     24 
     25class FakePayload(object): 
     26    """ 
     27    A wrapper around StringIO that restricts what can be read since data from 
     28    the network can't be seeked and cannot be read outside of its content 
     29    length. This makes sure that views can't do anything under the test client 
     30    that wouldn't work in Real Life. 
     31    """ 
     32    def __init__(self, content): 
     33        self.__content = StringIO(content) 
     34        self.__len = len(content) 
     35 
     36    def read(self, num_bytes=None): 
     37        if num_bytes is None: 
     38            num_bytes = self.__len or 1 
     39        assert self.__len >= num_bytes, "Cannot read more than the available bytes from the HTTP incoming data." 
     40        content = self.__content.read(num_bytes) 
     41        self.__len -= num_bytes 
     42        return content 
    2143 
    2244class ClientHandler(BaseHandler): 
     
    237259            'PATH_INFO':      urllib.unquote(path), 
    238260            'REQUEST_METHOD': 'POST', 
    239             'wsgi.input':     StringIO(post_data), 
     261            'wsgi.input':     FakePayload(post_data), 
    240262        } 
    241263        r.update(extra) 
  • django/branches/newforms-admin/django/utils/datastructures.py

    r7770 r7815  
    333333                current = {bits[-1]: v} 
    334334 
    335 class FileDict(dict): 
    336     """ 
    337     A dictionary used to hold uploaded file contents. The only special feature 
    338     here is that repr() of this object won't dump the entire contents of the 
    339     file to the output. A handy safeguard for a large file upload. 
    340     """ 
    341     def __repr__(self): 
    342         if 'content' in self: 
    343             d = dict(self, content='<omitted>') 
    344             return dict.__repr__(d) 
    345         return dict.__repr__(self) 
     335class ImmutableList(tuple): 
     336    """ 
     337    A tuple-like object that raises useful errors when it is asked to mutate. 
     338 
     339    Example:: 
     340 
     341        >>> a = ImmutableList(range(5), warning="You cannot mutate this.") 
     342        >>> a[3] = '4' 
     343        Traceback (most recent call last): 
     344            ... 
     345        AttributeError: You cannot mutate this. 
     346    """ 
     347 
     348    def __new__(cls, *args, **kwargs): 
     349        if 'warning' in kwargs: 
     350            warning = kwargs['warning'] 
     351            del kwargs['warning'] 
     352        else: 
     353            warning = 'ImmutableList object is immutable.' 
     354        self = tuple.__new__(cls, *args, **kwargs) 
     355        self.warning = warning 
     356        return self 
     357 
     358    def complain(self, *wargs, **kwargs): 
     359        if isinstance(self.warning, Exception): 
     360            raise self.warning 
     361        else: 
     362            raise AttributeError, self.warning 
     363 
     364    # All list mutation functions complain. 
     365    __delitem__  = complain 
     366    __delslice__ = complain 
     367    __iadd__     = complain 
     368    __imul__     = complain 
     369    __setitem__  = complain 
     370    __setslice__ = complain 
     371    append       = complain 
     372    extend       = complain 
     373    insert       = complain 
     374    pop          = complain 
     375    remove       = complain 
     376    sort         = complain 
     377    reverse      = complain 
    346378 
    347379class DictWrapper(dict): 
  • django/branches/newforms-admin/django/utils/text.py

    r7584 r7815  
    44from django.utils.functional import allow_lazy 
    55from django.utils.translation import ugettext_lazy 
     6from htmlentitydefs import name2codepoint 
    67 
    78# Capitalizes the first letter of a string. 
     
    223224smart_split = allow_lazy(smart_split, unicode) 
    224225 
     226def _replace_entity(match): 
     227     text = match.group(1) 
     228     if text[0] == u'#': 
     229         text = text[1:] 
     230         try: 
     231             if text[0] in u'xX': 
     232                 c = int(text[1:], 16) 
     233             else: 
     234                 c = int(text) 
     235             return unichr(c) 
     236         except ValueError: 
     237             return match.group(0) 
     238     else: 
     239         try: 
     240             return unichr(name2codepoint[text]) 
     241         except (ValueError, KeyError): 
     242             return match.group(0) 
     243 
     244_entity_re = re.compile(r"&(#?[xX]?(?:[0-9a-fA-F]+|\w{1,8}));") 
     245 
     246def unescape_entities(text): 
     247     return _entity_re.sub(_replace_entity, text) 
     248unescape_entities = allow_lazy(unescape_entities, unicode) 
  • django/branches/newforms-admin/docs/newforms.txt

    r7707 r7815  
    809809 
    810810    # Bound form with an image field 
     811    >>> from django.core.files.uploadedfile import SimpleUploadedFile 
    811812    >>> data = {'subject': 'hello', 
    812813    ...         'message': 'Hi there', 
    813814    ...         'sender': 'foo@example.com', 
    814815    ...         'cc_myself': True} 
    815     >>> file_data = {'mugshot': {'filename':'face.jpg' 
    816     ...                          'content': <file data>}} 
     816    >>> file_data = {'mugshot': SimpleUploadedFile('face.jpg', <file data>)} 
    817817    >>> f = ContactFormWithMugshot(data, file_data) 
    818818 
  • django/branches/newforms-admin/docs/request_response.txt

    r7533 r7815  
    8181 
    8282``FILES`` 
     83     
     84    .. admonition:: Changed in Django development version 
     85         
     86        In previous versions of Django, ``request.FILES`` contained 
     87        simple ``dict`` objects representing uploaded files. This is 
     88        no longer true -- files are represented by ``UploadedFile`` 
     89        objects as described below. 
     90         
     91        These ``UploadedFile`` objects will emulate the old-style ``dict`` 
     92        interface, but this is deprecated and will be removed in the next 
     93        release of Django. 
     94         
    8395    A dictionary-like object containing all uploaded files. Each key in 
    8496    ``FILES`` is the ``name`` from the ``<input type="file" name="" />``. Each 
    85     value in ``FILES`` is a standard Python dictionary with the following three 
    86     keys: 
    87  
    88         * ``filename`` -- The name of the uploaded file, as a Python string. 
    89         * ``content-type`` -- The content type of the uploaded file. 
    90         * ``content`` -- The raw content of the uploaded file. 
    91  
     97    value in ``FILES`` is an ``UploadedFile`` object containing the following 
     98    attributes: 
     99 
     100        * ``read(num_bytes=None)`` -- Read a number of bytes from the file. 
     101        * ``file_name`` -- The name of the uploaded file. 
     102        * ``file_size`` -- The size, in bytes, of the uploaded file. 
     103        * ``chunk()`` -- A generator that yields sequential chunks of data. 
     104 
     105    See `File Uploads`_ for more information.  
     106     
    92107    Note that ``FILES`` will only contain data if the request method was POST 
    93108    and the ``<form>`` that posted to the request had 
    94109    ``enctype="multipart/form-data"``. Otherwise, ``FILES`` will be a blank 
    95110    dictionary-like object. 
     111     
     112    .. _File Uploads: ../upload_handling/ 
    96113 
    97114``META`` 
  • django/branches/newforms-admin/docs/settings.txt

    r7707 r7815  
    280280The database backend to use. The build-in database backends are 
    281281``'postgresql_psycopg2'``, ``'postgresql'``, ``'mysql'``, ``'mysql_old'``, 
    282 ``'sqlite3'`` and ``'oracle'``. 
     282``'sqlite3'``, ``'oracle'``, and ``'oracle'``. 
    283283 
    284284In the Django development version, you can use a database backend that doesn't 
     
    530530The character encoding used to decode any files read from disk. This includes 
    531531template files and initial SQL data files. 
     532 
     533FILE_UPLOAD_HANDLERS 
     534-------------------- 
     535 
     536**New in Django development version** 
     537 
     538Default:: 
     539 
     540    ("django.core.files.fileuploadhandler.MemoryFileUploadHandler", 
     541     "django.core.files.fileuploadhandler.TemporaryFileUploadHandler",) 
     542 
     543A tuple of handlers to use for uploading. See `file uploads`_ for details. 
     544 
     545.. _file uploads: ../upload_handling/ 
     546 
     547FILE_UPLOAD_MAX_MEMORY_SIZE 
     548--------------------------- 
     549 
     550**New in Django development version** 
     551 
     552Default: ``2621440`` (i.e. 2.5 MB). 
     553 
     554The maximum size (in bytes) that an upload will be before it gets streamed to 
     555the file system. See `file uploads`_ for details. 
     556 
     557FILE_UPLOAD_TEMP_DIR 
     558-------------------- 
     559 
     560**New in Django development version** 
     561 
     562Default: ``None`` 
     563 
     564The directory to store data temporarily while uploading files. If ``None``, 
     565Django will use the standard temporary directory for the operating system. For 
     566example, this will default to '/tmp' on *nix-style operating systems. 
     567 
     568See `file uploads`_ for details. 
    532569 
    533570FIXTURE_DIRS 
  • django/branches/newforms-admin/docs/sitemaps.txt

    r7351 r7815  
    318318to Google's servers, so you may not want to introduce that network overhead 
    319319each time you call ``save()``. 
     320 
     321Pinging Google via `manage.py` 
     322------------------------------ 
     323 
     324**New in Django development version** 
     325 
     326Once the sitemaps application is added to your project, you may also 
     327ping the Google server's through the command line manage.py interface:: 
     328 
     329    python manage.py ping_google [/sitemap.xml] 
     330 
  • django/branches/newforms-admin/docs/templates.txt

    r7707 r7815  
    478478This means you would write :: 
    479479 
    480     {{ data|default:"3 &gt; 2" }} 
     480    {{ data|default:"3 &lt; 2" }} 
    481481 
    482482...rather than :: 
    483483 
    484     {{ data|default:"3 > 2" }}  <-- Bad! Don't do this. 
     484    {{ data|default:"3 < 2" }}  <-- Bad! Don't do this. 
    485485 
    486486This doesn't affect what happens to data coming from the variable itself. 
  • django/branches/newforms-admin/tests/modeltests/model_forms/models.py

    r7365 r7815  
    6868class ImageFile(models.Model): 
    6969    description = models.CharField(max_length=20) 
    70     image = models.FileField(upload_to=tempfile.gettempdir()) 
     70    try: 
     71        # If PIL is available, try testing PIL. 
     72        # Otherwise, it's equivalent to TextFile above. 
     73        import Image 
     74        image = models.ImageField(upload_to=tempfile.gettempdir()) 
     75    except ImportError: 
     76        image = models.FileField(upload_to=tempfile.gettempdir()) 
    7177 
    7278    def __unicode__(self): 
     
    7682>>> from django import newforms as forms 
    7783>>> from django.newforms.models import ModelForm 
     84>>> from django.core.files.uploadedfile