當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。