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


Python forms.Widget方法代碼示例

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


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

示例1: formfield_for_dbfield

# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import Widget [as 別名]
def formfield_for_dbfield(self, db_field, **kwargs):
        if db_field.name == 'widget_type':
            widgets = widget_manager.get_widgets(self.request.GET.get('page_id', ''))
            form_widget = WidgetTypeSelect(widgets)
            return forms.ChoiceField(choices=[(w.widget_type, w.description) for w in widgets],
                                     widget=form_widget, label=_('Widget Type'))
        if 'page_id' in self.request.GET and db_field.name == 'page_id':
            kwargs['widget'] = forms.HiddenInput
        field = super(
            UserWidgetAdmin, self).formfield_for_dbfield(db_field, **kwargs)
        return field 
開發者ID:stormsha,項目名稱:StormOnline,代碼行數:13,代碼來源:dashboard.py

示例2: obj_as_dict

# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import Widget [as 別名]
def obj_as_dict(o):

    if isinstance(o, DeclarativeFieldsMetaclass):
        o = FormSerializer(form=o).data

    if isinstance(o, forms.Field):
        o = FormFieldSerializer(field=o).data

    if isinstance(o, forms.Widget):
        o = FormWidgetSerializer(widget=o).data

    if isinstance(o, (list, tuple)):
        o = [obj_as_dict(x) for x in o]

    if isinstance(o, Promise):
        try:
            o = force_unicode(o)
        except:
            # Item could be a lazy tuple or list
            try:
                o = [obj_as_dict(x) for x in o]
            except:
                raise Exception('Unable to resolve lazy object %s' % o)
    if callable(o):
        o = o()

    if isinstance(o, dict):
        for k, v in o.items():
            o[k] = obj_as_dict(v)

    return o 
開發者ID:erdem,項目名稱:django-admino,代碼行數:33,代碼來源:serializers.py

示例3: test_decimalfield_widget_attrs

# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import Widget [as 別名]
def test_decimalfield_widget_attrs(self):
        f = DecimalField(max_digits=6, decimal_places=2)
        self.assertEqual(f.widget_attrs(Widget()), {})
        self.assertEqual(f.widget_attrs(NumberInput()), {'step': '0.01'})
        f = DecimalField(max_digits=10, decimal_places=0)
        self.assertEqual(f.widget_attrs(NumberInput()), {'step': '1'})
        f = DecimalField(max_digits=19, decimal_places=19)
        self.assertEqual(f.widget_attrs(NumberInput()), {'step': '1e-19'})
        f = DecimalField(max_digits=20)
        self.assertEqual(f.widget_attrs(NumberInput()), {'step': 'any'})
        f = DecimalField(max_digits=6, widget=NumberInput(attrs={'step': '0.01'}))
        self.assertWidgetRendersTo(f, '<input step="0.01" name="f" type="number" id="id_f" required>') 
開發者ID:nesdis,項目名稱:djongo,代碼行數:14,代碼來源:test_decimalfield.py

示例4: test_format_value

# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import Widget [as 別名]
def test_format_value(self):
        widget = Widget()
        self.assertIsNone(widget.format_value(None))
        self.assertIsNone(widget.format_value(''))
        self.assertEqual(widget.format_value('español'), 'español')
        self.assertEqual(widget.format_value(42.5), '42.5') 
開發者ID:nesdis,項目名稱:djongo,代碼行數:8,代碼來源:test_widget.py

示例5: test_value_omitted_from_data

# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import Widget [as 別名]
def test_value_omitted_from_data(self):
        widget = Widget()
        self.assertIs(widget.value_omitted_from_data({}, {}, 'field'), True)
        self.assertIs(widget.value_omitted_from_data({'field': 'value'}, {}, 'field'), False) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:6,代碼來源:test_widget.py


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