Python django.forms.BaseForm() Examples
The following are 17
code examples of django.forms.BaseForm().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
django.forms
, or try the search function
.
Example #1
Source File: filter.py From django-admin-rangefilter with MIT License | 6 votes |
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
Example #2
Source File: wizard.py From ImitationTmall_Django with GNU General Public License v3.0 | 6 votes |
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
Example #3
Source File: wizard.py From Dailyfresh-B2C with Apache License 2.0 | 6 votes |
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
Example #4
Source File: wizard.py From online with GNU Affero General Public License v3.0 | 6 votes |
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
Example #5
Source File: wizard.py From devops with MIT License | 6 votes |
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
Example #6
Source File: wizard.py From imoocc with GNU General Public License v2.0 | 6 votes |
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
Example #7
Source File: wizard.py From Mxonline3 with Apache License 2.0 | 6 votes |
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
Example #8
Source File: wizard.py From django_OA with GNU General Public License v3.0 | 6 votes |
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
Example #9
Source File: wizard.py From CTF_AWD_Platform with MIT License | 6 votes |
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
Example #10
Source File: wizard.py From myblog with GNU Affero General Public License v3.0 | 6 votes |
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
Example #11
Source File: wizard.py From weibo-analysis-system with MIT License | 6 votes |
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
Example #12
Source File: wizard.py From StormOnline with Apache License 2.0 | 6 votes |
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
Example #13
Source File: export_form.py From website with GNU General Public License v3.0 | 5 votes |
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)
Example #14
Source File: views.py From connect with MIT License | 5 votes |
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))
Example #15
Source File: views.py From connect with MIT License | 5 votes |
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)
Example #16
Source File: bootstrap_toolkit.py From yats with MIT License | 5 votes |
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
Example #17
Source File: djangoforms.py From python-compat-runtime with Apache License 2.0 | 4 votes |
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)