当前位置: 首页>>代码示例>>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;未经允许,请勿转载。