Changeset 8640
- Timestamp:
- 08/27/08 17:21:14 (3 months ago)
- Files:
-
- django/trunk/django/conf/global_settings.py (modified) (1 diff)
- django/trunk/django/core/files/storage.py (modified) (1 diff)
- django/trunk/docs/ref/settings.txt (modified) (4 diffs)
- django/trunk/docs/topics/http/file-uploads.txt (modified) (2 diffs)
- django/trunk/tests/regressiontests/file_storage/tests.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/trunk/django/conf/global_settings.py
r8537 r8640 253 253 FILE_UPLOAD_TEMP_DIR = None 254 254 255 # The numeric mode to set newly-uploaded files to. The value should be a mode 256 # you'd pass directly to os.chmod; see http://docs.python.org/lib/os-file-dir.html. 257 FILE_UPLOAD_PERMISSIONS = None 258 255 259 # Default formatting for date objects. See all available format strings here: 256 260 # http://www.djangoproject.com/documentation/templates/#now django/trunk/django/core/files/storage.py
r8639 r8640 173 173 # OK, the file save worked. Break out of the loop. 174 174 break 175 175 176 if settings.FILE_UPLOAD_PERMISSIONS is not None: 177 os.chmod(full_path, settings.FILE_UPLOAD_PERMISSIONS) 178 176 179 return name 177 180 django/trunk/docs/ref/settings.txt
r8612 r8640 454 454 template files and initial SQL data files. 455 455 456 .. setting:: FILE_UPLOAD_HANDLERS 457 456 458 FILE_UPLOAD_HANDLERS 457 459 -------------------- … … 466 468 A tuple of handlers to use for uploading. See :ref:`topics-files` for details. 467 469 470 .. setting:: FILE_UPLOAD_MAX_MEMORY_SIZE 471 468 472 FILE_UPLOAD_MAX_MEMORY_SIZE 469 473 --------------------------- … … 475 479 The maximum size (in bytes) that an upload will be before it gets streamed to 476 480 the file system. See :ref:`topics-files` for details. 481 482 .. setting:: FILE_UPLOAD_TEMP_DIR 477 483 478 484 FILE_UPLOAD_TEMP_DIR … … 488 494 489 495 See :ref:`topics-files` for details. 496 497 .. setting:: FILE_UPLOAD_PERMISSIONS 498 499 FILE_UPLOAD_PERMISSIONS 500 ----------------------- 501 502 Default: ``None`` 503 504 The numeric mode (i.e. ``0644``) to set newly uploaded files to. For 505 more information about what these modes mean, see the `documentation for 506 os.chmod`_ 507 508 If this isn't given or is ``None``, you'll get operating-system 509 dependent behavior. On most platforms, temporary files will have a mode 510 of ``0600``, and files saved from memory will be saved using the 511 system's standard umask. 512 513 .. warning:: 514 515 **Always prefix the mode with a 0.** 516 517 If you're not familiar with file modes, please note that the leading 518 ``0`` is very important: it indicates an octal number, which is the 519 way that modes must be specified. If you try to use ``644``, you'll 520 get totally incorrect behavior. 521 522 523 .. _documentation for os.chmod: http://docs.python.org/lib/os-file-dir.html 490 524 491 525 .. setting:: FIXTURE_DIRS django/trunk/docs/topics/http/file-uploads.txt
r8506 r8640 123 123 Three settings control Django's file upload behavior: 124 124 125 ``FILE_UPLOAD_MAX_MEMORY_SIZE``126 The maximum size, in bytes, for files that will be uploaded 127 into memory. Files larger than ``FILE_UPLOAD_MAX_MEMORY_SIZE``128 will bestreamed to disk.125 :setting:`FILE_UPLOAD_MAX_MEMORY_SIZE` 126 The maximum size, in bytes, for files that will be uploaded into memory. 127 Files larger than :setting:`FILE_UPLOAD_MAX_MEMORY_SIZE` will be 128 streamed to disk. 129 129 130 130 Defaults to 2.5 megabytes. 131 131 132 ``FILE_UPLOAD_TEMP_DIR``133 The directory where uploaded files larger than ``FILE_UPLOAD_TEMP_DIR``134 will be stored.132 :setting:`FILE_UPLOAD_TEMP_DIR` 133 The directory where uploaded files larger than 134 :setting:`FILE_UPLOAD_TEMP_DIR` will be stored. 135 135 136 136 Defaults to your system's standard temporary directory (i.e. ``/tmp`` on 137 137 most Unix-like systems). 138 139 ``FILE_UPLOAD_HANDLERS`` 140 The actual handlers for uploaded files. Changing this setting 141 allows complete customization -- even replacement -- of 142 Django's upload process. See `upload handlers`_, below, 143 for details. 138 139 :setting:`FILE_UPLOAD_PERMISSIONS` 140 The numeric mode (i.e. ``0644``) to set newly uploaded files to. For 141 more information about what these modes mean, see the `documentation for 142 os.chmod`_ 143 144 If this isn't given or is ``None``, you'll get operating-system 145 dependent behavior. On most platforms, temporary files will have a mode 146 of ``0600``, and files saved from memory will be saved using the 147 system's standard umask. 148 149 .. warning:: 150 151 If you're not familiar with file modes, please note that the leading 152 ``0`` is very important: it indicates an octal number, which is the 153 way that modes must be specified. If you try to use ``644``, you'll 154 get totally incorrect behavior. 155 156 **Always prefix the mode with a ``0``.** 157 158 :setting:`FILE_UPLOAD_HANDLERS` 159 The actual handlers for uploaded files. Changing this setting allows 160 complete customization -- even replacement -- of Django's upload 161 process. See `upload handlers`_, below, for details. 144 162 145 163 Defaults to:: … … 150 168 Which means "try to upload to memory first, then fall back to temporary 151 169 files." 170 171 .. _documentation for os.chmod: http://docs.python.org/lib/os-file-dir.html 152 172 153 173 ``UploadedFile`` objects django/trunk/tests/regressiontests/file_storage/tests.py
r8636 r8640 87 87 # This is written in such a way that it'll always pass on platforms 88 88 # without threading. 89 89 import os 90 90 import time 91 91 from unittest import TestCase 92 from django.conf import settings 92 93 from django.core.files.base import ContentFile 93 94 from models import temp_storage … … 118 119 temp_storage.delete('conflict_') 119 120 121 class FileStoragePermissions(TestCase): 122 def setUp(self): 123 self.old_perms = settings.FILE_UPLOAD_PERMISSIONS 124 settings.FILE_UPLOAD_PERMISSIONS = 0666 125 126 def test_file_upload_permissions(self): 127 name = temp_storage.save("the_file", ContentFile("data")) 128 actual_mode = os.stat(temp_storage.path(name))[0] & 0777 129 self.assertEqual(actual_mode, 0666) 130 131 def tearDown(self): 132 settings.FILE_UPLOAD_PERMISSIONS = self.old_perms
