当前位置: 首页>>代码示例>>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;未经允许,请勿转载。