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


Python forms.BaseForm方法代碼示例

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


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

示例1: get_step_form

# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import BaseForm [as 別名]
def get_step_form(self, step=None):
        if step is None:
            step = self.steps.current
        attrs = self.get_form_list()[step]
        if type(attrs) in (list, tuple):
            return modelform_factory(self.model, form=forms.ModelForm,
                                     fields=attrs, formfield_callback=self.admin_view.formfield_for_dbfield)
        elif type(attrs) is dict:
            if attrs.get('fields', None):
                return modelform_factory(self.model, form=forms.ModelForm,
                                         fields=attrs['fields'], formfield_callback=self.admin_view.formfield_for_dbfield)
            if attrs.get('callback', None):
                callback = attrs['callback']
                if callable(callback):
                    return callback(self)
                elif hasattr(self.admin_view, str(callback)):
                    return getattr(self.admin_view, str(callback))(self)
        elif issubclass(attrs, forms.BaseForm):
            return attrs
        return None 
開發者ID:stormsha,項目名稱:StormOnline,代碼行數:22,代碼來源:wizard.py

示例2: _get_form_class

# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import BaseForm [as 別名]
def _get_form_class(self):
        fields = self._get_form_fields()

        form_class = type(
            str('DateRangeForm'),
            (forms.BaseForm,),
            {'base_fields': fields}
        )
        form_class.media = self._get_media()
        # lines below ensure that the js static files are loaded just once
        # even if there is more than one DateRangeFilter in use
        request_key = 'DJANGO_RANGEFILTER_ADMIN_JS_SET'
        if (getattr(self.request, request_key, False)):
            form_class.js = []
        else:
            setattr(self.request, request_key, True)
            form_class.js = self.get_js()
        return form_class 
開發者ID:silentsokolov,項目名稱:django-admin-rangefilter,代碼行數:20,代碼來源:filter.py

示例3: go

# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import BaseForm [as 別名]
def go(self, obj):
        if isinstance(obj, str):
            self.stdout.write('<h1>{}</h1>'.format(obj))

        elif isinstance(obj, BaseFormSet):
            self.stdout.write('<ol>')
            for idx, form in enumerate(obj, 1):
                self.stdout.write('<li>')
                self.stdout.write(form.as_p())
                self.stdout.write('</li>')
            self.stdout.write('</ol>')

        elif isinstance(obj, BaseForm):
            self.stdout.write(obj.as_p())

        elif callable(obj):
            self.go(obj())

        else:
            try:
                children = iter(obj)
            except TypeError:
                self.stdout.write("<p><code>{!r}</code></p>".format(obj))

            else:
                for child in children:
                    self.go(child) 
開發者ID:outreachy,項目名稱:website,代碼行數:29,代碼來源:export_form.py

示例4: get

# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import BaseForm [as 別名]
def get(self, request, *args, **kwargs):
        """Process a get request."""
        form_classes = self.get_form_classes()
        forms = self.get_forms(form_classes)
        kwargs = forms
        kwargs['forms'] = [
            form_class for form_class in forms.itervalues()
            if isinstance(form_class, BaseForm)
        ]
        return self.render_to_response(self.get_context_data(**kwargs)) 
開發者ID:ofa,項目名稱:connect,代碼行數:12,代碼來源:views.py

示例5: render_invalid_response

# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import BaseForm [as 別名]
def render_invalid_response(self, forms):
        """Renders a response if forms don't validate."""
        kwargs = forms
        kwargs['forms'] = [
            form_class for form_class in forms.itervalues()
            if isinstance(form_class, BaseForm)
        ]
        kwargs['form_errors'] = True
        return self.form_invalid(kwargs) 
開發者ID:ofa,項目名稱:connect,代碼行數:11,代碼來源:views.py

示例6: as_bootstrap

# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import BaseForm [as 別名]
def as_bootstrap(form_or_field, layout='vertical,false'):
    """
    Render a field or a form according to Bootstrap guidelines
    """
    params = split(layout, ",")
    layout = str(params[0]).lower()

    try:
        bootstrap_float = str(params[1]).lower() == "float"
    except IndexError:
        bootstrap_float = False

    if isinstance(form_or_field, BaseForm):
        return render_to_string("bootstrap_toolkit/form.html", context={
                'form': form_or_field,
                'layout': layout,
                'float': bootstrap_float,
            }
        )
    elif isinstance(form_or_field, BoundField):
        return render_to_string("bootstrap_toolkit/field.html", context={
                'field': form_or_field,
                'layout': layout,
                'float': bootstrap_float,
            }
        )
    else:
        # Display the default
        return settings.TEMPLATE_STRING_IF_INVALID 
開發者ID:mediafactory,項目名稱:yats,代碼行數:31,代碼來源:bootstrap_toolkit.py

示例7: __init__

# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import BaseForm [as 別名]
def __init__(self, data=None, files=None, auto_id=None, prefix=None,
               initial=None, error_class=None, label_suffix=None,
               instance=None):
    """Constructor.

    Args (all optional and defaulting to None):
      data: dict of data values, typically from a POST request)
      files: dict of file upload values; Django 0.97 or later only
      auto_id, prefix: see Django documentation
      initial: dict of initial values
      error_class, label_suffix: see Django 0.97 or later documentation
      instance: Model instance to be used for additional initial values

    Except for initial and instance, these arguments are passed on to
    the forms.BaseForm constructor unchanged, but only if not None.
    Some arguments (files, error_class, label_suffix) are only
    supported by Django 0.97 or later.  Leave these blank (i.e. None)
    when using Django 0.96.  Their default values will be used with
    Django 0.97 or later even when they are explicitly set to None.
    """
    opts = self._meta
    self.instance = instance
    object_data = {}
    if instance is not None:
      for name, prop in instance.properties().iteritems():
        if opts.fields and name not in opts.fields:
          continue
        if opts.exclude and name in opts.exclude:
          continue
        object_data[name] = prop.get_value_for_form(instance)
    if initial is not None:

      object_data.update(initial)




    kwargs = dict(data=data, files=files, auto_id=auto_id,
                  prefix=prefix, initial=object_data,
                  error_class=error_class, label_suffix=label_suffix)
    kwargs = dict((name, value)
                  for name, value in kwargs.iteritems()
                  if value is not None)
    super(BaseModelForm, self).__init__(**kwargs) 
開發者ID:GoogleCloudPlatform,項目名稱:python-compat-runtime,代碼行數:46,代碼來源:djangoforms.py


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