Python django.conf.settings.DEFAULT_FILE_STORAGE Examples

The following are 7 code examples for showing how to use django.conf.settings.DEFAULT_FILE_STORAGE(). These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.

You may check out the related API usage on the sidebar.

You may also want to check out all available functions/classes of the module django.conf.settings , or try the search function .

Example 1
Project: luscan-devel   Author: blackye   File: storage.py    License: GNU General Public License v2.0 6 votes vote down vote up
def get_storage_class(import_path=None):
    if import_path is None:
        import_path = settings.DEFAULT_FILE_STORAGE
    try:
        dot = import_path.rindex('.')
    except ValueError:
        raise ImproperlyConfigured("%s isn't a storage module." % import_path)
    module, classname = import_path[:dot], import_path[dot+1:]
    try:
        mod = import_module(module)
    except ImportError as e:
        raise ImproperlyConfigured('Error importing storage module %s: "%s"' % (module, e))
    try:
        return getattr(mod, classname)
    except AttributeError:
        raise ImproperlyConfigured('Storage module "%s" does not define a "%s" class.' % (module, classname)) 
Example 2
Project: developer-portal   Author: mdn   File: test_utils.py    License: Mozilla Public License 2.0 6 votes vote down vote up
def test__store_external_image__local_filesystem(self, mock_requests_get):
        # This test is written assuming local file storage, even though
        # everything apart from CI will be using S3 as its backend. The function
        # HAS been tested with S3, though.
        assert (
            settings.DEFAULT_FILE_STORAGE
            == "django.core.files.storage.FileSystemStorage"
        )
        mock_response = mock.Mock()
        mock_response.content = image_one_bytearray
        mock_requests_get.return_value = mock_response

        saved_image = _store_external_image(image_url="https://example.com/test.png")

        mock_requests_get.assert_called_once_with("https://example.com/test.png")

        saved_image.file.open()
        saved_image.file.seek(0)
        comparison_content = saved_image.file.read()
        self.assertEqual(bytearray(comparison_content), image_one_bytearray) 
Example 3
Project: django-content-gallery   Author: Kemaweyan   File: runner.py    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def setup_test_environment(self):
        """
        Setups the environment. Creates a temporary directory
        and saves default the values of environment settings
        """
        super().setup_test_environment()
        # save original settings
        settings._original_media_root = settings.MEDIA_ROOT
        settings._original_file_storage = settings.DEFAULT_FILE_STORAGE
        # create a temporary directory
        self._temp_media = tempfile.mkdtemp()
        # set a new media directory setting
        settings.MEDIA_ROOT = self._temp_media
        # set a file system storage setting
        storage = 'django.core.files.storage.FileSystemStorage'
        settings.DEFAULT_FILE_STORAGE = storage 
Example 4
Project: GTDWeb   Author: lanbing510   File: storage.py    License: GNU General Public License v2.0 5 votes vote down vote up
def get_storage_class(import_path=None):
    return import_string(import_path or settings.DEFAULT_FILE_STORAGE) 
Example 5
Project: OasisPlatform   Author: OasisLMF   File: views.py    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def get(self, request):
        server_version = ""
        server_config = dict()

        try:
            with open('VERSION', 'r') as ver:
                server_version = ver.read().strip()
        except FileNotFoundError:
            server_version = ""

        server_config['DEBUG'] = settings.DEBUG
        server_config['LANGUAGE_CODE'] = settings.LANGUAGE_CODE
        server_config['TIME_ZONE'] = settings.TIME_ZONE

        # Backends  
        server_config['WSGI_APPLICATION'] = settings.WSGI_APPLICATION
        server_config['DEFAULT_FILE_STORAGE'] = settings.DEFAULT_FILE_STORAGE
        server_config['DB_ENGINE'] = settings.DB_ENGINE

        # Storage 
        server_config['STORAGE_TYPE'] = settings.STORAGE_TYPE
        server_config['MEDIA_ROOT'] = settings.MEDIA_ROOT
        server_config['AWS_STORAGE_BUCKET_NAME'] = settings.AWS_STORAGE_BUCKET_NAME
        server_config['AWS_LOCATION'] = settings.AWS_LOCATION
        server_config['AWS_SHARED_BUCKET'] = settings.AWS_SHARED_BUCKET
        server_config['AWS_QUERYSTRING_EXPIRE'] = settings.AWS_QUERYSTRING_EXPIRE
        server_config['AWS_QUERYSTRING_AUTH'] = settings.AWS_QUERYSTRING_AUTH

        # Token Conf
        server_config['ROTATE_REFRESH_TOKEN'] = settings.SIMPLE_JWT['ROTATE_REFRESH_TOKENS']
        server_config['ACCESS_TOKEN_LIFETIME'] = settings.SIMPLE_JWT['ACCESS_TOKEN_LIFETIME']
        server_config['REFRESH_TOKEN_LIFETIME'] = settings.SIMPLE_JWT['REFRESH_TOKEN_LIFETIME']

        return Response({
            'version': server_version,
            'config': server_config
        }) 
Example 6
Project: OasisPlatform   Author: OasisLMF   File: tasks.py    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def log_worker_monitor(sender, **k):
    logger.info('DEBUG: {}'.format(settings.DEBUG))    
    logger.info('DB_ENGINE: {}'.format(settings.DB_ENGINE))    
    logger.info('STORAGE_TYPE: {}'.format(settings.STORAGE_TYPE))    
    logger.info('DEFAULT_FILE_STORAGE: {}'.format(settings.DEFAULT_FILE_STORAGE))    
    logger.info('MEDIA_ROOT: {}'.format(settings.MEDIA_ROOT))    
    logger.info('AWS_STORAGE_BUCKET_NAME: {}'.format(settings.AWS_STORAGE_BUCKET_NAME))    
    logger.info('AWS_LOCATION: {}'.format(settings.AWS_LOCATION))    
    logger.info('AWS_S3_REGION_NAME: {}'.format(settings.AWS_S3_REGION_NAME))    
    logger.info('AWS_QUERYSTRING_AUTH: {}'.format(settings.AWS_QUERYSTRING_AUTH))    
    logger.info('AWS_QUERYSTRING_EXPIRE: {}'.format(settings.AWS_QUERYSTRING_EXPIRE))    
    logger.info('AWS_SHARED_BUCKET: {}'.format(settings.AWS_SHARED_BUCKET))    
    logger.info('AWS_IS_GZIPPED: {}'.format(settings.AWS_IS_GZIPPED)) 
Example 7
Project: django-content-gallery   Author: Kemaweyan   File: runner.py    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def teardown_test_environment(self):
        """
        Deletes all temporary files and the temporary directory.
        Restores original settings.
        """
        super().teardown_test_environment()
        # remove all temporary files
        shutil.rmtree(self._temp_media, ignore_errors=True)
        # restore original settings and delete saved values
        settings.MEDIA_ROOT = settings._original_media_root
        del settings._original_media_root
        settings.DEFAULT_FILE_STORAGE = settings._original_file_storage
        del settings._original_file_storage