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


Python forms.ClearableFileInput方法代码示例

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


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

示例1: render

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import ClearableFileInput [as 别名]
def render(self, name, value, attrs=None, renderer=None):
        name = str(name)
        substitutions = {
            'initial_text': self.initial_text,
            'input_text': self.input_text,
            'clear_template': '',
            'clear_checkbox_label': self.clear_checkbox_label,
        }
        template = '%(input)s'
        substitutions['input'] = super(forms.ClearableFileInput, self).render(name, value, attrs, renderer=renderer)

        if value and hasattr(value, "url"):
            template = self.template_with_initial
            substitutions['initial'] = ('<a href="%s">%s</a>'
                                        % (escape(value.file_sub.get_file_url()),
                                           escape(value.file_sub.display_filename())))
            if not self.is_required:
                checkbox_name = self.clear_checkbox_name(name)
                checkbox_id = self.clear_checkbox_id(checkbox_name)
                substitutions['clear_checkbox_name'] = escape(checkbox_name)
                substitutions['clear_checkbox_id'] = escape(checkbox_id)
                substitutions['clear'] = forms.CheckboxInput().render(checkbox_name, False, attrs={'id': checkbox_id})
                substitutions['clear_template'] = self.template_with_clear % substitutions

        return mark_safe(template % substitutions) 
开发者ID:sfu-fas,项目名称:coursys,代码行数:27,代码来源:other.py

示例2: get_field

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import ClearableFileInput [as 别名]
def get_field(param, initial=None):
        field = param.form_field
        choices = json.loads(param.choices)
        field_kwargs = {'label': param.script_param.title(),
                        'required': param.required,
                        'help_text': param.param_help,
                        }
        if choices:
            field = 'ChoiceField'
            base_choices = [(None, '----')] if not param.required else []
            field_kwargs['choices'] = base_choices+[(str(i), str(i).title()) for i in choices]
        if field == 'FileField':
            if param.is_output:
                field = 'CharField'
                initial = None
            else:
                if initial is not None:
                    initial = utils.get_storage_object(initial) if not hasattr(initial, 'path') else initial
                    field_kwargs['widget'] = forms.ClearableFileInput()
        if initial is not None:
            field_kwargs['initial'] = initial
        field = getattr(forms, field)
        return field(**field_kwargs) 
开发者ID:Chris7,项目名称:django-djangui,代码行数:25,代码来源:factory.py

示例3: test_accept

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import ClearableFileInput [as 别名]
def test_accept(self):
        widget = ClearableFileInput()
        assert 'accept' not in widget.render(name='file', value='test.jpg')
        assert ["starts-with", "$Content-Type", ""] in widget.get_conditions(None)

        widget = ClearableFileInput(attrs={'accept': 'image/*'})
        assert 'accept="image/*"' in widget.render(name='file', value='test.jpg')
        assert [
                   "starts-with", "$Content-Type", "image/"
               ] in widget.get_conditions('image/*')

        widget = ClearableFileInput(attrs={'accept': 'image/jpeg'})
        assert 'accept="image/jpeg"' in widget.render(name='file', value='test.jpg')
        assert {"Content-Type": 'image/jpeg'} in widget.get_conditions('image/jpeg')

        widget = ClearableFileInput(attrs={'accept': 'application/pdf,image/*'})
        assert 'accept="application/pdf,image/*"' in widget.render(
            name='file',
            value='test.jpg',
        )
        assert ["starts-with", "$Content-Type", ""] in widget.get_conditions(
            'application/pdf,image/*')
        assert {"Content-Type": 'application/pdf'} not in widget.get_conditions(
            'application/pdf,image/*') 
开发者ID:codingjoe,项目名称:django-s3file,代码行数:26,代码来源:test_forms.py

示例4: test_build_attr

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import ClearableFileInput [as 别名]
def test_build_attr(self):
        assert set(ClearableFileInput().build_attrs({}).keys()) == {
            'class',
            'data-url',
            'data-fields-x-amz-algorithm',
            'data-fields-x-amz-date',
            'data-fields-x-amz-signature',
            'data-fields-x-amz-credential',
            'data-fields-policy',
            'data-fields-key',
        }
        assert ClearableFileInput().build_attrs({})['class'] == 's3file'
        assert ClearableFileInput().build_attrs(
            {'class': 'my-class'})['class'] == 'my-class s3file' 
开发者ID:codingjoe,项目名称:django-s3file,代码行数:16,代码来源:test_forms.py

示例5: test_get_conditions

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import ClearableFileInput [as 别名]
def test_get_conditions(self, freeze):
        conditions = ClearableFileInput().get_conditions(None)
        assert all(condition in conditions for condition in [
            {"bucket": 'test-bucket'},
            {"success_action_status": "201"},
            ['starts-with', '$key', 'custom/location/tmp'],
            ["starts-with", "$Content-Type", ""]
        ]), conditions 
开发者ID:codingjoe,项目名称:django-s3file,代码行数:10,代码来源:test_forms.py

示例6: test_media

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import ClearableFileInput [as 别名]
def test_media(self):
        assert ClearableFileInput().media._js == ['s3file/js/s3file.js'] 
开发者ID:codingjoe,项目名称:django-s3file,代码行数:4,代码来源:test_forms.py

示例7: test_upload_folder

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import ClearableFileInput [as 别名]
def test_upload_folder(self):
        assert ClearableFileInput().upload_folder.startswith(
            'custom/location/tmp/s3file/'
        )
        assert len(ClearableFileInput().upload_folder) == 49 
开发者ID:codingjoe,项目名称:django-s3file,代码行数:7,代码来源:test_forms.py

示例8: is_file

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import ClearableFileInput [as 别名]
def is_file(field):
    return isinstance(field.field.widget, forms.ClearableFileInput) 
开发者ID:mishbahr,项目名称:djangocms-forms,代码行数:4,代码来源:djangocms_forms_tags.py

示例9: prepare_file

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import ClearableFileInput [as 别名]
def prepare_file(self, field):
        field_attrs = field.build_field_attrs()
        widget_attrs = field.build_widget_attrs()

        field_attrs.update({
            'widget': forms.ClearableFileInput(attrs=widget_attrs)
        })

        if field.choice_values:
            regex = re.compile('[\s]*\n[\s]*')
            choices = regex.split(field.choice_values)
            field_attrs.update({
                'allowed_file_types': [i.lstrip('.').lower() for i in choices]
            })
        return FormBuilderFileField(**field_attrs) 
开发者ID:mishbahr,项目名称:djangocms-forms,代码行数:17,代码来源:forms.py


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