当前位置: 首页>>代码示例>>Python>>正文


Python default_storage.save方法代码示例

本文整理汇总了Python中django.core.files.storage.default_storage.save方法的典型用法代码示例。如果您正苦于以下问题:Python default_storage.save方法的具体用法?Python default_storage.save怎么用?Python default_storage.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在django.core.files.storage.default_storage的用法示例。


在下文中一共展示了default_storage.save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: download_media_files

# 需要导入模块: from django.core.files.storage import default_storage [as 别名]
# 或者: from django.core.files.storage.default_storage import save [as 别名]
def download_media_files(self, xml_doc, media_path):
        for media_node in xml_doc.getElementsByTagName('mediaFile'):
            filename_node = media_node.getElementsByTagName('filename')
            url_node = media_node.getElementsByTagName('downloadUrl')
            if filename_node and url_node:
                filename = filename_node[0].childNodes[0].nodeValue
                path = os.path.join(media_path, filename)
                if default_storage.exists(path):
                    continue
                download_url = url_node[0].childNodes[0].nodeValue
                if self._get_media_response(download_url):
                    download_res = self._current_response
                    media_content = ContentFile(download_res.content)
                    default_storage.save(path, media_content)
                    self.logger.debug("Fetched %s." % filename)
                else:
                    self.logger.error("Failed to fetch %s." % filename) 
开发者ID:awemulya,项目名称:kobo-predict,代码行数:19,代码来源:briefcase_client.py

示例2: profile_settings

# 需要导入模块: from django.core.files.storage import default_storage [as 别名]
# 或者: from django.core.files.storage.default_storage import save [as 别名]
def profile_settings(request, username):
    content_user = check_and_set_user(request, username)
    profile, created = UserProfile.objects.get_or_create(user=content_user)
    if request.method == 'POST':
        form = UserProfileForm(request.POST, instance=profile)
        if form.is_valid():
            # get user
            # user.email = cleaned_email
            form.instance.user.email = form.cleaned_data['email']
            form.instance.user.save()
            form.save()
            # todo: add string rep. of settings to see what changed
            audit = {}
            audit_log(
                Actions.PROFILE_SETTINGS_UPDATED, request.user, content_user,
                _("Profile settings updated."), audit, request)
            return HttpResponseRedirect(reverse(
                public_profile, kwargs={'username': request.user.username}
            ))
    else:
        form = UserProfileForm(
            instance=profile, initial={"email": content_user.email})

    return render(request, "settings.html",
                  {'content_user': content_user, 'form': form}) 
开发者ID:awemulya,项目名称:kobo-predict,代码行数:27,代码来源:views.py

示例3: create_from_as2mdn

# 需要导入模块: from django.core.files.storage import default_storage [as 别名]
# 或者: from django.core.files.storage.default_storage import save [as 别名]
def create_from_as2mdn(self, as2mdn, message, status, return_url=None):
        """Create the MDN from the pyas2lib's MDN object"""
        signed = True if as2mdn.digest_alg else False
        mdn, _ = self.update_or_create(
            message=message,
            defaults=dict(
                mdn_id=as2mdn.message_id,
                status=status,
                signed=signed,
                return_url=return_url,
            ),
        )
        filename = f"{uuid4()}.mdn"
        mdn.headers.save(
            name=f"{filename}.header", content=ContentFile(as2mdn.headers_str)
        )
        mdn.payload.save(filename, content=ContentFile(as2mdn.content))
        return mdn 
开发者ID:abhishek-ram,项目名称:django-pyas2,代码行数:20,代码来源:models.py

示例4: send_async_mdn

# 需要导入模块: from django.core.files.storage import default_storage [as 别名]
# 或者: from django.core.files.storage.default_storage import save [as 别名]
def send_async_mdn(self):
        """ Send the asynchronous MDN to the partner"""

        # convert the mdn headers to dictionary
        headers = HeaderParser().parsestr(self.headers.read().decode())

        # Send the mdn to the partner
        try:
            response = requests.post(
                self.return_url, headers=dict(headers.items()), data=self.payload.read()
            )
            response.raise_for_status()
        except requests.exceptions.RequestException:
            return

        # Update the status of the MDN
        self.status = "S"
        self.save() 
开发者ID:abhishek-ram,项目名称:django-pyas2,代码行数:20,代码来源:models.py

示例5: handle

# 需要导入模块: from django.core.files.storage import default_storage [as 别名]
# 或者: from django.core.files.storage.default_storage import save [as 别名]
def handle(self, *args, **options):
        script = options.get('script')
        if not script:
            if len(args):
                 script = args[0]
            else:
                raise CommandError('You must provide a script path or directory containing scripts.')
        if not os.path.exists(script):
            raise CommandError('{0} does not exist.'.format(script))
        group = options.get('group', 'Djangui Scripts')
        scripts = [os.path.join(script, i) for i in os.listdir(script)] if os.path.isdir(script) else [script]
        converted = 0
        for script in scripts:
            if script.endswith('.pyc') or '__init__' in script:
                continue
            if script.endswith('.py'):
                sys.stdout.write('Converting {}\n'.format(script))
                # copy the script to our storage
                with open(script, 'r') as f:
                    script = default_storage.save(os.path.join(djangui_settings.DJANGUI_SCRIPT_DIR, os.path.split(script)[1]), File(f))
                added, error = add_djangui_script(script=os.path.abspath(os.path.join(settings.MEDIA_ROOT, script)), group=group)
                if added:
                    converted += 1
        sys.stdout.write('Converted {} scripts\n'.format(converted)) 
开发者ID:Chris7,项目名称:django-djangui,代码行数:26,代码来源:addscript.py

示例6: test_open_read

# 需要导入模块: from django.core.files.storage import default_storage [as 别名]
# 或者: from django.core.files.storage.default_storage import save [as 别名]
def test_open_read(self):
        self.storage.location = 'root'
        stream = io.BytesIO(b'Im a stream')
        name = self.storage.save('path/some file.txt', stream)
        fh = self.storage.open(name, 'r+b')
        try:
            self.assertEqual(fh.read(), b'Im a stream')
        finally:
            fh.close()

        stream = io.BytesIO()
        self.storage.service.get_blob_to_stream(
            container_name=self.storage.azure_container,
            blob_name='root/path/some file.txt',
            stream=stream,
            max_connections=1,
            timeout=10)
        stream.seek(0)
        self.assertEqual(stream.read(), b'Im a stream') 
开发者ID:jschneier,项目名称:django-storages,代码行数:21,代码来源:test_azure.py

示例7: test_open_read_write

# 需要导入模块: from django.core.files.storage import default_storage [as 别名]
# 或者: from django.core.files.storage.default_storage import save [as 别名]
def test_open_read_write(self):
        self.storage.location = 'root'
        stream = io.BytesIO(b'Im a stream')
        name = self.storage.save('file.txt', stream)
        fh = self.storage.open(name, 'r+b')
        try:
            self.assertEqual(fh.read(), b'Im a stream')
            fh.write(b' foo')
            fh.seek(0)
            self.assertEqual(fh.read(), b'Im a stream foo')
        finally:
            fh.close()

        stream = io.BytesIO()
        self.storage.service.get_blob_to_stream(
            container_name=self.storage.azure_container,
            blob_name='root/file.txt',
            stream=stream,
            max_connections=1,
            timeout=10)
        stream.seek(0)
        self.assertEqual(stream.read(), b'Im a stream foo') 
开发者ID:jschneier,项目名称:django-storages,代码行数:24,代码来源:test_azure.py

示例8: test_model_form

# 需要导入模块: from django.core.files.storage import default_storage [as 别名]
# 或者: from django.core.files.storage.default_storage import save [as 别名]
def test_model_form(self):
        files = {
            'foo_file': SimpleUploadedFile(
                name='foo.pdf',
                content=b'foo content',
                content_type='application/pdf')}
        form = FooFileModelForm(data={}, files=files)
        self.assertTrue(form.is_valid())
        form.save()
        self.assertTrue(default_storage.exists('foo_uploads/foo.pdf'))

        # check file content was saved
        fh = default_storage.open('foo_uploads/foo.pdf', 'r+b')
        try:
            self.assertEqual(fh.read(), b'foo content')
        finally:
            fh.close() 
开发者ID:jschneier,项目名称:django-storages,代码行数:19,代码来源:test_azure.py

示例9: add_dataset

# 需要导入模块: from django.core.files.storage import default_storage [as 别名]
# 或者: from django.core.files.storage.default_storage import save [as 别名]
def add_dataset(request):
    daterange = ""
    dataset = Dataset(author=request.user, index=request.POST['index'],
                      mapping=request.POST['mapping'], daterange=daterange, access=(request.POST['access']))
    dataset.save()

    create_dataset_access_permission_and_propagate(dataset, request.POST['access'])
    indices = ES_Manager.get_indices()
    ds_out = dataset.__dict__
    for index in indices:
        if index['index'] == ds_out['index']:
            ds_out['status'] = index['status']
            ds_out['docs_count'] = index['docs_count']
            ds_out['store_size'] = index['store_size']
            break
        elif '*' in ds_out['index']:
            ds_out['status'] = 'open'
            ds_out['docs_count'] = 'multiindex'
            ds_out['store_size'] = 'multiindex'
    ds_out['_state'] = ''
    ds_out['author'] = request.user.get_username()
    return JsonResponse(ds_out) 
开发者ID:texta-tk,项目名称:texta,代码行数:24,代码来源:views.py

示例10: silence_streams

# 需要导入模块: from django.core.files.storage import default_storage [as 别名]
# 或者: from django.core.files.storage.default_storage import save [as 别名]
def silence_streams(func):
        def wrapper(*args, **kwargs):
            # save stderr
            save_streams = sys.__stderr__
            save_streams.flush()
            # file descriptor for stderr is 2
            save_stderr = os.dup(2)
            # silence
            null_fd = os.open(os.devnull, os.O_RDWR)
            os.dup2(null_fd, 2)
            # uncomment the line to test if stderr is silenced
            # 1/0
            try:
                bak_file_path = func(*args, **kwargs)
                sys.stderr = save_streams
                os.dup2(save_stderr, 2)
                return bak_file_path
            except:
                sys.stderr = save_streams
                os.dup2(save_stderr, 2)
        return wrapper 
开发者ID:Contrast-Security-OSS,项目名称:DjanGoat,代码行数:23,代码来源:benefits.py

示例11: download_xforms

# 需要导入模块: from django.core.files.storage import default_storage [as 别名]
# 或者: from django.core.files.storage.default_storage import save [as 别名]
def download_xforms(self, include_instances=False):
        # fetch formList
        if not self._get_response(self.form_list_url):
            response = self._current_response.content \
                if self._current_response else "Unknown Error"
            self.logger.error("Failed to download xforms %s." % response)

            return

        response = self._current_response
        forms = self._get_form_list(response.content)

        self.logger.debug('Successfull fetched %s.' % self.form_list_url)

        for id_string, download_url, manifest_url in forms:
            form_path = os.path.join(
                self.forms_path, id_string, '%s.xml' % id_string)

            if not default_storage.exists(form_path):
                if not self._get_response(download_url):
                    self.logger.error("Failed to download xform %s."
                                      % download_url)
                    continue

                form_res = self._current_response
                content = ContentFile(form_res.content.strip())
                default_storage.save(form_path, content)
            else:
                form_res = default_storage.open(form_path)
                content = form_res.read()

            self.logger.debug("Fetched %s." % download_url)

            self.download_manifest(manifest_url, id_string)

            if include_instances:
                self.download_instances(id_string)
                self.logger.debug("Done downloading submissions for %s" %
                                  id_string) 
开发者ID:awemulya,项目名称:kobo-predict,代码行数:41,代码来源:briefcase_client.py

示例12: save

# 需要导入模块: from django.core.files.storage import default_storage [as 别名]
# 或者: from django.core.files.storage.default_storage import save [as 别名]
def save(self, **kwargs):
        user = User.objects.get(username=self.username)
        xls_file_path = upload_to(None, '%s%s.xls' % (
                                  self.xform.id_string,
                                  XForm.CLONED_SUFFIX),
                                  self.username)
        xls_data = default_storage.open(self.xform.xls.name)
        xls_file = default_storage.save(xls_file_path, xls_data)
        self.cloned_form = DataDictionary.objects.create(
            user=user,
            xls=xls_file
        ) 
开发者ID:awemulya,项目名称:kobo-predict,代码行数:14,代码来源:clone_xform.py

示例13: save

# 需要导入模块: from django.core.files.storage import default_storage [as 别名]
# 或者: from django.core.files.storage.default_storage import save [as 别名]
def save(self, new_user):
        new_profile = \
            UserProfile(user=new_user, name=self.cleaned_data['name'],
                        city=self.cleaned_data['city'],
                        country=self.cleaned_data['country'],
                        organization=self.cleaned_data['organization'],
                        home_page=self.cleaned_data['home_page'],
                        twitter=self.cleaned_data['twitter'])
        new_profile.save()
        return new_profile


# order of inheritance control order of form display 
开发者ID:awemulya,项目名称:kobo-predict,代码行数:15,代码来源:forms.py

示例14: update_status

# 需要导入模块: from django.core.files.storage import default_storage [as 别名]
# 或者: from django.core.files.storage.default_storage import save [as 别名]
def update_status(self):
        try:
            status = self.site_instances.order_by('-date').first().form_status
            print status, identifier

        except:
            status = 0
        self.current_status = status
        self.save() 
开发者ID:awemulya,项目名称:kobo-predict,代码行数:11,代码来源:models.py

示例15: update_current_progress

# 需要导入模块: from django.core.files.storage import default_storage [as 别名]
# 或者: from django.core.files.storage.default_storage import save [as 别名]
def update_current_progress(self):
        self.current_progress = self.progress()
        try:
            status = self.site_instances.order_by('-date').first().form_status
        except:
            status = 0
        self.current_status = status
        self.save() 
开发者ID:awemulya,项目名称:kobo-predict,代码行数:10,代码来源:models.py


注:本文中的django.core.files.storage.default_storage.save方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。