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


Python widgets.ClearableFileInput方法代碼示例

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


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

示例1: render

# 需要導入模塊: from django.forms import widgets [as 別名]
# 或者: from django.forms.widgets import ClearableFileInput [as 別名]
def render(self, name, value, attrs=None,):

        substitutions = {
            'clear_checkbox_label': self.clear_checkbox_label,
            'initial' : '<img class="img-responsive img-thumbnail" width="%s" src="%s">' % (
                force_text('100%'),
                force_text(get_thumbnailer(value)['medium'].url if value and hasattr(value, 'url') else static('images/placeholder.svg'))
            )
        }
        template = '%(initial)s%(input)s'

        substitutions['input'] = super(ClearableFileInput, self).render(name, value, attrs)

        if not self.is_required:
            template = '%(initial)s%(clear_template)s%(input)s'
            checkbox_name = self.clear_checkbox_name(name)
            checkbox_id = self.clear_checkbox_id(checkbox_name)
            substitutions['clear_checkbox_name'] = conditional_escape(checkbox_name)
            substitutions['clear_checkbox_id'] = conditional_escape(checkbox_id)
            substitutions['clear'] = CheckboxInput().render(checkbox_name, False, attrs={'id': checkbox_id})
            substitutions['clear_template'] = self.clear_checkbox_name(checkbox_name)

        return mark_safe(template % substitutions) 
開發者ID:freedomvote,項目名稱:freedomvote,代碼行數:25,代碼來源:widgets.py

示例2: get_context

# 需要導入模塊: from django.forms import widgets [as 別名]
# 或者: from django.forms.widgets import ClearableFileInput [as 別名]
def get_context(self, name, value, attrs):
        """Get the context to render this widget with."""
        if self.has_template_widget_rendering:
            context = super(ClearableFileInputWithImagePreview, self).get_context(name, value, attrs)
        else:
            # Build the context manually.
            context = {}
            context['widget'] = {
                'name': name,
                'is_hidden': self.is_hidden,
                'required': self.is_required,
                'value': self._format_value(value),
                'attrs': self.build_attrs(self.attrs, attrs),
                'template_name': self.template_name,
                'type': self.input_type,
            }

        # It seems Django 1.11's ClearableFileInput doesn't add everything to the 'widget' key, so we can't use it
        # in MultiWidget. Add it manually here.
        checkbox_name = self.clear_checkbox_name(name)
        checkbox_id = self.clear_checkbox_id(checkbox_name)

        context['widget'].update({
            'checkbox_name': checkbox_name,
            'checkbox_id': checkbox_id,
            'is_initial': self.is_initial(value),
            'input_text': self.input_text,
            'initial_text': self.initial_text,
            'clear_checkbox_label': self.clear_checkbox_label,
        })

        if value and hasattr(value, "url"):
            context['widget'].update({
                'hidden_field_id': self.get_hidden_field_id(name),
                'point_stage_id': self.get_point_stage_id(name),
                'ppoi_id': self.get_ppoi_id(name),
                'sized_url': self.get_sized_url(value),
                'image_preview_id': self.image_preview_id(name),
            })

        return context 
開發者ID:respondcreate,項目名稱:django-versatileimagefield,代碼行數:43,代碼來源:widgets.py

示例3: __init__

# 需要導入模塊: from django.forms import widgets [as 別名]
# 或者: from django.forms.widgets import ClearableFileInput [as 別名]
def __init__(self, widgets=None, attrs=None):
        widgets = [
            ClearableFileInput(attrs=None),
            Select(attrs=attrs, choices=CENTERPOINT_CHOICES)
        ]
        super(VersatileImagePPOISelectWidget, self).__init__(widgets, attrs) 
開發者ID:respondcreate,項目名稱:django-versatileimagefield,代碼行數:8,代碼來源:widgets.py

示例4: value_from_datadict

# 需要導入模塊: from django.forms import widgets [as 別名]
# 或者: from django.forms.widgets import ClearableFileInput [as 別名]
def value_from_datadict(self, data, files, name):
        """
        Modify value_from_datadict, so that delete takes precedence over
        upload.
        """
        file_value = super(widgets.ClearableFileInput, self)\
            .value_from_datadict(data, files, name)
        checkbox_value = widgets.CheckboxInput()\
            .value_from_datadict(data, files, self.clear_checkbox_name(name))
        if not self.is_required and checkbox_value:
            return False
        return file_value 
開發者ID:liqd,項目名稱:adhocracy4,代碼行數:14,代碼來源:widgets.py

示例5: __init__

# 需要導入模塊: from django.forms import widgets [as 別名]
# 或者: from django.forms.widgets import ClearableFileInput [as 別名]
def __init__(self, *args, **kwargs):
      super(ClearableFileInput, self).__init__(*args, **kwargs)

      self.template_name = "core/custom_file_input.html" 
開發者ID:freedomvote,項目名稱:freedomvote,代碼行數:6,代碼來源:widgets.py


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