diff --git a/contrib/conf/kiwi-httpd.conf b/contrib/conf/kiwi-httpd.conf index 873a2426b2..ffddc3bb80 100644 --- a/contrib/conf/kiwi-httpd.conf +++ b/contrib/conf/kiwi-httpd.conf @@ -62,3 +62,27 @@ Alias /static /usr/share/kiwi/static ExpiresActive On ExpiresDefault "access plus 10 years" + +# user uploaded files +Alias /uploads /var/kiwi/uploads + + + SetHandler None + Options -Indexes + + # Disable auth on the static content, so that we're aren't forced to + # use Kerberos. Doing so would remove "Expires" headers from the static + # content, which would lead to poor page-load times. + AuthType none + Satisfy Any + Allow from All + + # Many file types are likely to benefit from compression + # Enable gzip compression on them: + AddOutputFilterByType DEFLATE text/html text/plain text/xml text/javascript application/x-javascript text/css + + # Set far-future Expires headers on static content + # (trac 184): + ExpiresActive On + ExpiresDefault "access plus 10 years" + diff --git a/tcms/core/files.py b/tcms/core/files.py index 0dcea48d15..14ed806d17 100644 --- a/tcms/core/files.py +++ b/tcms/core/files.py @@ -50,7 +50,7 @@ def upload_file(request): stored_name = '%s-%s-%s' % (request.user.username, now, upload_file.name) stored_file_name = os.path.join( - settings.FILE_UPLOAD_DIR, stored_name).replace('\\', '/') + settings.MEDIA_ROOT, stored_name).replace('\\', '/') stored_file_name = smart_str(stored_file_name) if upload_file.size > settings.MAX_UPLOAD_SIZE: @@ -63,8 +63,8 @@ def upload_file(request): ) # Create the upload directory when it's not exist - if not os.path.exists(settings.FILE_UPLOAD_DIR): - os.mkdir(settings.FILE_UPLOAD_DIR) + if not os.path.exists(settings.MEDIA_ROOT): + os.mkdir(settings.MEDIA_ROOT) if os.path.exists(stored_file_name): return Prompt.render( @@ -143,7 +143,7 @@ def check_file(request, file_id): except TestAttachmentData.DoesNotExist: if attachment.stored_name: stored_file_name = os.path.join( - settings.FILE_UPLOAD_DIR, unquote(attachment.stored_name) + settings.MEDIA_ROOT, unquote(attachment.stored_name) ).replace('\\', '/') stored_file_name = stored_file_name.encode('utf-8') try: @@ -153,7 +153,7 @@ def check_file(request, file_id): raise Http404(error) else: stored_file_name = os.path.join( - settings.FILE_UPLOAD_DIR, unquote(attachment.file_name) + settings.MEDIA_ROOT, unquote(attachment.file_name) ).replace('\\', '/') stored_file_name = stored_file_name.encode('utf-8') try: diff --git a/tcms/core/tests/test_files.py b/tcms/core/tests/test_files.py index fd0da66c2e..80d7f0e189 100644 --- a/tcms/core/tests/test_files.py +++ b/tcms/core/tests/test_files.py @@ -92,7 +92,7 @@ def test_refuse_if_file_is_too_big(self): def test_upload_file_to_plan(self): self.client.login(username=self.user.username, password=self.password) - with patch('tcms.core.files.settings.FILE_UPLOAD_DIR', + with patch('tcms.core.files.settings.MEDIA_ROOT', new=self.file_upload_dir): with open(self.upload_filename, 'r') as upload_file: response = self.client.post(self.upload_file_url, @@ -117,7 +117,7 @@ def test_upload_file_to_plan(self): def test_upload_file_to_case(self): self.client.login(username=self.user.username, password=self.password) - with patch('tcms.core.files.settings.FILE_UPLOAD_DIR', + with patch('tcms.core.files.settings.MEDIA_ROOT', new=self.file_upload_dir): with open(self.upload_filename, 'r') as upload_file: response = self.client.post(self.upload_file_url, diff --git a/tcms/settings/common.py b/tcms/settings/common.py index 4984df1531..323da3037b 100644 --- a/tcms/settings/common.py +++ b/tcms/settings/common.py @@ -63,10 +63,6 @@ MAX_UPLOAD_SIZE = 5242880 -# Attachement file download path -FILE_UPLOAD_DIR = '/var/kiwi/uploads' - - # TCMS email templates PLAN_EMAIL_TEMPLATE = 'mail/change_plan.txt' PLAN_DELELE_EMAIL_TEMPLATE = 'mail/delete_plan.txt' @@ -135,13 +131,12 @@ TIME_ZONE = 'Etc/UTC' # Absolute filesystem path to the directory that will hold user-uploaded files. -# Example: "/var/www/example.com/media/" -MEDIA_ROOT = '' +MEDIA_ROOT = '/var/kiwi/uploads' # URL that handles the media served from MEDIA_ROOT. Make sure to use a # trailing slash. # Examples: "http://example.com/media/", "http://media.example.com/" -MEDIA_URL = '' +MEDIA_URL = '/uploads/' # URL prefix for admin absolute URL ADMIN_PREFIX = '/admin' diff --git a/tcms/settings/devel.py b/tcms/settings/devel.py index 51936eff26..239e42fbc5 100644 --- a/tcms/settings/devel.py +++ b/tcms/settings/devel.py @@ -24,7 +24,7 @@ INSTALLED_APPS += ['debug_toolbar', 'django_extensions'] # noqa: F405 -FILE_UPLOAD_DIR = os.path.join(TCMS_ROOT_PATH, '..', 'uploads') # noqa: F405 +MEDIA_ROOT = os.path.join(TCMS_ROOT_PATH, '..', 'uploads') # noqa: F405 # Needed by django.template.context_processors.debug: # See: diff --git a/tcms/urls.py b/tcms/urls.py index cd5107bf9a..57e9dfde0c 100644 --- a/tcms/urls.py +++ b/tcms/urls.py @@ -2,6 +2,7 @@ from django.conf import settings from django.conf.urls import include, url +from django.conf.urls.static import static from django.contrib import admin from django.contrib.admindocs import urls as admindocs_urls from django.views.i18n import JavaScriptCatalog @@ -112,6 +113,8 @@ # Debug zone if settings.DEBUG: + urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) + try: import debug_toolbar