summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorLoic Bistuer <loic.bistuer@sixmedia.com>2013-12-10 00:29:39 +0700
committerTim Graham <timograham@gmail.com>2013-12-31 14:58:49 -0500
commit4befb3015c26810a68cfcf57e0cd8b062f56f1c5 (patch)
tree52909117010247223190bf2112bcaf7b0926d3f2 /django
parent4d8d76e7a89858932b6f4f280a0ebf4cf94ab4b7 (diff)
Fixed #21581 -- Fixed a number of issues with collectstatic.
When STATIC_ROOT wasn't set, collectstatic --clear would delete every files within the current directory and its descendants. This patch makes the following changes: Prevent collectstatic from running if STATIC_ROOT isn't set. Fixed an issue that prevented collectstatic from displaying the destination directory. Changed the warning header to notify when the command is run in dry-run mode.
Diffstat (limited to 'django')
-rw-r--r--django/conf/global_settings.py2
-rw-r--r--django/contrib/staticfiles/management/commands/collectstatic.py40
-rw-r--r--django/contrib/staticfiles/storage.py11
3 files changed, 28 insertions, 25 deletions
diff --git a/django/conf/global_settings.py b/django/conf/global_settings.py
index d29dd5ec34..d86a4272cd 100644
--- a/django/conf/global_settings.py
+++ b/django/conf/global_settings.py
@@ -290,7 +290,7 @@ MEDIA_URL = ''
# Absolute path to the directory static files should be collected to.
# Example: "/var/www/example.com/static/"
-STATIC_ROOT = ''
+STATIC_ROOT = None
# URL that handles the static files served from STATIC_ROOT.
# Example: "http://example.com/static/", "http://static.example.com/"
diff --git a/django/contrib/staticfiles/management/commands/collectstatic.py b/django/contrib/staticfiles/management/commands/collectstatic.py
index 67fa6229c4..9009b82c67 100644
--- a/django/contrib/staticfiles/management/commands/collectstatic.py
+++ b/django/contrib/staticfiles/management/commands/collectstatic.py
@@ -137,32 +137,38 @@ class Command(NoArgsCommand):
def handle_noargs(self, **options):
self.set_options(**options)
- # Warn before doing anything more.
- if (isinstance(self.storage, FileSystemStorage) and
+
+ message = ['\n']
+ if self.dry_run:
+ message.append(
+ 'You have activated the --dry-run option so no files will be modified.\n\n'
+ )
+
+ message.append(
+ 'You have requested to collect static files at the destination\n'
+ 'location as specified in your settings'
+ )
+
+ if (isinstance(self.storage._wrapped, FileSystemStorage) and
self.storage.location):
destination_path = self.storage.location
- destination_display = ':\n\n %s' % destination_path
+ message.append(':\n\n %s\n\n' % destination_path)
else:
destination_path = None
- destination_display = '.'
+ message.append('.\n\n')
if self.clear:
- clear_display = 'This will DELETE EXISTING FILES!'
+ message.append('This will DELETE EXISTING FILES!\n')
else:
- clear_display = 'This will overwrite existing files!'
-
- if self.interactive:
- confirm = input("""
-You have requested to collect static files at the destination
-location as specified in your settings%s
+ message.append('This will overwrite existing files!\n')
-%s
-Are you sure you want to do this?
+ message.append(
+ 'Are you sure you want to do this?\n\n'
+ "Type 'yes' to continue, or 'no' to cancel: "
+ )
-Type 'yes' to continue, or 'no' to cancel: """
-% (destination_display, clear_display))
- if confirm != 'yes':
- raise CommandError("Collecting static files cancelled.")
+ if self.interactive and input(''.join(message)) != 'yes':
+ raise CommandError("Collecting static files cancelled.")
collected = self.collect()
modified_count = len(collected['modified'])
diff --git a/django/contrib/staticfiles/storage.py b/django/contrib/staticfiles/storage.py
index 5190a299e4..b5d05aa6b2 100644
--- a/django/contrib/staticfiles/storage.py
+++ b/django/contrib/staticfiles/storage.py
@@ -32,16 +32,13 @@ class StaticFilesStorage(FileSystemStorage):
location = settings.STATIC_ROOT
if base_url is None:
base_url = settings.STATIC_URL
- check_settings(base_url)
- super(StaticFilesStorage, self).__init__(location, base_url,
- *args, **kwargs)
-
- def path(self, name):
- if not self.location:
+ if not location:
raise ImproperlyConfigured("You're using the staticfiles app "
"without having set the STATIC_ROOT "
"setting to a filesystem path.")
- return super(StaticFilesStorage, self).path(name)
+ check_settings(base_url)
+ super(StaticFilesStorage, self).__init__(location, base_url,
+ *args, **kwargs)
class CachedFilesMixin(object):