我们从Python开源项目中,提取了以下34个代码示例,用于说明如何使用django.conf.settings.DEFAULT_FILE_STORAGE。
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
def get_storage_class(import_path=None): return import_string(import_path or settings.DEFAULT_FILE_STORAGE)
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
def get_storage_class(import_path=None): return import_by_path(import_path or settings.DEFAULT_FILE_STORAGE)
def setup_test_environment(self): "Create temp directory and update MEDIA_ROOT and default storage." super().setup_test_environment() settings._original_media_root = settings.MEDIA_ROOT settings._original_file_storage = settings.DEFAULT_FILE_STORAGE self._temp_media = tempfile.mkdtemp() settings.MEDIA_ROOT = self._temp_media settings.DEFAULT_FILE_STORAGE = 'django.core.files.storage.FileSystemStorage'
def teardown_test_environment(self): "Delete temp storage." super().teardown_test_environment() shutil.rmtree(self._temp_media, ignore_errors=True) 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
def do_import(self): """ Imports objects into database """ self.stdout.write(self.style.MIGRATE_HEADING('\nBeginning import:')) if settings.DEFAULT_FILE_STORAGE == 'storages.backends.s3boto3.S3Boto3Storage': with default_storage.open('data/tStudyAreas.csv', 'r') as areas_csv_bin, \ default_storage.open('data/Kea.csv', 'r') as birds_csv_bin, \ default_storage.open('data/Transmitter actions.csv', 'r') as transmitters_csv_bin: # boto3 opens files as binary, hence the need to convert areas_csv = io.StringIO(areas_csv_bin.read().decode('utf-8')) birds_csv = io.StringIO(birds_csv_bin.read().decode('utf-8')) transmitters_csv = io.StringIO(transmitters_csv_bin.read().decode('utf-8')) synchronise_StudyArea(self, areas_csv) synchronise_Bird(self, birds_csv) synchronise_BandCombo(self, transmitters_csv) else: with open('../data/tStudyAreas.csv', 'rt') as areas_csv, \ open('../data/Kea.csv', 'rt') as birds_csv, \ open('../data/Transmitter actions.csv', 'rt') as transmitters_csv: synchronise_StudyArea(self, areas_csv) synchronise_Bird(self, birds_csv) synchronise_BandCombo(self, transmitters_csv) self.stdout.write(self.style.SUCCESS('\nImport complete'))
def handle(self, *args, **options): self.check_current_status() self.stdout.write('\nUsing input data from: %s' % settings.DEFAULT_FILE_STORAGE) confirm = input('\nReady to import? Type \'yes\' to continue: ') #confirm = 'yes' # for debugging if confirm == 'yes': self.do_import() else: self.stdout.write('\nImport cancelled!')