當前位置: 首頁>>代碼示例>>Python>>正文


Python storage.get_storage_class方法代碼示例

本文整理匯總了Python中django.core.files.storage.get_storage_class方法的典型用法代碼示例。如果您正苦於以下問題:Python storage.get_storage_class方法的具體用法?Python storage.get_storage_class怎麽用?Python storage.get_storage_class使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在django.core.files.storage的用法示例。


在下文中一共展示了storage.get_storage_class方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: image_urls_dict

# 需要導入模塊: from django.core.files import storage [as 別名]
# 或者: from django.core.files.storage import get_storage_class [as 別名]
def image_urls_dict(instance):
    default_storage = get_storage_class()()
    urls = dict()
    suffix = settings.THUMB_CONF['medium']['suffix']
    for a in instance.attachments.all():
        filename = a.media_file.name
        if default_storage.exists(get_path(a.media_file.name, suffix)):
            url = default_storage.url(
                get_path(a.media_file.name, suffix))
        else:
            url = a.media_file.url
        file_basename = os.path.basename(filename)
        if url.startswith('/'):
            url = settings.KOBOCAT_URL + url
        urls[file_basename] = url
    return urls 
開發者ID:awemulya,項目名稱:kobo-predict,代碼行數:18,代碼來源:utils.py

示例2: test_csv_export_output

# 需要導入模塊: from django.core.files import storage [as 別名]
# 或者: from django.core.files.storage import get_storage_class [as 別名]
def test_csv_export_output(self):
        path = os.path.join(self.fixture_dir, 'tutorial_w_repeats.xls')
        self._publish_xls_file_and_set_xform(path)
        path = os.path.join(self.fixture_dir, 'tutorial_w_repeats.xml')
        self._make_submission(
            path, forced_submission_time=self._submission_time)
        # test csv
        export = generate_export(Export.CSV_EXPORT, 'csv', self.user.username,
                                 'tutorial_w_repeats')
        storage = get_storage_class()()
        self.assertTrue(storage.exists(export.filepath))
        path, ext = os.path.splitext(export.filename)
        self.assertEqual(ext, '.csv')
        with open(os.path.join(
                self.fixture_dir, 'tutorial_w_repeats.csv')) as f1:
            with storage.open(export.filepath) as f2:
                expected_content = f1.read()
                actual_content = f2.read()
                self.assertEquals(actual_content, expected_content) 
開發者ID:awemulya,項目名稱:kobo-predict,代碼行數:21,代碼來源:test_csv_export.py

示例3: test_dotted_fields_csv_export_output

# 需要導入模塊: from django.core.files import storage [as 別名]
# 或者: from django.core.files.storage import get_storage_class [as 別名]
def test_dotted_fields_csv_export_output(self):
        path = os.path.join(os.path.dirname(__file__), 'fixtures', 'userone',
                            'userone_with_dot_name_fields.xls')
        self._publish_xls_file_and_set_xform(path)
        path = os.path.join(os.path.dirname(__file__), 'fixtures', 'userone',
                            'userone_with_dot_name_fields.xml')
        self._make_submission(
            path, forced_submission_time=self._submission_time)
        # test csv
        export = generate_export(Export.CSV_EXPORT, 'csv', self.user.username,
                                 'userone')
        storage = get_storage_class()()
        self.assertTrue(storage.exists(export.filepath))
        path, ext = os.path.splitext(export.filename)
        self.assertEqual(ext, '.csv')
        with open(os.path.join(
                os.path.dirname(__file__), 'fixtures', 'userone',
                'userone_with_dot_name_fields.csv')) as f1:
            with storage.open(export.filepath) as f2:
                expected_content = f1.read()
                actual_content = f2.read()
                self.assertEquals(actual_content, expected_content) 
開發者ID:awemulya,項目名稱:kobo-predict,代碼行數:24,代碼來源:test_csv_export.py

示例4: get_media_file_response

# 需要導入模塊: from django.core.files import storage [as 別名]
# 或者: from django.core.files.storage import get_storage_class [as 別名]
def get_media_file_response(metadata):
    if metadata.data_file:
        file_path = metadata.data_file.name
        filename, extension = os.path.splitext(file_path.split('/')[-1])
        extension = extension.strip('.')
        dfs = get_storage_class()()

        if dfs.exists(file_path):
            response = response_with_mimetype_and_name(
                metadata.data_file_type,
                filename, extension=extension, show_date=False,
                file_path=file_path, full_mime=True)

            return response
        else:
            return HttpResponseNotFound()
    else:
        return HttpResponseRedirect(metadata.data_value) 
開發者ID:awemulya,項目名稱:kobo-predict,代碼行數:20,代碼來源:tools.py

示例5: test_graceful_exit_on_export_delete_if_file_doesnt_exist

# 需要導入模塊: from django.core.files import storage [as 別名]
# 或者: from django.core.files.storage import get_storage_class [as 別名]
def test_graceful_exit_on_export_delete_if_file_doesnt_exist(self):
        self._publish_transportation_form()
        self._submit_transport_instance()
        export = generate_export(Export.XLS_EXPORT, 'xls', self.user.username,
                                 self.xform.id_string)
        storage = get_storage_class()()
        # delete file
        storage.delete(export.filepath)
        self.assertFalse(storage.exists(export.filepath))
        # clear filename, like it would be in an incomplete export
        export.filename = None
        export.filedir = None
        export.save()
        # delete export record, which should try to delete file as well
        delete_url = reverse(delete_export, kwargs={
            'username': self.user.username,
            'id_string': self.xform.id_string,
            'export_type': 'xls'
        })
        post_data = {'export_id': export.id}
        response = self.client.post(delete_url, post_data)
        self.assertEqual(response.status_code, 302) 
開發者ID:awemulya,項目名稱:kobo-predict,代碼行數:24,代碼來源:test_exports.py

示例6: storage_factory

# 需要導入模塊: from django.core.files import storage [as 別名]
# 或者: from django.core.files.storage import get_storage_class [as 別名]
def storage_factory(collector):
    class DebugConfiguredStorage(LazyObject):
        def _setup(self):
            configured_storage_cls = get_storage_class(settings.STATICFILES_STORAGE)

            class DebugStaticFilesStorage(configured_storage_cls):

                def __init__(self, collector, *args, **kwargs):
                    super(DebugStaticFilesStorage, self).__init__(*args, **kwargs)
                    self.collector = collector

                def url(self, path):
                    self.collector.collect(path)
                    return super(DebugStaticFilesStorage, self).url(path)

            self._wrapped = DebugStaticFilesStorage(collector)
    return DebugConfiguredStorage 
開發者ID:skorokithakis,項目名稱:django-cloudflare-push,代碼行數:19,代碼來源:middleware.py

示例7: serve_document_from_s3

# 需要導入模塊: from django.core.files import storage [as 別名]
# 或者: from django.core.files.storage import get_storage_class [as 別名]
def serve_document_from_s3(document, request):
    # Skip this hook if not using django-storages boto3 backend.
    if not issubclass(get_storage_class(), S3Boto3Storage):
        return

    # Send document_served signal.
    document_served.send(sender=get_document_model(), instance=document,
                         request=request)

    # Get direct S3 link.
    file_url = document.file.url

    # Generate redirect response and add never_cache headers.
    response = redirect(file_url)
    del response['Cache-control']
    add_never_cache_headers(response)
    return response 
開發者ID:torchbox,項目名稱:wagtail-torchbox,代碼行數:19,代碼來源:wagtail_hooks.py

示例8: __init__

# 需要導入模塊: from django.core.files import storage [as 別名]
# 或者: from django.core.files.storage import get_storage_class [as 別名]
def __init__(self, storage_path=None, **options):
        """
        Initialize a Django Storage instance with given options.

        :param storage_path: Path to a Django Storage class with dot style
                             If ``None``, ``settings.DBBACKUP_STORAGE`` will
                             be used.
        :type storage_path: str
        """
        self._storage_path = storage_path or settings.STORAGE
        options = options.copy()
        options.update(settings.STORAGE_OPTIONS)
        options = dict([(key.lower(), value) for key, value in options.items()])
        self.storageCls = get_storage_class(self._storage_path)
        self.storage = self.storageCls(**options)
        self.name = self.storageCls.__name__ 
開發者ID:django-dbbackup,項目名稱:django-dbbackup,代碼行數:18,代碼來源:storage.py

示例9: handle

# 需要導入模塊: from django.core.files import storage [as 別名]
# 或者: from django.core.files.storage import get_storage_class [as 別名]
def handle(self, *args, **options):
        """Django command handler."""
        self.verbosity = int(options.get('verbosity'))
        self.quiet = options.get('quiet')
        self._set_logger_level()

        self.servername = options.get('servername')
        self.decrypt = options.get('decrypt')
        self.uncompress = options.get('uncompress')

        self.filename = options.get('input_filename')
        self.path = options.get('input_path')

        self.replace = options.get('replace')
        self.passphrase = options.get('passphrase')
        self.interactive = options.get('interactive')

        self.storage = get_storage()
        self.media_storage = get_storage_class()()
        self._restore_backup() 
開發者ID:django-dbbackup,項目名稱:django-dbbackup,代碼行數:22,代碼來源:mediarestore.py

示例10: handle

# 需要導入模塊: from django.core.files import storage [as 別名]
# 或者: from django.core.files.storage import get_storage_class [as 別名]
def handle(self, **options):
        self.verbosity = options.get('verbosity')
        self.quiet = options.get('quiet')
        self._set_logger_level()

        self.encrypt = options.get('encrypt', False)
        self.compress = options.get('compress', False)
        self.servername = options.get('servername')

        self.filename = options.get('output_filename')
        self.path = options.get('output_path')
        try:
            self.media_storage = get_storage_class()()
            self.storage = get_storage()
            self.backup_mediafiles()
            if options.get('clean'):
                self._cleanup_old_backups(servername=self.servername)

        except StorageError as err:
            raise CommandError(err) 
開發者ID:django-dbbackup,項目名稱:django-dbbackup,代碼行數:22,代碼來源:mediabackup.py

示例11: _setup

# 需要導入模塊: from django.core.files import storage [as 別名]
# 或者: from django.core.files.storage import get_storage_class [as 別名]
def _setup(self):
        self._wrapped = get_storage_class(settings.STATICFILES_STORAGE)() 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:4,代碼來源:storage.py

示例12: image_urls

# 需要導入模塊: from django.core.files import storage [as 別名]
# 或者: from django.core.files.storage import get_storage_class [as 別名]
def image_urls(instance):
    default_storage = get_storage_class()()
    urls = []
    suffix = settings.THUMB_CONF['medium']['suffix']
    for a in instance.attachments.all():
        if default_storage.exists(get_path(a.media_file.name, suffix)):
            url = default_storage.url(
                get_path(a.media_file.name, suffix))
        else:
            url = a.media_file.url
        urls.append(url)
    return urls 
開發者ID:awemulya,項目名稱:kobo-predict,代碼行數:14,代碼來源:viewer_tools.py

示例13: create_attachments_zipfile

# 需要導入模塊: from django.core.files import storage [as 別名]
# 或者: from django.core.files.storage import get_storage_class [as 別名]
def create_attachments_zipfile(attachments, temporary_file=None):
    if not temporary_file:
        temporary_file = NamedTemporaryFile()

    storage = get_storage_class()()
    with zipfile.ZipFile(temporary_file, 'w', zipfile.ZIP_STORED, allowZip64=True) as zip_file:
        for attachment in attachments:
            if storage.exists(attachment.media_file.name):
                try:
                    with storage.open(attachment.media_file.name, 'rb') as source_file:
                        zip_file.writestr(attachment.media_file.name, source_file.read())
                except Exception, e:
                    report_exception("Error adding file \"{}\" to archive.".format(attachment.media_file.name), e)

    # Be kind; rewind. 
開發者ID:awemulya,項目名稱:kobo-predict,代碼行數:17,代碼來源:viewer_tools.py

示例14: generate_attachments_zip_export

# 需要導入模塊: from django.core.files import storage [as 別名]
# 或者: from django.core.files.storage import get_storage_class [as 別名]
def generate_attachments_zip_export(
        export_type, extension, username, id_string, export_id=None,
        filter_query=None):
    xform = XForm.objects.get(user__username=username, id_string=id_string)
    attachments = Attachment.objects.filter(instance__xform=xform)
    basename = "%s_%s" % (id_string,
                          datetime.now().strftime("%Y_%m_%d_%H_%M_%S"))
    filename = basename + "." + extension
    file_path = os.path.join(
        username,
        'exports',
        id_string,
        export_type,
        filename)

    with NamedTemporaryFile('wb+', prefix='media_zip_export_', suffix='.zip') as temporary_file:
        create_attachments_zipfile(attachments, temporary_file=temporary_file)
        export_filename = get_storage_class()().save(
            file_path,
            File(temporary_file, file_path))

    dir_name, basename = os.path.split(export_filename)

    # get or create export object
    if(export_id):
        export = Export.objects.get(id=export_id)
    else:
        export = Export.objects.create(xform=xform, export_type=export_type)

    export.filedir = dir_name
    export.filename = basename
    export.internal_status = Export.SUCCESSFUL
    export.save()
    return export 
開發者ID:awemulya,項目名稱:kobo-predict,代碼行數:36,代碼來源:export_tools.py

示例15: generate_kml_export

# 需要導入模塊: from django.core.files import storage [as 別名]
# 或者: from django.core.files.storage import get_storage_class [as 別名]
def generate_kml_export(
        export_type, extension, username, id_string, export_id=None,
        filter_query=None):
    user = User.objects.get(username=username)
    xform = XForm.objects.get(user__username=username, id_string=id_string)
    response = render_to_response(
        'survey.kml', {'data': kml_export_data(id_string, user)})

    basename = "%s_%s" % (id_string,
                          datetime.now().strftime("%Y_%m_%d_%H_%M_%S"))
    filename = basename + "." + extension
    file_path = os.path.join(
        username,
        'exports',
        id_string,
        export_type,
        filename)

    storage = get_storage_class()()
    temp_file = NamedTemporaryFile(suffix=extension)
    temp_file.write(response.content)
    temp_file.seek(0)
    export_filename = storage.save(
        file_path,
        File(temp_file, file_path))
    temp_file.close()

    dir_name, basename = os.path.split(export_filename)

    # get or create export object
    if(export_id):
        export = Export.objects.get(id=export_id)
    else:
        export = Export.objects.create(xform=xform, export_type=export_type)

    export.filedir = dir_name
    export.filename = basename
    export.internal_status = Export.SUCCESSFUL
    export.save()

    return export 
開發者ID:awemulya,項目名稱:kobo-predict,代碼行數:43,代碼來源:export_tools.py


注:本文中的django.core.files.storage.get_storage_class方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。