telemeta.forms.media module
# -*- coding: utf-8 -*- # Copyright (C) 2011-2014 Parisson SARL # This file is part of Telemeta. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Affero General Public License for more details. # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. # # Authors: Guillaume Pellerin <yomguy@parisson.com> import django.forms as forms from django.forms import ModelForm from django.contrib.admin.widgets import FilteredSelectMultiple from telemeta.models import * from extra_views import CreateWithInlinesView, UpdateWithInlinesView, InlineFormSet from extra_views.generic import GenericInlineFormSet from django.forms.widgets import HiddenInput from django.utils.translation import ugettext_lazy as _ class MediaFondsForm(ModelForm): queryset = MediaCorpus.objects.all() widget = FilteredSelectMultiple("Corpus", is_stacked=False) children = forms.ModelMultipleChoiceField(widget=widget, queryset=queryset, label='Corpus', required=False) class Meta: model = MediaFonds exclude = ['description', 'public_access'] class Media: css = {'all': ['/static/admin/css/widgets.css',],} js = ['/admin/django/jsi18n/',] class MediaCorpusForm(ModelForm): queryset = MediaCollection.objects.all() widget = FilteredSelectMultiple('Collections', is_stacked=False) children = forms.ModelMultipleChoiceField(widget=widget, queryset=queryset, label='Collections', required=False) class Meta: model = MediaCorpus exclude = ['description', 'public_access'] class Media: css = {'all': ('/static/admin/css/widgets.css',),} js = ('/admin/django/jsi18n/',) class MediaCollectionForm(ModelForm): def __init__(self, *args, **kwargs): super(MediaCollectionForm, self).__init__(*args, **kwargs) if '_I_' in self.instance.code: self.fields["reference"].widget = HiddenInput() if self.instance.computed_duration: self.fields["approx_duration"].widget = HiddenInput() class Meta: model = MediaCollection exclude = model.exclude def clean_doctype_code(self): return self.cleaned_data['doctype_code'] or 0 class MediaItemForm(ModelForm): class Meta: model = MediaItem exclude = model.exclude def clean_code(self): return self.cleaned_data['code'] or None class RestrictedMediaItemForm(MediaItemForm): class Meta: model = MediaItem exclude = model.restricted class PlaylistForm(ModelForm): class Meta: model = Playlist class FondsRelatedInline(InlineFormSet): model = MediaFondsRelated exclude = ['mime_type'] class CorpusRelatedInline(InlineFormSet): model = MediaCorpusRelated exclude = ['mime_type'] class CollectionRelatedInline(InlineFormSet): model = MediaCollectionRelated exclude = ['mime_type'] class ItemRelatedInline(InlineFormSet): model = MediaItemRelated exclude = ['mime_type'] class CollectionIdentifierInline(InlineFormSet): model = MediaCollectionIdentifier max_num = 1 class ItemPerformanceInline(InlineFormSet): model = MediaItemPerformance class ItemKeywordInline(InlineFormSet): model = MediaItemKeyword class ItemFormatInline(InlineFormSet): model = Format max_num = 1 class ItemIdentifierInline(InlineFormSet): model = MediaItemIdentifier max_num = 1 class EpubPasswordForm(forms.Form): password = forms.CharField(label=_('password'))
Module variables
var ITEM_PUBLIC_ACCESS_CHOICES
var ITEM_TRANSODING_STATUS
var PUBLIC_ACCESS_CHOICES
var SCOPE_CHOICES
var TYPE_CHOICES
var app_name
var code_linesep
var collection_code_regex
var collection_published_code_regex
var collection_unpublished_code_regex
var default_decoding
var default_encoding
var engine
var eol
var ext
var item_code_regex
var item_published_code_regex
var item_unpublished_code_regex
var mime_type
var private_extra_types
var public_extra_types
var resource_code_regex
var strict_code
Classes
class CollectionIdentifierInline
class CollectionIdentifierInline(InlineFormSet): model = MediaCollectionIdentifier max_num = 1
Ancestors (in MRO)
- CollectionIdentifierInline
- extra_views.advanced.InlineFormSet
- extra_views.formsets.BaseInlineFormSetMixin
- extra_views.formsets.BaseFormSetMixin
- __builtin__.object
Class variables
var can_delete
var can_order
var exclude
var extra
var fields
var fk_name
var form_class
var formfield_callback
var formset_class
var initial
var inline_model
var max_num
var model
var prefix
var save_as_new
var success_url
Methods
def __init__(
self, parent_model, request, instance, view_kwargs=None, view=None)
def __init__(self, parent_model, request, instance, view_kwargs=None, view=None): self.inline_model = self.model self.model = parent_model self.request = request self.object = instance self.kwargs = view_kwargs self.view = view
def construct_formset(
self)
Overrides construct_formset to attach the model class as an attribute of the returned formset instance.
def construct_formset(self): """ Overrides construct_formset to attach the model class as an attribute of the returned formset instance. """ formset = super(InlineFormSet, self).construct_formset() formset.model = self.inline_model return formset
def get_context_data(
self, **kwargs)
If an object has been supplied, inject it into the context with the supplied context_object_name name.
def get_context_data(self, **kwargs): """ If an object has been supplied, inject it into the context with the supplied context_object_name name. """ context = {} if self.object: context['object'] = self.object context_object_name = self.get_context_object_name(self.object) if context_object_name: context[context_object_name] = self.object context.update(kwargs) return super(BaseInlineFormSetMixin, self).get_context_data(**context)
def get_extra_form_kwargs(
self)
Returns extra keyword arguments to pass to each form in the formset
def get_extra_form_kwargs(self): """ Returns extra keyword arguments to pass to each form in the formset """ return {}
def get_factory_kwargs(
self)
Returns the keyword arguments for calling the formset factory
def get_factory_kwargs(self): """ Returns the keyword arguments for calling the formset factory """ kwargs = super(BaseInlineFormSetMixin, self).get_factory_kwargs() kwargs.update({ 'exclude': self.exclude, 'fields': self.fields, 'formfield_callback': self.formfield_callback, 'fk_name': self.fk_name, }) if self.get_form_class(): kwargs['form'] = self.get_form_class() if self.get_formset_class(): kwargs['formset'] = self.get_formset_class() return kwargs
def get_form_class(
self)
Returns the form class to use with the formset in this view
def get_form_class(self): """ Returns the form class to use with the formset in this view """ return self.form_class
def get_formset(
self)
Returns the formset class from the inline formset factory
def get_formset(self): """ Returns the formset class from the inline formset factory """ return inlineformset_factory(self.model, self.get_inline_model(), **self.get_factory_kwargs())
def get_formset_class(
self)
Returns the formset class to use in the formset factory
def get_formset_class(self): """ Returns the formset class to use in the formset factory """ return self.formset_class
def get_formset_kwargs(
self)
Returns the keyword arguments for instantiating the formset.
def get_formset_kwargs(self): """ Returns the keyword arguments for instantiating the formset. """ kwargs = super(BaseInlineFormSetMixin, self).get_formset_kwargs() kwargs['save_as_new'] = self.save_as_new kwargs['instance'] = self.object return kwargs
def get_initial(
self)
Returns the initial data to use for formsets on this view.
def get_initial(self): """ Returns the initial data to use for formsets on this view. """ return self.initial
def get_inline_model(
self)
Returns the inline model to use with the inline formset
def get_inline_model(self): """ Returns the inline model to use with the inline formset """ return self.inline_model
class CollectionRelatedInline
class CollectionRelatedInline(InlineFormSet): model = MediaCollectionRelated exclude = ['mime_type']
Ancestors (in MRO)
- CollectionRelatedInline
- extra_views.advanced.InlineFormSet
- extra_views.formsets.BaseInlineFormSetMixin
- extra_views.formsets.BaseFormSetMixin
- __builtin__.object
Class variables
var can_delete
var can_order
var exclude
var extra
var fields
var fk_name
var form_class
var formfield_callback
var formset_class
var initial
var inline_model
var max_num
var model
var prefix
var save_as_new
var success_url
Methods
def __init__(
self, parent_model, request, instance, view_kwargs=None, view=None)
def __init__(self, parent_model, request, instance, view_kwargs=None, view=None): self.inline_model = self.model self.model = parent_model self.request = request self.object = instance self.kwargs = view_kwargs self.view = view
def construct_formset(
self)
Overrides construct_formset to attach the model class as an attribute of the returned formset instance.
def construct_formset(self): """ Overrides construct_formset to attach the model class as an attribute of the returned formset instance. """ formset = super(InlineFormSet, self).construct_formset() formset.model = self.inline_model return formset
def get_context_data(
self, **kwargs)
If an object has been supplied, inject it into the context with the supplied context_object_name name.
def get_context_data(self, **kwargs): """ If an object has been supplied, inject it into the context with the supplied context_object_name name. """ context = {} if self.object: context['object'] = self.object context_object_name = self.get_context_object_name(self.object) if context_object_name: context[context_object_name] = self.object context.update(kwargs) return super(BaseInlineFormSetMixin, self).get_context_data(**context)
def get_extra_form_kwargs(
self)
Returns extra keyword arguments to pass to each form in the formset
def get_extra_form_kwargs(self): """ Returns extra keyword arguments to pass to each form in the formset """ return {}
def get_factory_kwargs(
self)
Returns the keyword arguments for calling the formset factory
def get_factory_kwargs(self): """ Returns the keyword arguments for calling the formset factory """ kwargs = super(BaseInlineFormSetMixin, self).get_factory_kwargs() kwargs.update({ 'exclude': self.exclude, 'fields': self.fields, 'formfield_callback': self.formfield_callback, 'fk_name': self.fk_name, }) if self.get_form_class(): kwargs['form'] = self.get_form_class() if self.get_formset_class(): kwargs['formset'] = self.get_formset_class() return kwargs
def get_form_class(
self)
Returns the form class to use with the formset in this view
def get_form_class(self): """ Returns the form class to use with the formset in this view """ return self.form_class
def get_formset(
self)
Returns the formset class from the inline formset factory
def get_formset(self): """ Returns the formset class from the inline formset factory """ return inlineformset_factory(self.model, self.get_inline_model(), **self.get_factory_kwargs())
def get_formset_class(
self)
Returns the formset class to use in the formset factory
def get_formset_class(self): """ Returns the formset class to use in the formset factory """ return self.formset_class
def get_formset_kwargs(
self)
Returns the keyword arguments for instantiating the formset.
def get_formset_kwargs(self): """ Returns the keyword arguments for instantiating the formset. """ kwargs = super(BaseInlineFormSetMixin, self).get_formset_kwargs() kwargs['save_as_new'] = self.save_as_new kwargs['instance'] = self.object return kwargs
def get_initial(
self)
Returns the initial data to use for formsets on this view.
def get_initial(self): """ Returns the initial data to use for formsets on this view. """ return self.initial
def get_inline_model(
self)
Returns the inline model to use with the inline formset
def get_inline_model(self): """ Returns the inline model to use with the inline formset """ return self.inline_model
class CorpusRelatedInline
class CorpusRelatedInline(InlineFormSet): model = MediaCorpusRelated exclude = ['mime_type']
Ancestors (in MRO)
- CorpusRelatedInline
- extra_views.advanced.InlineFormSet
- extra_views.formsets.BaseInlineFormSetMixin
- extra_views.formsets.BaseFormSetMixin
- __builtin__.object
Class variables
var can_delete
var can_order
var exclude
var extra
var fields
var fk_name
var form_class
var formfield_callback
var formset_class
var initial
var inline_model
var max_num
var model
var prefix
var save_as_new
var success_url
Methods
def __init__(
self, parent_model, request, instance, view_kwargs=None, view=None)
def __init__(self, parent_model, request, instance, view_kwargs=None, view=None): self.inline_model = self.model self.model = parent_model self.request = request self.object = instance self.kwargs = view_kwargs self.view = view
def construct_formset(
self)
Overrides construct_formset to attach the model class as an attribute of the returned formset instance.
def construct_formset(self): """ Overrides construct_formset to attach the model class as an attribute of the returned formset instance. """ formset = super(InlineFormSet, self).construct_formset() formset.model = self.inline_model return formset
def get_context_data(
self, **kwargs)
If an object has been supplied, inject it into the context with the supplied context_object_name name.
def get_context_data(self, **kwargs): """ If an object has been supplied, inject it into the context with the supplied context_object_name name. """ context = {} if self.object: context['object'] = self.object context_object_name = self.get_context_object_name(self.object) if context_object_name: context[context_object_name] = self.object context.update(kwargs) return super(BaseInlineFormSetMixin, self).get_context_data(**context)
def get_extra_form_kwargs(
self)
Returns extra keyword arguments to pass to each form in the formset
def get_extra_form_kwargs(self): """ Returns extra keyword arguments to pass to each form in the formset """ return {}
def get_factory_kwargs(
self)
Returns the keyword arguments for calling the formset factory
def get_factory_kwargs(self): """ Returns the keyword arguments for calling the formset factory """ kwargs = super(BaseInlineFormSetMixin, self).get_factory_kwargs() kwargs.update({ 'exclude': self.exclude, 'fields': self.fields, 'formfield_callback': self.formfield_callback, 'fk_name': self.fk_name, }) if self.get_form_class(): kwargs['form'] = self.get_form_class() if self.get_formset_class(): kwargs['formset'] = self.get_formset_class() return kwargs
def get_form_class(
self)
Returns the form class to use with the formset in this view
def get_form_class(self): """ Returns the form class to use with the formset in this view """ return self.form_class
def get_formset(
self)
Returns the formset class from the inline formset factory
def get_formset(self): """ Returns the formset class from the inline formset factory """ return inlineformset_factory(self.model, self.get_inline_model(), **self.get_factory_kwargs())
def get_formset_class(
self)
Returns the formset class to use in the formset factory
def get_formset_class(self): """ Returns the formset class to use in the formset factory """ return self.formset_class
def get_formset_kwargs(
self)
Returns the keyword arguments for instantiating the formset.
def get_formset_kwargs(self): """ Returns the keyword arguments for instantiating the formset. """ kwargs = super(BaseInlineFormSetMixin, self).get_formset_kwargs() kwargs['save_as_new'] = self.save_as_new kwargs['instance'] = self.object return kwargs
def get_initial(
self)
Returns the initial data to use for formsets on this view.
def get_initial(self): """ Returns the initial data to use for formsets on this view. """ return self.initial
def get_inline_model(
self)
Returns the inline model to use with the inline formset
def get_inline_model(self): """ Returns the inline model to use with the inline formset """ return self.inline_model
class EpubPasswordForm
class EpubPasswordForm(forms.Form): password = forms.CharField(label=_('password'))
Ancestors (in MRO)
- EpubPasswordForm
- django.forms.forms.Form
- django.forms.forms.BaseForm
- __builtin__.object
Class variables
var base_fields
var password
Instance variables
var changed_data
var errors
Returns an ErrorDict for the data provided for the form
var media
Methods
def __init__(
self, data=None, files=None, auto_id=u'id_%s', prefix=None, initial=None, error_class=<class 'django.forms.util.ErrorList'>, label_suffix=None, empty_permitted=False)
def __init__(self, data=None, files=None, auto_id='id_%s', prefix=None, initial=None, error_class=ErrorList, label_suffix=None, empty_permitted=False): self.is_bound = data is not None or files is not None self.data = data or {} self.files = files or {} self.auto_id = auto_id self.prefix = prefix self.initial = initial or {} self.error_class = error_class # Translators: This is the default suffix added to form field labels self.label_suffix = label_suffix if label_suffix is not None else _(':') self.empty_permitted = empty_permitted self._errors = None # Stores the errors after clean() has been called. self._changed_data = None # The base_fields class attribute is the *class-wide* definition of # fields. Because a particular *instance* of the class might want to # alter self.fields, we create self.fields here by copying base_fields. # Instances should always modify self.fields; they should not modify # self.base_fields. self.fields = copy.deepcopy(self.base_fields)
def add_initial_prefix(
self, field_name)
Add a 'initial' prefix for checking dynamic initial values
def add_initial_prefix(self, field_name): """ Add a 'initial' prefix for checking dynamic initial values """ return 'initial-%s' % self.add_prefix(field_name)
def add_prefix(
self, field_name)
Returns the field name with a prefix appended, if this Form has a prefix set.
Subclasses may wish to override.
def add_prefix(self, field_name): """ Returns the field name with a prefix appended, if this Form has a prefix set. Subclasses may wish to override. """ return '%s-%s' % (self.prefix, field_name) if self.prefix else field_name
def as_p(
self)
Returns this form rendered as HTML
s.
def as_p(self): "Returns this form rendered as HTML <p>s." return self._html_output( normal_row = '<p%(html_class_attr)s>%(label)s %(field)s%(help_text)s</p>', error_row = '%s', row_ender = '</p>', help_text_html = ' <span class="helptext">%s</span>', errors_on_separate_row = True)
def as_table(
self)
Returns this form rendered as HTML
def as_table(self): "Returns this form rendered as HTML <tr>s -- excluding the <table></table>." return self._html_output( normal_row = '<tr%(html_class_attr)s><th>%(label)s</th><td>%(errors)s%(field)s%(help_text)s</td></tr>', error_row = '<tr><td colspan="2">%s</td></tr>', row_ender = '</td></tr>', help_text_html = '<br /><span class="helptext">%s</span>', errors_on_separate_row = False)
def as_ul(
self)
Returns this form rendered as HTML
def as_ul(self): "Returns this form rendered as HTML <li>s -- excluding the <ul></ul>." return self._html_output( normal_row = '<li%(html_class_attr)s>%(errors)s%(label)s %(field)s%(help_text)s</li>', error_row = '<li>%s</li>', row_ender = '</li>', help_text_html = ' <span class="helptext">%s</span>', errors_on_separate_row = False)
def clean(
self)
Hook for doing any extra form-wide cleaning after Field.clean() been called on every field. Any ValidationError raised by this method will not be associated with a particular field; it will have a special-case association with the field named 'all'.
def clean(self): """ Hook for doing any extra form-wide cleaning after Field.clean() been called on every field. Any ValidationError raised by this method will not be associated with a particular field; it will have a special-case association with the field named '__all__'. """ return self.cleaned_data
def full_clean(
self)
Cleans all of self.data and populates self._errors and self.cleaned_data.
def full_clean(self): """ Cleans all of self.data and populates self._errors and self.cleaned_data. """ self._errors = ErrorDict() if not self.is_bound: # Stop further processing. return self.cleaned_data = {} # If the form is permitted to be empty, and none of the form data has # changed from the initial data, short circuit any validation. if self.empty_permitted and not self.has_changed(): return self._clean_fields() self._clean_form() self._post_clean()
def has_changed(
self)
Returns True if data differs from initial.
def has_changed(self): """ Returns True if data differs from initial. """ return bool(self.changed_data)
Returns a list of all the BoundField objects that are hidden fields. Useful for manual form layout in templates.
def is_multipart(
self)
Returns True if the form needs to be multipart-encoded, i.e. it has FileInput. Otherwise, False.
def is_multipart(self): """ Returns True if the form needs to be multipart-encoded, i.e. it has FileInput. Otherwise, False. """ for field in self.fields.values(): if field.widget.needs_multipart_form: return True return False
def is_valid(
self)
Returns True if the form has no errors. Otherwise, False. If errors are being ignored, returns False.
def is_valid(self): """ Returns True if the form has no errors. Otherwise, False. If errors are being ignored, returns False. """ return self.is_bound and not bool(self.errors)
def non_field_errors(
self)
Returns an ErrorList of errors that aren't associated with a particular field -- i.e., from Form.clean(). Returns an empty ErrorList if there are none.
def non_field_errors(self): """ Returns an ErrorList of errors that aren't associated with a particular field -- i.e., from Form.clean(). Returns an empty ErrorList if there are none. """ return self.errors.get(NON_FIELD_ERRORS, self.error_class())
def visible_fields(
self)
Returns a list of BoundField objects that aren't hidden fields. The opposite of the hidden_fields() method.
def visible_fields(self): """ Returns a list of BoundField objects that aren't hidden fields. The opposite of the hidden_fields() method. """ return [field for field in self if not field.is_hidden]
class FondsRelatedInline
class FondsRelatedInline(InlineFormSet): model = MediaFondsRelated exclude = ['mime_type']
Ancestors (in MRO)
- FondsRelatedInline
- extra_views.advanced.InlineFormSet
- extra_views.formsets.BaseInlineFormSetMixin
- extra_views.formsets.BaseFormSetMixin
- __builtin__.object
Class variables
var can_delete
var can_order
var exclude
var extra
var fields
var fk_name
var form_class
var formfield_callback
var formset_class
var initial
var inline_model
var max_num
var model
var prefix
var save_as_new
var success_url
Methods
def __init__(
self, parent_model, request, instance, view_kwargs=None, view=None)
def __init__(self, parent_model, request, instance, view_kwargs=None, view=None): self.inline_model = self.model self.model = parent_model self.request = request self.object = instance self.kwargs = view_kwargs self.view = view
def construct_formset(
self)
Overrides construct_formset to attach the model class as an attribute of the returned formset instance.
def construct_formset(self): """ Overrides construct_formset to attach the model class as an attribute of the returned formset instance. """ formset = super(InlineFormSet, self).construct_formset() formset.model = self.inline_model return formset
def get_context_data(
self, **kwargs)
If an object has been supplied, inject it into the context with the supplied context_object_name name.
def get_context_data(self, **kwargs): """ If an object has been supplied, inject it into the context with the supplied context_object_name name. """ context = {} if self.object: context['object'] = self.object context_object_name = self.get_context_object_name(self.object) if context_object_name: context[context_object_name] = self.object context.update(kwargs) return super(BaseInlineFormSetMixin, self).get_context_data(**context)
def get_extra_form_kwargs(
self)
Returns extra keyword arguments to pass to each form in the formset
def get_extra_form_kwargs(self): """ Returns extra keyword arguments to pass to each form in the formset """ return {}
def get_factory_kwargs(
self)
Returns the keyword arguments for calling the formset factory
def get_factory_kwargs(self): """ Returns the keyword arguments for calling the formset factory """ kwargs = super(BaseInlineFormSetMixin, self).get_factory_kwargs() kwargs.update({ 'exclude': self.exclude, 'fields': self.fields, 'formfield_callback': self.formfield_callback, 'fk_name': self.fk_name, }) if self.get_form_class(): kwargs['form'] = self.get_form_class() if self.get_formset_class(): kwargs['formset'] = self.get_formset_class() return kwargs
def get_form_class(
self)
Returns the form class to use with the formset in this view
def get_form_class(self): """ Returns the form class to use with the formset in this view """ return self.form_class
def get_formset(
self)
Returns the formset class from the inline formset factory
def get_formset(self): """ Returns the formset class from the inline formset factory """ return inlineformset_factory(self.model, self.get_inline_model(), **self.get_factory_kwargs())
def get_formset_class(
self)
Returns the formset class to use in the formset factory
def get_formset_class(self): """ Returns the formset class to use in the formset factory """ return self.formset_class
def get_formset_kwargs(
self)
Returns the keyword arguments for instantiating the formset.
def get_formset_kwargs(self): """ Returns the keyword arguments for instantiating the formset. """ kwargs = super(BaseInlineFormSetMixin, self).get_formset_kwargs() kwargs['save_as_new'] = self.save_as_new kwargs['instance'] = self.object return kwargs
def get_initial(
self)
Returns the initial data to use for formsets on this view.
def get_initial(self): """ Returns the initial data to use for formsets on this view. """ return self.initial
def get_inline_model(
self)
Returns the inline model to use with the inline formset
def get_inline_model(self): """ Returns the inline model to use with the inline formset """ return self.inline_model
class ItemFormatInline
class ItemFormatInline(InlineFormSet): model = Format max_num = 1
Ancestors (in MRO)
- ItemFormatInline
- extra_views.advanced.InlineFormSet
- extra_views.formsets.BaseInlineFormSetMixin
- extra_views.formsets.BaseFormSetMixin
- __builtin__.object
Class variables
var can_delete
var can_order
var exclude
var extra
var fields
var fk_name
var form_class
var formfield_callback
var formset_class
var initial
var inline_model
var max_num
var model
var prefix
var save_as_new
var success_url
Methods
def __init__(
self, parent_model, request, instance, view_kwargs=None, view=None)
def __init__(self, parent_model, request, instance, view_kwargs=None, view=None): self.inline_model = self.model self.model = parent_model self.request = request self.object = instance self.kwargs = view_kwargs self.view = view
def construct_formset(
self)
Overrides construct_formset to attach the model class as an attribute of the returned formset instance.
def construct_formset(self): """ Overrides construct_formset to attach the model class as an attribute of the returned formset instance. """ formset = super(InlineFormSet, self).construct_formset() formset.model = self.inline_model return formset
def get_context_data(
self, **kwargs)
If an object has been supplied, inject it into the context with the supplied context_object_name name.
def get_context_data(self, **kwargs): """ If an object has been supplied, inject it into the context with the supplied context_object_name name. """ context = {} if self.object: context['object'] = self.object context_object_name = self.get_context_object_name(self.object) if context_object_name: context[context_object_name] = self.object context.update(kwargs) return super(BaseInlineFormSetMixin, self).get_context_data(**context)
def get_extra_form_kwargs(
self)
Returns extra keyword arguments to pass to each form in the formset
def get_extra_form_kwargs(self): """ Returns extra keyword arguments to pass to each form in the formset """ return {}
def get_factory_kwargs(
self)
Returns the keyword arguments for calling the formset factory
def get_factory_kwargs(self): """ Returns the keyword arguments for calling the formset factory """ kwargs = super(BaseInlineFormSetMixin, self).get_factory_kwargs() kwargs.update({ 'exclude': self.exclude, 'fields': self.fields, 'formfield_callback': self.formfield_callback, 'fk_name': self.fk_name, }) if self.get_form_class(): kwargs['form'] = self.get_form_class() if self.get_formset_class(): kwargs['formset'] = self.get_formset_class() return kwargs
def get_form_class(
self)
Returns the form class to use with the formset in this view
def get_form_class(self): """ Returns the form class to use with the formset in this view """ return self.form_class
def get_formset(
self)
Returns the formset class from the inline formset factory
def get_formset(self): """ Returns the formset class from the inline formset factory """ return inlineformset_factory(self.model, self.get_inline_model(), **self.get_factory_kwargs())
def get_formset_class(
self)
Returns the formset class to use in the formset factory
def get_formset_class(self): """ Returns the formset class to use in the formset factory """ return self.formset_class
def get_formset_kwargs(
self)
Returns the keyword arguments for instantiating the formset.
def get_formset_kwargs(self): """ Returns the keyword arguments for instantiating the formset. """ kwargs = super(BaseInlineFormSetMixin, self).get_formset_kwargs() kwargs['save_as_new'] = self.save_as_new kwargs['instance'] = self.object return kwargs
def get_initial(
self)
Returns the initial data to use for formsets on this view.
def get_initial(self): """ Returns the initial data to use for formsets on this view. """ return self.initial
def get_inline_model(
self)
Returns the inline model to use with the inline formset
def get_inline_model(self): """ Returns the inline model to use with the inline formset """ return self.inline_model
class ItemIdentifierInline
class ItemIdentifierInline(InlineFormSet): model = MediaItemIdentifier max_num = 1
Ancestors (in MRO)
- ItemIdentifierInline
- extra_views.advanced.InlineFormSet
- extra_views.formsets.BaseInlineFormSetMixin
- extra_views.formsets.BaseFormSetMixin
- __builtin__.object
Class variables
var can_delete
var can_order
var exclude
var extra
var fields
var fk_name
var form_class
var formfield_callback
var formset_class
var initial
var inline_model
var max_num
var model
var prefix
var save_as_new
var success_url
Methods
def __init__(
self, parent_model, request, instance, view_kwargs=None, view=None)
def __init__(self, parent_model, request, instance, view_kwargs=None, view=None): self.inline_model = self.model self.model = parent_model self.request = request self.object = instance self.kwargs = view_kwargs self.view = view
def construct_formset(
self)
Overrides construct_formset to attach the model class as an attribute of the returned formset instance.
def construct_formset(self): """ Overrides construct_formset to attach the model class as an attribute of the returned formset instance. """ formset = super(InlineFormSet, self).construct_formset() formset.model = self.inline_model return formset
def get_context_data(
self, **kwargs)
If an object has been supplied, inject it into the context with the supplied context_object_name name.
def get_context_data(self, **kwargs): """ If an object has been supplied, inject it into the context with the supplied context_object_name name. """ context = {} if self.object: context['object'] = self.object context_object_name = self.get_context_object_name(self.object) if context_object_name: context[context_object_name] = self.object context.update(kwargs) return super(BaseInlineFormSetMixin, self).get_context_data(**context)
def get_extra_form_kwargs(
self)
Returns extra keyword arguments to pass to each form in the formset
def get_extra_form_kwargs(self): """ Returns extra keyword arguments to pass to each form in the formset """ return {}
def get_factory_kwargs(
self)
Returns the keyword arguments for calling the formset factory
def get_factory_kwargs(self): """ Returns the keyword arguments for calling the formset factory """ kwargs = super(BaseInlineFormSetMixin, self).get_factory_kwargs() kwargs.update({ 'exclude': self.exclude, 'fields': self.fields, 'formfield_callback': self.formfield_callback, 'fk_name': self.fk_name, }) if self.get_form_class(): kwargs['form'] = self.get_form_class() if self.get_formset_class(): kwargs['formset'] = self.get_formset_class() return kwargs
def get_form_class(
self)
Returns the form class to use with the formset in this view
def get_form_class(self): """ Returns the form class to use with the formset in this view """ return self.form_class
def get_formset(
self)
Returns the formset class from the inline formset factory
def get_formset(self): """ Returns the formset class from the inline formset factory """ return inlineformset_factory(self.model, self.get_inline_model(), **self.get_factory_kwargs())
def get_formset_class(
self)
Returns the formset class to use in the formset factory
def get_formset_class(self): """ Returns the formset class to use in the formset factory """ return self.formset_class
def get_formset_kwargs(
self)
Returns the keyword arguments for instantiating the formset.
def get_formset_kwargs(self): """ Returns the keyword arguments for instantiating the formset. """ kwargs = super(BaseInlineFormSetMixin, self).get_formset_kwargs() kwargs['save_as_new'] = self.save_as_new kwargs['instance'] = self.object return kwargs
def get_initial(
self)
Returns the initial data to use for formsets on this view.
def get_initial(self): """ Returns the initial data to use for formsets on this view. """ return self.initial
def get_inline_model(
self)
Returns the inline model to use with the inline formset
def get_inline_model(self): """ Returns the inline model to use with the inline formset """ return self.inline_model
class ItemKeywordInline
class ItemKeywordInline(InlineFormSet): model = MediaItemKeyword
Ancestors (in MRO)
- ItemKeywordInline
- extra_views.advanced.InlineFormSet
- extra_views.formsets.BaseInlineFormSetMixin
- extra_views.formsets.BaseFormSetMixin
- __builtin__.object
Class variables
var can_delete
var can_order
var exclude
var extra
var fields
var fk_name
var form_class
var formfield_callback
var formset_class
var initial
var inline_model
var max_num
var model
var prefix
var save_as_new
var success_url
Methods
def __init__(
self, parent_model, request, instance, view_kwargs=None, view=None)
def __init__(self, parent_model, request, instance, view_kwargs=None, view=None): self.inline_model = self.model self.model = parent_model self.request = request self.object = instance self.kwargs = view_kwargs self.view = view
def construct_formset(
self)
Overrides construct_formset to attach the model class as an attribute of the returned formset instance.
def construct_formset(self): """ Overrides construct_formset to attach the model class as an attribute of the returned formset instance. """ formset = super(InlineFormSet, self).construct_formset() formset.model = self.inline_model return formset
def get_context_data(
self, **kwargs)
If an object has been supplied, inject it into the context with the supplied context_object_name name.
def get_context_data(self, **kwargs): """ If an object has been supplied, inject it into the context with the supplied context_object_name name. """ context = {} if self.object: context['object'] = self.object context_object_name = self.get_context_object_name(self.object) if context_object_name: context[context_object_name] = self.object context.update(kwargs) return super(BaseInlineFormSetMixin, self).get_context_data(**context)
def get_extra_form_kwargs(
self)
Returns extra keyword arguments to pass to each form in the formset
def get_extra_form_kwargs(self): """ Returns extra keyword arguments to pass to each form in the formset """ return {}
def get_factory_kwargs(
self)
Returns the keyword arguments for calling the formset factory
def get_factory_kwargs(self): """ Returns the keyword arguments for calling the formset factory """ kwargs = super(BaseInlineFormSetMixin, self).get_factory_kwargs() kwargs.update({ 'exclude': self.exclude, 'fields': self.fields, 'formfield_callback': self.formfield_callback, 'fk_name': self.fk_name, }) if self.get_form_class(): kwargs['form'] = self.get_form_class() if self.get_formset_class(): kwargs['formset'] = self.get_formset_class() return kwargs
def get_form_class(
self)
Returns the form class to use with the formset in this view
def get_form_class(self): """ Returns the form class to use with the formset in this view """ return self.form_class
def get_formset(
self)
Returns the formset class from the inline formset factory
def get_formset(self): """ Returns the formset class from the inline formset factory """ return inlineformset_factory(self.model, self.get_inline_model(), **self.get_factory_kwargs())
def get_formset_class(
self)
Returns the formset class to use in the formset factory
def get_formset_class(self): """ Returns the formset class to use in the formset factory """ return self.formset_class
def get_formset_kwargs(
self)
Returns the keyword arguments for instantiating the formset.
def get_formset_kwargs(self): """ Returns the keyword arguments for instantiating the formset. """ kwargs = super(BaseInlineFormSetMixin, self).get_formset_kwargs() kwargs['save_as_new'] = self.save_as_new kwargs['instance'] = self.object return kwargs
def get_initial(
self)
Returns the initial data to use for formsets on this view.
def get_initial(self): """ Returns the initial data to use for formsets on this view. """ return self.initial
def get_inline_model(
self)
Returns the inline model to use with the inline formset
def get_inline_model(self): """ Returns the inline model to use with the inline formset """ return self.inline_model
class ItemPerformanceInline
class ItemPerformanceInline(InlineFormSet): model = MediaItemPerformance
Ancestors (in MRO)
- ItemPerformanceInline
- extra_views.advanced.InlineFormSet
- extra_views.formsets.BaseInlineFormSetMixin
- extra_views.formsets.BaseFormSetMixin
- __builtin__.object
Class variables
var can_delete
var can_order
var exclude
var extra
var fields
var fk_name
var form_class
var formfield_callback
var formset_class
var initial
var inline_model
var max_num
var model
var prefix
var save_as_new
var success_url
Methods
def __init__(
self, parent_model, request, instance, view_kwargs=None, view=None)
def __init__(self, parent_model, request, instance, view_kwargs=None, view=None): self.inline_model = self.model self.model = parent_model self.request = request self.object = instance self.kwargs = view_kwargs self.view = view
def construct_formset(
self)
Overrides construct_formset to attach the model class as an attribute of the returned formset instance.
def construct_formset(self): """ Overrides construct_formset to attach the model class as an attribute of the returned formset instance. """ formset = super(InlineFormSet, self).construct_formset() formset.model = self.inline_model return formset
def get_context_data(
self, **kwargs)
If an object has been supplied, inject it into the context with the supplied context_object_name name.
def get_context_data(self, **kwargs): """ If an object has been supplied, inject it into the context with the supplied context_object_name name. """ context = {} if self.object: context['object'] = self.object context_object_name = self.get_context_object_name(self.object) if context_object_name: context[context_object_name] = self.object context.update(kwargs) return super(BaseInlineFormSetMixin, self).get_context_data(**context)
def get_extra_form_kwargs(
self)
Returns extra keyword arguments to pass to each form in the formset
def get_extra_form_kwargs(self): """ Returns extra keyword arguments to pass to each form in the formset """ return {}
def get_factory_kwargs(
self)
Returns the keyword arguments for calling the formset factory
def get_factory_kwargs(self): """ Returns the keyword arguments for calling the formset factory """ kwargs = super(BaseInlineFormSetMixin, self).get_factory_kwargs() kwargs.update({ 'exclude': self.exclude, 'fields': self.fields, 'formfield_callback': self.formfield_callback, 'fk_name': self.fk_name, }) if self.get_form_class(): kwargs['form'] = self.get_form_class() if self.get_formset_class(): kwargs['formset'] = self.get_formset_class() return kwargs
def get_form_class(
self)
Returns the form class to use with the formset in this view
def get_form_class(self): """ Returns the form class to use with the formset in this view """ return self.form_class
def get_formset(
self)
Returns the formset class from the inline formset factory
def get_formset(self): """ Returns the formset class from the inline formset factory """ return inlineformset_factory(self.model, self.get_inline_model(), **self.get_factory_kwargs())
def get_formset_class(
self)
Returns the formset class to use in the formset factory
def get_formset_class(self): """ Returns the formset class to use in the formset factory """ return self.formset_class
def get_formset_kwargs(
self)
Returns the keyword arguments for instantiating the formset.
def get_formset_kwargs(self): """ Returns the keyword arguments for instantiating the formset. """ kwargs = super(BaseInlineFormSetMixin, self).get_formset_kwargs() kwargs['save_as_new'] = self.save_as_new kwargs['instance'] = self.object return kwargs
def get_initial(
self)
Returns the initial data to use for formsets on this view.
def get_initial(self): """ Returns the initial data to use for formsets on this view. """ return self.initial
def get_inline_model(
self)
Returns the inline model to use with the inline formset
def get_inline_model(self): """ Returns the inline model to use with the inline formset """ return self.inline_model
class ItemRelatedInline
class ItemRelatedInline(InlineFormSet): model = MediaItemRelated exclude = ['mime_type']
Ancestors (in MRO)
- ItemRelatedInline
- extra_views.advanced.InlineFormSet
- extra_views.formsets.BaseInlineFormSetMixin
- extra_views.formsets.BaseFormSetMixin
- __builtin__.object
Class variables
var can_delete
var can_order
var exclude
var extra
var fields
var fk_name
var form_class
var formfield_callback
var formset_class
var initial
var inline_model
var max_num
var model
var prefix
var save_as_new
var success_url
Methods
def __init__(
self, parent_model, request, instance, view_kwargs=None, view=None)
def __init__(self, parent_model, request, instance, view_kwargs=None, view=None): self.inline_model = self.model self.model = parent_model self.request = request self.object = instance self.kwargs = view_kwargs self.view = view
def construct_formset(
self)
Overrides construct_formset to attach the model class as an attribute of the returned formset instance.
def construct_formset(self): """ Overrides construct_formset to attach the model class as an attribute of the returned formset instance. """ formset = super(InlineFormSet, self).construct_formset() formset.model = self.inline_model return formset
def get_context_data(
self, **kwargs)
If an object has been supplied, inject it into the context with the supplied context_object_name name.
def get_context_data(self, **kwargs): """ If an object has been supplied, inject it into the context with the supplied context_object_name name. """ context = {} if self.object: context['object'] = self.object context_object_name = self.get_context_object_name(self.object) if context_object_name: context[context_object_name] = self.object context.update(kwargs) return super(BaseInlineFormSetMixin, self).get_context_data(**context)
def get_extra_form_kwargs(
self)
Returns extra keyword arguments to pass to each form in the formset
def get_extra_form_kwargs(self): """ Returns extra keyword arguments to pass to each form in the formset """ return {}
def get_factory_kwargs(
self)
Returns the keyword arguments for calling the formset factory
def get_factory_kwargs(self): """ Returns the keyword arguments for calling the formset factory """ kwargs = super(BaseInlineFormSetMixin, self).get_factory_kwargs() kwargs.update({ 'exclude': self.exclude, 'fields': self.fields, 'formfield_callback': self.formfield_callback, 'fk_name': self.fk_name, }) if self.get_form_class(): kwargs['form'] = self.get_form_class() if self.get_formset_class(): kwargs['formset'] = self.get_formset_class() return kwargs
def get_form_class(
self)
Returns the form class to use with the formset in this view
def get_form_class(self): """ Returns the form class to use with the formset in this view """ return self.form_class
def get_formset(
self)
Returns the formset class from the inline formset factory
def get_formset(self): """ Returns the formset class from the inline formset factory """ return inlineformset_factory(self.model, self.get_inline_model(), **self.get_factory_kwargs())
def get_formset_class(
self)
Returns the formset class to use in the formset factory
def get_formset_class(self): """ Returns the formset class to use in the formset factory """ return self.formset_class
def get_formset_kwargs(
self)
Returns the keyword arguments for instantiating the formset.
def get_formset_kwargs(self): """ Returns the keyword arguments for instantiating the formset. """ kwargs = super(BaseInlineFormSetMixin, self).get_formset_kwargs() kwargs['save_as_new'] = self.save_as_new kwargs['instance'] = self.object return kwargs
def get_initial(
self)
Returns the initial data to use for formsets on this view.
def get_initial(self): """ Returns the initial data to use for formsets on this view. """ return self.initial
def get_inline_model(
self)
Returns the inline model to use with the inline formset
def get_inline_model(self): """ Returns the inline model to use with the inline formset """ return self.inline_model
class MediaCollectionForm
class MediaCollectionForm(ModelForm): def __init__(self, *args, **kwargs): super(MediaCollectionForm, self).__init__(*args, **kwargs) if '_I_' in self.instance.code: self.fields["reference"].widget = HiddenInput() if self.instance.computed_duration: self.fields["approx_duration"].widget = HiddenInput() class Meta: model = MediaCollection exclude = model.exclude def clean_doctype_code(self): return self.cleaned_data['doctype_code'] or 0
Ancestors (in MRO)
- MediaCollectionForm
- django.forms.models.ModelForm
- django.forms.models.BaseModelForm
- django.forms.forms.BaseForm
- __builtin__.object
Class variables
var Meta
var base_fields
var declared_fields
Instance variables
var changed_data
var errors
Returns an ErrorDict for the data provided for the form
var media
Methods
def __init__(
self, *args, **kwargs)
def __init__(self, *args, **kwargs): super(MediaCollectionForm, self).__init__(*args, **kwargs) if '_I_' in self.instance.code: self.fields["reference"].widget = HiddenInput() if self.instance.computed_duration: self.fields["approx_duration"].widget = HiddenInput()
def add_initial_prefix(
self, field_name)
Add a 'initial' prefix for checking dynamic initial values
def add_initial_prefix(self, field_name): """ Add a 'initial' prefix for checking dynamic initial values """ return 'initial-%s' % self.add_prefix(field_name)
def add_prefix(
self, field_name)
Returns the field name with a prefix appended, if this Form has a prefix set.
Subclasses may wish to override.
def add_prefix(self, field_name): """ Returns the field name with a prefix appended, if this Form has a prefix set. Subclasses may wish to override. """ return '%s-%s' % (self.prefix, field_name) if self.prefix else field_name
def as_p(
self)
Returns this form rendered as HTML
s.
def as_p(self): "Returns this form rendered as HTML <p>s." return self._html_output( normal_row = '<p%(html_class_attr)s>%(label)s %(field)s%(help_text)s</p>', error_row = '%s', row_ender = '</p>', help_text_html = ' <span class="helptext">%s</span>', errors_on_separate_row = True)
def as_table(
self)
Returns this form rendered as HTML
def as_table(self): "Returns this form rendered as HTML <tr>s -- excluding the <table></table>." return self._html_output( normal_row = '<tr%(html_class_attr)s><th>%(label)s</th><td>%(errors)s%(field)s%(help_text)s</td></tr>', error_row = '<tr><td colspan="2">%s</td></tr>', row_ender = '</td></tr>', help_text_html = '<br /><span class="helptext">%s</span>', errors_on_separate_row = False)
def as_ul(
self)
Returns this form rendered as HTML
def as_ul(self): "Returns this form rendered as HTML <li>s -- excluding the <ul></ul>." return self._html_output( normal_row = '<li%(html_class_attr)s>%(errors)s%(label)s %(field)s%(help_text)s</li>', error_row = '<li>%s</li>', row_ender = '</li>', help_text_html = ' <span class="helptext">%s</span>', errors_on_separate_row = False)
def clean(
self)
def clean(self): self._validate_unique = True return self.cleaned_data
def clean_doctype_code(
self)
def clean_doctype_code(self): return self.cleaned_data['doctype_code'] or 0
def full_clean(
self)
Cleans all of self.data and populates self._errors and self.cleaned_data.
def full_clean(self): """ Cleans all of self.data and populates self._errors and self.cleaned_data. """ self._errors = ErrorDict() if not self.is_bound: # Stop further processing. return self.cleaned_data = {} # If the form is permitted to be empty, and none of the form data has # changed from the initial data, short circuit any validation. if self.empty_permitted and not self.has_changed(): return self._clean_fields() self._clean_form() self._post_clean()
def has_changed(
self)
Returns True if data differs from initial.
def has_changed(self): """ Returns True if data differs from initial. """ return bool(self.changed_data)
Returns a list of all the BoundField objects that are hidden fields. Useful for manual form layout in templates.
def is_multipart(
self)
Returns True if the form needs to be multipart-encoded, i.e. it has FileInput. Otherwise, False.
def is_multipart(self): """ Returns True if the form needs to be multipart-encoded, i.e. it has FileInput. Otherwise, False. """ for field in self.fields.values(): if field.widget.needs_multipart_form: return True return False
def is_valid(
self)
Returns True if the form has no errors. Otherwise, False. If errors are being ignored, returns False.
def is_valid(self): """ Returns True if the form has no errors. Otherwise, False. If errors are being ignored, returns False. """ return self.is_bound and not bool(self.errors)
def non_field_errors(
self)
Returns an ErrorList of errors that aren't associated with a particular field -- i.e., from Form.clean(). Returns an empty ErrorList if there are none.
def non_field_errors(self): """ Returns an ErrorList of errors that aren't associated with a particular field -- i.e., from Form.clean(). Returns an empty ErrorList if there are none. """ return self.errors.get(NON_FIELD_ERRORS, self.error_class())
def save(
self, commit=True)
Saves this form
's cleaned_data into model instance
self.instance
.
If commit=True, then the changes to instance
will be saved to the
database. Returns instance
.
def save(self, commit=True): """ Saves this ``form``'s cleaned_data into model instance ``self.instance``. If commit=True, then the changes to ``instance`` will be saved to the database. Returns ``instance``. """ if self.instance.pk is None: fail_message = 'created' else: fail_message = 'changed' return save_instance(self, self.instance, self._meta.fields, fail_message, commit, self._meta.exclude, construct=False)
def validate_unique(
self)
Calls the instance's validate_unique() method and updates the form's validation errors if any were raised.
def validate_unique(self): """ Calls the instance's validate_unique() method and updates the form's validation errors if any were raised. """ exclude = self._get_validation_exclusions() try: self.instance.validate_unique(exclude=exclude) except ValidationError as e: self._update_errors(e)
def visible_fields(
self)
Returns a list of BoundField objects that aren't hidden fields. The opposite of the hidden_fields() method.
def visible_fields(self): """ Returns a list of BoundField objects that aren't hidden fields. The opposite of the hidden_fields() method. """ return [field for field in self if not field.is_hidden]
class MediaCorpusForm
class MediaCorpusForm(ModelForm): queryset = MediaCollection.objects.all() widget = FilteredSelectMultiple('Collections', is_stacked=False) children = forms.ModelMultipleChoiceField(widget=widget, queryset=queryset, label='Collections', required=False) class Meta: model = MediaCorpus exclude = ['description', 'public_access'] class Media: css = {'all': ('/static/admin/css/widgets.css',),} js = ('/admin/django/jsi18n/',)
Ancestors (in MRO)
- MediaCorpusForm
- django.forms.models.ModelForm
- django.forms.models.BaseModelForm
- django.forms.forms.BaseForm
- __builtin__.object
Class variables
var Media
var Meta
var base_fields
var children
var declared_fields
var queryset
var widget
Instance variables
var changed_data
var errors
Returns an ErrorDict for the data provided for the form
var media
Methods
def __init__(
self, data=None, files=None, auto_id=u'id_%s', prefix=None, initial=None, error_class=<class 'django.forms.util.ErrorList'>, label_suffix=None, empty_permitted=False, instance=None)
def __init__(self, data=None, files=None, auto_id='id_%s', prefix=None, initial=None, error_class=ErrorList, label_suffix=None, empty_permitted=False, instance=None): opts = self._meta if opts.model is None: raise ValueError('ModelForm has no model class specified.') if instance is None: # if we didn't get an instance, instantiate a new one self.instance = opts.model() object_data = {} else: self.instance = instance object_data = model_to_dict(instance, opts.fields, opts.exclude) # if initial was provided, it should override the values from instance if initial is not None: object_data.update(initial) # self._validate_unique will be set to True by BaseModelForm.clean(). # It is False by default so overriding self.clean() and failing to call # super will stop validate_unique from being called. self._validate_unique = False super(BaseModelForm, self).__init__(data, files, auto_id, prefix, object_data, error_class, label_suffix, empty_permitted)
def add_initial_prefix(
self, field_name)
Add a 'initial' prefix for checking dynamic initial values
def add_initial_prefix(self, field_name): """ Add a 'initial' prefix for checking dynamic initial values """ return 'initial-%s' % self.add_prefix(field_name)
def add_prefix(
self, field_name)
Returns the field name with a prefix appended, if this Form has a prefix set.
Subclasses may wish to override.
def add_prefix(self, field_name): """ Returns the field name with a prefix appended, if this Form has a prefix set. Subclasses may wish to override. """ return '%s-%s' % (self.prefix, field_name) if self.prefix else field_name
def as_p(
self)
Returns this form rendered as HTML
s.
def as_p(self): "Returns this form rendered as HTML <p>s." return self._html_output( normal_row = '<p%(html_class_attr)s>%(label)s %(field)s%(help_text)s</p>', error_row = '%s', row_ender = '</p>', help_text_html = ' <span class="helptext">%s</span>', errors_on_separate_row = True)
def as_table(
self)
Returns this form rendered as HTML
def as_table(self): "Returns this form rendered as HTML <tr>s -- excluding the <table></table>." return self._html_output( normal_row = '<tr%(html_class_attr)s><th>%(label)s</th><td>%(errors)s%(field)s%(help_text)s</td></tr>', error_row = '<tr><td colspan="2">%s</td></tr>', row_ender = '</td></tr>', help_text_html = '<br /><span class="helptext">%s</span>', errors_on_separate_row = False)
def as_ul(
self)
Returns this form rendered as HTML
def as_ul(self): "Returns this form rendered as HTML <li>s -- excluding the <ul></ul>." return self._html_output( normal_row = '<li%(html_class_attr)s>%(errors)s%(label)s %(field)s%(help_text)s</li>', error_row = '<li>%s</li>', row_ender = '</li>', help_text_html = ' <span class="helptext">%s</span>', errors_on_separate_row = False)
def clean(
self)
def clean(self): self._validate_unique = True return self.cleaned_data
def full_clean(
self)
Cleans all of self.data and populates self._errors and self.cleaned_data.
def full_clean(self): """ Cleans all of self.data and populates self._errors and self.cleaned_data. """ self._errors = ErrorDict() if not self.is_bound: # Stop further processing. return self.cleaned_data = {} # If the form is permitted to be empty, and none of the form data has # changed from the initial data, short circuit any validation. if self.empty_permitted and not self.has_changed(): return self._clean_fields() self._clean_form() self._post_clean()
def has_changed(
self)
Returns True if data differs from initial.
def has_changed(self): """ Returns True if data differs from initial. """ return bool(self.changed_data)
Returns a list of all the BoundField objects that are hidden fields. Useful for manual form layout in templates.
def is_multipart(
self)
Returns True if the form needs to be multipart-encoded, i.e. it has FileInput. Otherwise, False.
def is_multipart(self): """ Returns True if the form needs to be multipart-encoded, i.e. it has FileInput. Otherwise, False. """ for field in self.fields.values(): if field.widget.needs_multipart_form: return True return False
def is_valid(
self)
Returns True if the form has no errors. Otherwise, False. If errors are being ignored, returns False.
def is_valid(self): """ Returns True if the form has no errors. Otherwise, False. If errors are being ignored, returns False. """ return self.is_bound and not bool(self.errors)
def non_field_errors(
self)
Returns an ErrorList of errors that aren't associated with a particular field -- i.e., from Form.clean(). Returns an empty ErrorList if there are none.
def non_field_errors(self): """ Returns an ErrorList of errors that aren't associated with a particular field -- i.e., from Form.clean(). Returns an empty ErrorList if there are none. """ return self.errors.get(NON_FIELD_ERRORS, self.error_class())
def save(
self, commit=True)
Saves this form
's cleaned_data into model instance
self.instance
.
If commit=True, then the changes to instance
will be saved to the
database. Returns instance
.
def save(self, commit=True): """ Saves this ``form``'s cleaned_data into model instance ``self.instance``. If commit=True, then the changes to ``instance`` will be saved to the database. Returns ``instance``. """ if self.instance.pk is None: fail_message = 'created' else: fail_message = 'changed' return save_instance(self, self.instance, self._meta.fields, fail_message, commit, self._meta.exclude, construct=False)
def validate_unique(
self)
Calls the instance's validate_unique() method and updates the form's validation errors if any were raised.
def validate_unique(self): """ Calls the instance's validate_unique() method and updates the form's validation errors if any were raised. """ exclude = self._get_validation_exclusions() try: self.instance.validate_unique(exclude=exclude) except ValidationError as e: self._update_errors(e)
def visible_fields(
self)
Returns a list of BoundField objects that aren't hidden fields. The opposite of the hidden_fields() method.
def visible_fields(self): """ Returns a list of BoundField objects that aren't hidden fields. The opposite of the hidden_fields() method. """ return [field for field in self if not field.is_hidden]
class MediaFondsForm
class MediaFondsForm(ModelForm): queryset = MediaCorpus.objects.all() widget = FilteredSelectMultiple("Corpus", is_stacked=False) children = forms.ModelMultipleChoiceField(widget=widget, queryset=queryset, label='Corpus', required=False) class Meta: model = MediaFonds exclude = ['description', 'public_access'] class Media: css = {'all': ['/static/admin/css/widgets.css',],} js = ['/admin/django/jsi18n/',]
Ancestors (in MRO)
- MediaFondsForm
- django.forms.models.ModelForm
- django.forms.models.BaseModelForm
- django.forms.forms.BaseForm
- __builtin__.object
Class variables
var Media
var Meta
var base_fields
var children
var declared_fields
var queryset
var widget
Instance variables
var changed_data
var errors
Returns an ErrorDict for the data provided for the form
var media
Methods
def __init__(
self, data=None, files=None, auto_id=u'id_%s', prefix=None, initial=None, error_class=<class 'django.forms.util.ErrorList'>, label_suffix=None, empty_permitted=False, instance=None)
def __init__(self, data=None, files=None, auto_id='id_%s', prefix=None, initial=None, error_class=ErrorList, label_suffix=None, empty_permitted=False, instance=None): opts = self._meta if opts.model is None: raise ValueError('ModelForm has no model class specified.') if instance is None: # if we didn't get an instance, instantiate a new one self.instance = opts.model() object_data = {} else: self.instance = instance object_data = model_to_dict(instance, opts.fields, opts.exclude) # if initial was provided, it should override the values from instance if initial is not None: object_data.update(initial) # self._validate_unique will be set to True by BaseModelForm.clean(). # It is False by default so overriding self.clean() and failing to call # super will stop validate_unique from being called. self._validate_unique = False super(BaseModelForm, self).__init__(data, files, auto_id, prefix, object_data, error_class, label_suffix, empty_permitted)
def add_initial_prefix(
self, field_name)
Add a 'initial' prefix for checking dynamic initial values
def add_initial_prefix(self, field_name): """ Add a 'initial' prefix for checking dynamic initial values """ return 'initial-%s' % self.add_prefix(field_name)
def add_prefix(
self, field_name)
Returns the field name with a prefix appended, if this Form has a prefix set.
Subclasses may wish to override.
def add_prefix(self, field_name): """ Returns the field name with a prefix appended, if this Form has a prefix set. Subclasses may wish to override. """ return '%s-%s' % (self.prefix, field_name) if self.prefix else field_name
def as_p(
self)
Returns this form rendered as HTML
s.
def as_p(self): "Returns this form rendered as HTML <p>s." return self._html_output( normal_row = '<p%(html_class_attr)s>%(label)s %(field)s%(help_text)s</p>', error_row = '%s', row_ender = '</p>', help_text_html = ' <span class="helptext">%s</span>', errors_on_separate_row = True)
def as_table(
self)
Returns this form rendered as HTML
def as_table(self): "Returns this form rendered as HTML <tr>s -- excluding the <table></table>." return self._html_output( normal_row = '<tr%(html_class_attr)s><th>%(label)s</th><td>%(errors)s%(field)s%(help_text)s</td></tr>', error_row = '<tr><td colspan="2">%s</td></tr>', row_ender = '</td></tr>', help_text_html = '<br /><span class="helptext">%s</span>', errors_on_separate_row = False)
def as_ul(
self)
Returns this form rendered as HTML
def as_ul(self): "Returns this form rendered as HTML <li>s -- excluding the <ul></ul>." return self._html_output( normal_row = '<li%(html_class_attr)s>%(errors)s%(label)s %(field)s%(help_text)s</li>', error_row = '<li>%s</li>', row_ender = '</li>', help_text_html = ' <span class="helptext">%s</span>', errors_on_separate_row = False)
def clean(
self)
def clean(self): self._validate_unique = True return self.cleaned_data
def full_clean(
self)
Cleans all of self.data and populates self._errors and self.cleaned_data.
def full_clean(self): """ Cleans all of self.data and populates self._errors and self.cleaned_data. """ self._errors = ErrorDict() if not self.is_bound: # Stop further processing. return self.cleaned_data = {} # If the form is permitted to be empty, and none of the form data has # changed from the initial data, short circuit any validation. if self.empty_permitted and not self.has_changed(): return self._clean_fields() self._clean_form() self._post_clean()
def has_changed(
self)
Returns True if data differs from initial.
def has_changed(self): """ Returns True if data differs from initial. """ return bool(self.changed_data)
Returns a list of all the BoundField objects that are hidden fields. Useful for manual form layout in templates.
def is_multipart(
self)
Returns True if the form needs to be multipart-encoded, i.e. it has FileInput. Otherwise, False.
def is_multipart(self): """ Returns True if the form needs to be multipart-encoded, i.e. it has FileInput. Otherwise, False. """ for field in self.fields.values(): if field.widget.needs_multipart_form: return True return False
def is_valid(
self)
Returns True if the form has no errors. Otherwise, False. If errors are being ignored, returns False.
def is_valid(self): """ Returns True if the form has no errors. Otherwise, False. If errors are being ignored, returns False. """ return self.is_bound and not bool(self.errors)
def non_field_errors(
self)
Returns an ErrorList of errors that aren't associated with a particular field -- i.e., from Form.clean(). Returns an empty ErrorList if there are none.
def non_field_errors(self): """ Returns an ErrorList of errors that aren't associated with a particular field -- i.e., from Form.clean(). Returns an empty ErrorList if there are none. """ return self.errors.get(NON_FIELD_ERRORS, self.error_class())
def save(
self, commit=True)
Saves this form
's cleaned_data into model instance
self.instance
.
If commit=True, then the changes to instance
will be saved to the
database. Returns instance
.
def save(self, commit=True): """ Saves this ``form``'s cleaned_data into model instance ``self.instance``. If commit=True, then the changes to ``instance`` will be saved to the database. Returns ``instance``. """ if self.instance.pk is None: fail_message = 'created' else: fail_message = 'changed' return save_instance(self, self.instance, self._meta.fields, fail_message, commit, self._meta.exclude, construct=False)
def validate_unique(
self)
Calls the instance's validate_unique() method and updates the form's validation errors if any were raised.
def validate_unique(self): """ Calls the instance's validate_unique() method and updates the form's validation errors if any were raised. """ exclude = self._get_validation_exclusions() try: self.instance.validate_unique(exclude=exclude) except ValidationError as e: self._update_errors(e)
def visible_fields(
self)
Returns a list of BoundField objects that aren't hidden fields. The opposite of the hidden_fields() method.
def visible_fields(self): """ Returns a list of BoundField objects that aren't hidden fields. The opposite of the hidden_fields() method. """ return [field for field in self if not field.is_hidden]
class MediaItemForm
class MediaItemForm(ModelForm): class Meta: model = MediaItem exclude = model.exclude def clean_code(self): return self.cleaned_data['code'] or None
Ancestors (in MRO)
- MediaItemForm
- django.forms.models.ModelForm
- django.forms.models.BaseModelForm
- django.forms.forms.BaseForm
- __builtin__.object
Class variables
var Meta
var base_fields
var declared_fields
Instance variables
var changed_data
var errors
Returns an ErrorDict for the data provided for the form
var media
Methods
def __init__(
self, data=None, files=None, auto_id=u'id_%s', prefix=None, initial=None, error_class=<class 'django.forms.util.ErrorList'>, label_suffix=None, empty_permitted=False, instance=None)
def __init__(self, data=None, files=None, auto_id='id_%s', prefix=None, initial=None, error_class=ErrorList, label_suffix=None, empty_permitted=False, instance=None): opts = self._meta if opts.model is None: raise ValueError('ModelForm has no model class specified.') if instance is None: # if we didn't get an instance, instantiate a new one self.instance = opts.model() object_data = {} else: self.instance = instance object_data = model_to_dict(instance, opts.fields, opts.exclude) # if initial was provided, it should override the values from instance if initial is not None: object_data.update(initial) # self._validate_unique will be set to True by BaseModelForm.clean(). # It is False by default so overriding self.clean() and failing to call # super will stop validate_unique from being called. self._validate_unique = False super(BaseModelForm, self).__init__(data, files, auto_id, prefix, object_data, error_class, label_suffix, empty_permitted)
def add_initial_prefix(
self, field_name)
Add a 'initial' prefix for checking dynamic initial values
def add_initial_prefix(self, field_name): """ Add a 'initial' prefix for checking dynamic initial values """ return 'initial-%s' % self.add_prefix(field_name)
def add_prefix(
self, field_name)
Returns the field name with a prefix appended, if this Form has a prefix set.
Subclasses may wish to override.
def add_prefix(self, field_name): """ Returns the field name with a prefix appended, if this Form has a prefix set. Subclasses may wish to override. """ return '%s-%s' % (self.prefix, field_name) if self.prefix else field_name
def as_p(
self)
Returns this form rendered as HTML
s.
def as_p(self): "Returns this form rendered as HTML <p>s." return self._html_output( normal_row = '<p%(html_class_attr)s>%(label)s %(field)s%(help_text)s</p>', error_row = '%s', row_ender = '</p>', help_text_html = ' <span class="helptext">%s</span>', errors_on_separate_row = True)
def as_table(
self)
Returns this form rendered as HTML
def as_table(self): "Returns this form rendered as HTML <tr>s -- excluding the <table></table>." return self._html_output( normal_row = '<tr%(html_class_attr)s><th>%(label)s</th><td>%(errors)s%(field)s%(help_text)s</td></tr>', error_row = '<tr><td colspan="2">%s</td></tr>', row_ender = '</td></tr>', help_text_html = '<br /><span class="helptext">%s</span>', errors_on_separate_row = False)
def as_ul(
self)
Returns this form rendered as HTML
def as_ul(self): "Returns this form rendered as HTML <li>s -- excluding the <ul></ul>." return self._html_output( normal_row = '<li%(html_class_attr)s>%(errors)s%(label)s %(field)s%(help_text)s</li>', error_row = '<li>%s</li>', row_ender = '</li>', help_text_html = ' <span class="helptext">%s</span>', errors_on_separate_row = False)
def clean(
self)
def clean(self): self._validate_unique = True return self.cleaned_data
def clean_code(
self)
def clean_code(self): return self.cleaned_data['code'] or None
def full_clean(
self)
Cleans all of self.data and populates self._errors and self.cleaned_data.
def full_clean(self): """ Cleans all of self.data and populates self._errors and self.cleaned_data. """ self._errors = ErrorDict() if not self.is_bound: # Stop further processing. return self.cleaned_data = {} # If the form is permitted to be empty, and none of the form data has # changed from the initial data, short circuit any validation. if self.empty_permitted and not self.has_changed(): return self._clean_fields() self._clean_form() self._post_clean()
def has_changed(
self)
Returns True if data differs from initial.
def has_changed(self): """ Returns True if data differs from initial. """ return bool(self.changed_data)
Returns a list of all the BoundField objects that are hidden fields. Useful for manual form layout in templates.
def is_multipart(
self)
Returns True if the form needs to be multipart-encoded, i.e. it has FileInput. Otherwise, False.
def is_multipart(self): """ Returns True if the form needs to be multipart-encoded, i.e. it has FileInput. Otherwise, False. """ for field in self.fields.values(): if field.widget.needs_multipart_form: return True return False
def is_valid(
self)
Returns True if the form has no errors. Otherwise, False. If errors are being ignored, returns False.
def is_valid(self): """ Returns True if the form has no errors. Otherwise, False. If errors are being ignored, returns False. """ return self.is_bound and not bool(self.errors)
def non_field_errors(
self)
Returns an ErrorList of errors that aren't associated with a particular field -- i.e., from Form.clean(). Returns an empty ErrorList if there are none.
def non_field_errors(self): """ Returns an ErrorList of errors that aren't associated with a particular field -- i.e., from Form.clean(). Returns an empty ErrorList if there are none. """ return self.errors.get(NON_FIELD_ERRORS, self.error_class())
def save(
self, commit=True)
Saves this form
's cleaned_data into model instance
self.instance
.
If commit=True, then the changes to instance
will be saved to the
database. Returns instance
.
def save(self, commit=True): """ Saves this ``form``'s cleaned_data into model instance ``self.instance``. If commit=True, then the changes to ``instance`` will be saved to the database. Returns ``instance``. """ if self.instance.pk is None: fail_message = 'created' else: fail_message = 'changed' return save_instance(self, self.instance, self._meta.fields, fail_message, commit, self._meta.exclude, construct=False)
def validate_unique(
self)
Calls the instance's validate_unique() method and updates the form's validation errors if any were raised.
def validate_unique(self): """ Calls the instance's validate_unique() method and updates the form's validation errors if any were raised. """ exclude = self._get_validation_exclusions() try: self.instance.validate_unique(exclude=exclude) except ValidationError as e: self._update_errors(e)
def visible_fields(
self)
Returns a list of BoundField objects that aren't hidden fields. The opposite of the hidden_fields() method.
def visible_fields(self): """ Returns a list of BoundField objects that aren't hidden fields. The opposite of the hidden_fields() method. """ return [field for field in self if not field.is_hidden]
class PlaylistForm
class PlaylistForm(ModelForm): class Meta: model = Playlist
Ancestors (in MRO)
- PlaylistForm
- django.forms.models.ModelForm
- django.forms.models.BaseModelForm
- django.forms.forms.BaseForm
- __builtin__.object
Class variables
var Meta
var base_fields
var declared_fields
Instance variables
var changed_data
var errors
Returns an ErrorDict for the data provided for the form
var media
Methods
def __init__(
self, data=None, files=None, auto_id=u'id_%s', prefix=None, initial=None, error_class=<class 'django.forms.util.ErrorList'>, label_suffix=None, empty_permitted=False, instance=None)
def __init__(self, data=None, files=None, auto_id='id_%s', prefix=None, initial=None, error_class=ErrorList, label_suffix=None, empty_permitted=False, instance=None): opts = self._meta if opts.model is None: raise ValueError('ModelForm has no model class specified.') if instance is None: # if we didn't get an instance, instantiate a new one self.instance = opts.model() object_data = {} else: self.instance = instance object_data = model_to_dict(instance, opts.fields, opts.exclude) # if initial was provided, it should override the values from instance if initial is not None: object_data.update(initial) # self._validate_unique will be set to True by BaseModelForm.clean(). # It is False by default so overriding self.clean() and failing to call # super will stop validate_unique from being called. self._validate_unique = False super(BaseModelForm, self).__init__(data, files, auto_id, prefix, object_data, error_class, label_suffix, empty_permitted)
def add_initial_prefix(
self, field_name)
Add a 'initial' prefix for checking dynamic initial values
def add_initial_prefix(self, field_name): """ Add a 'initial' prefix for checking dynamic initial values """ return 'initial-%s' % self.add_prefix(field_name)
def add_prefix(
self, field_name)
Returns the field name with a prefix appended, if this Form has a prefix set.
Subclasses may wish to override.
def add_prefix(self, field_name): """ Returns the field name with a prefix appended, if this Form has a prefix set. Subclasses may wish to override. """ return '%s-%s' % (self.prefix, field_name) if self.prefix else field_name
def as_p(
self)
Returns this form rendered as HTML
s.
def as_p(self): "Returns this form rendered as HTML <p>s." return self._html_output( normal_row = '<p%(html_class_attr)s>%(label)s %(field)s%(help_text)s</p>', error_row = '%s', row_ender = '</p>', help_text_html = ' <span class="helptext">%s</span>', errors_on_separate_row = True)
def as_table(
self)
Returns this form rendered as HTML
def as_table(self): "Returns this form rendered as HTML <tr>s -- excluding the <table></table>." return self._html_output( normal_row = '<tr%(html_class_attr)s><th>%(label)s</th><td>%(errors)s%(field)s%(help_text)s</td></tr>', error_row = '<tr><td colspan="2">%s</td></tr>', row_ender = '</td></tr>', help_text_html = '<br /><span class="helptext">%s</span>', errors_on_separate_row = False)
def as_ul(
self)
Returns this form rendered as HTML
def as_ul(self): "Returns this form rendered as HTML <li>s -- excluding the <ul></ul>." return self._html_output( normal_row = '<li%(html_class_attr)s>%(errors)s%(label)s %(field)s%(help_text)s</li>', error_row = '<li>%s</li>', row_ender = '</li>', help_text_html = ' <span class="helptext">%s</span>', errors_on_separate_row = False)
def clean(
self)
def clean(self): self._validate_unique = True return self.cleaned_data
def full_clean(
self)
Cleans all of self.data and populates self._errors and self.cleaned_data.
def full_clean(self): """ Cleans all of self.data and populates self._errors and self.cleaned_data. """ self._errors = ErrorDict() if not self.is_bound: # Stop further processing. return self.cleaned_data = {} # If the form is permitted to be empty, and none of the form data has # changed from the initial data, short circuit any validation. if self.empty_permitted and not self.has_changed(): return self._clean_fields() self._clean_form() self._post_clean()
def has_changed(
self)
Returns True if data differs from initial.
def has_changed(self): """ Returns True if data differs from initial. """ return bool(self.changed_data)
Returns a list of all the BoundField objects that are hidden fields. Useful for manual form layout in templates.
def is_multipart(
self)
Returns True if the form needs to be multipart-encoded, i.e. it has FileInput. Otherwise, False.
def is_multipart(self): """ Returns True if the form needs to be multipart-encoded, i.e. it has FileInput. Otherwise, False. """ for field in self.fields.values(): if field.widget.needs_multipart_form: return True return False
def is_valid(
self)
Returns True if the form has no errors. Otherwise, False. If errors are being ignored, returns False.
def is_valid(self): """ Returns True if the form has no errors. Otherwise, False. If errors are being ignored, returns False. """ return self.is_bound and not bool(self.errors)
def non_field_errors(
self)
Returns an ErrorList of errors that aren't associated with a particular field -- i.e., from Form.clean(). Returns an empty ErrorList if there are none.
def non_field_errors(self): """ Returns an ErrorList of errors that aren't associated with a particular field -- i.e., from Form.clean(). Returns an empty ErrorList if there are none. """ return self.errors.get(NON_FIELD_ERRORS, self.error_class())
def save(
self, commit=True)
Saves this form
's cleaned_data into model instance
self.instance
.
If commit=True, then the changes to instance
will be saved to the
database. Returns instance
.
def save(self, commit=True): """ Saves this ``form``'s cleaned_data into model instance ``self.instance``. If commit=True, then the changes to ``instance`` will be saved to the database. Returns ``instance``. """ if self.instance.pk is None: fail_message = 'created' else: fail_message = 'changed' return save_instance(self, self.instance, self._meta.fields, fail_message, commit, self._meta.exclude, construct=False)
def validate_unique(
self)
Calls the instance's validate_unique() method and updates the form's validation errors if any were raised.
def validate_unique(self): """ Calls the instance's validate_unique() method and updates the form's validation errors if any were raised. """ exclude = self._get_validation_exclusions() try: self.instance.validate_unique(exclude=exclude) except ValidationError as e: self._update_errors(e)
def visible_fields(
self)
Returns a list of BoundField objects that aren't hidden fields. The opposite of the hidden_fields() method.
def visible_fields(self): """ Returns a list of BoundField objects that aren't hidden fields. The opposite of the hidden_fields() method. """ return [field for field in self if not field.is_hidden]
class RestrictedMediaItemForm
class RestrictedMediaItemForm(MediaItemForm): class Meta: model = MediaItem exclude = model.restricted
Ancestors (in MRO)
- RestrictedMediaItemForm
- MediaItemForm
- django.forms.models.ModelForm
- django.forms.models.BaseModelForm
- django.forms.forms.BaseForm
- __builtin__.object
Class variables
Instance variables
var errors
Inheritance:
MediaItemForm
.errors
Returns an ErrorDict for the data provided for the form
Methods
def __init__(
self, data=None, files=None, auto_id=u'id_%s', prefix=None, initial=None, error_class=<class 'django.forms.util.ErrorList'>, label_suffix=None, empty_permitted=False, instance=None)
Inheritance:
MediaItemForm
.__init__
def __init__(self, data=None, files=None, auto_id='id_%s', prefix=None, initial=None, error_class=ErrorList, label_suffix=None, empty_permitted=False, instance=None): opts = self._meta if opts.model is None: raise ValueError('ModelForm has no model class specified.') if instance is None: # if we didn't get an instance, instantiate a new one self.instance = opts.model() object_data = {} else: self.instance = instance object_data = model_to_dict(instance, opts.fields, opts.exclude) # if initial was provided, it should override the values from instance if initial is not None: object_data.update(initial) # self._validate_unique will be set to True by BaseModelForm.clean(). # It is False by default so overriding self.clean() and failing to call # super will stop validate_unique from being called. self._validate_unique = False super(BaseModelForm, self).__init__(data, files, auto_id, prefix, object_data, error_class, label_suffix, empty_permitted)
def add_initial_prefix(
self, field_name)
Inheritance:
MediaItemForm
.add_initial_prefix
Add a 'initial' prefix for checking dynamic initial values
def add_initial_prefix(self, field_name): """ Add a 'initial' prefix for checking dynamic initial values """ return 'initial-%s' % self.add_prefix(field_name)
def add_prefix(
self, field_name)
Inheritance:
MediaItemForm
.add_prefix
Returns the field name with a prefix appended, if this Form has a prefix set.
Subclasses may wish to override.
def add_prefix(self, field_name): """ Returns the field name with a prefix appended, if this Form has a prefix set. Subclasses may wish to override. """ return '%s-%s' % (self.prefix, field_name) if self.prefix else field_name
def as_p(
self)
Inheritance:
MediaItemForm
.as_p
Returns this form rendered as HTML
s.
def as_p(self): "Returns this form rendered as HTML <p>s." return self._html_output( normal_row = '<p%(html_class_attr)s>%(label)s %(field)s%(help_text)s</p>', error_row = '%s', row_ender = '</p>', help_text_html = ' <span class="helptext">%s</span>', errors_on_separate_row = True)
def as_table(
self)
Inheritance:
MediaItemForm
.as_table
Returns this form rendered as HTML
def as_table(self): "Returns this form rendered as HTML <tr>s -- excluding the <table></table>." return self._html_output( normal_row = '<tr%(html_class_attr)s><th>%(label)s</th><td>%(errors)s%(field)s%(help_text)s</td></tr>', error_row = '<tr><td colspan="2">%s</td></tr>', row_ender = '</td></tr>', help_text_html = '<br /><span class="helptext">%s</span>', errors_on_separate_row = False)
def as_ul(
self)
Inheritance:
MediaItemForm
.as_ul
Returns this form rendered as HTML
def as_ul(self): "Returns this form rendered as HTML <li>s -- excluding the <ul></ul>." return self._html_output( normal_row = '<li%(html_class_attr)s>%(errors)s%(label)s %(field)s%(help_text)s</li>', error_row = '<li>%s</li>', row_ender = '</li>', help_text_html = ' <span class="helptext">%s</span>', errors_on_separate_row = False)
def clean(
self)
Inheritance:
MediaItemForm
.clean
def clean(self): self._validate_unique = True return self.cleaned_data
def clean_code(
self)
Inheritance:
MediaItemForm
.clean_code
def clean_code(self): return self.cleaned_data['code'] or None
def full_clean(
self)
Inheritance:
MediaItemForm
.full_clean
Cleans all of self.data and populates self._errors and self.cleaned_data.
def full_clean(self): """ Cleans all of self.data and populates self._errors and self.cleaned_data. """ self._errors = ErrorDict() if not self.is_bound: # Stop further processing. return self.cleaned_data = {} # If the form is permitted to be empty, and none of the form data has # changed from the initial data, short circuit any validation. if self.empty_permitted and not self.has_changed(): return self._clean_fields() self._clean_form() self._post_clean()
def has_changed(
self)
Inheritance:
MediaItemForm
.has_changed
Returns True if data differs from initial.
def has_changed(self): """ Returns True if data differs from initial. """ return bool(self.changed_data)
Inheritance:
MediaItemForm
.hidden_fields
Returns a list of all the BoundField objects that are hidden fields. Useful for manual form layout in templates.
def is_multipart(
self)
Inheritance:
MediaItemForm
.is_multipart
Returns True if the form needs to be multipart-encoded, i.e. it has FileInput. Otherwise, False.
def is_multipart(self): """ Returns True if the form needs to be multipart-encoded, i.e. it has FileInput. Otherwise, False. """ for field in self.fields.values(): if field.widget.needs_multipart_form: return True return False
def is_valid(
self)
Inheritance:
MediaItemForm
.is_valid
Returns True if the form has no errors. Otherwise, False. If errors are being ignored, returns False.
def is_valid(self): """ Returns True if the form has no errors. Otherwise, False. If errors are being ignored, returns False. """ return self.is_bound and not bool(self.errors)
def non_field_errors(
self)
Inheritance:
MediaItemForm
.non_field_errors
Returns an ErrorList of errors that aren't associated with a particular field -- i.e., from Form.clean(). Returns an empty ErrorList if there are none.
def non_field_errors(self): """ Returns an ErrorList of errors that aren't associated with a particular field -- i.e., from Form.clean(). Returns an empty ErrorList if there are none. """ return self.errors.get(NON_FIELD_ERRORS, self.error_class())
def save(
self, commit=True)
Inheritance:
MediaItemForm
.save
Saves this form
's cleaned_data into model instance
self.instance
.
If commit=True, then the changes to instance
will be saved to the
database. Returns instance
.
def save(self, commit=True): """ Saves this ``form``'s cleaned_data into model instance ``self.instance``. If commit=True, then the changes to ``instance`` will be saved to the database. Returns ``instance``. """ if self.instance.pk is None: fail_message = 'created' else: fail_message = 'changed' return save_instance(self, self.instance, self._meta.fields, fail_message, commit, self._meta.exclude, construct=False)
def validate_unique(
self)
Inheritance:
MediaItemForm
.validate_unique
Calls the instance's validate_unique() method and updates the form's validation errors if any were raised.
def validate_unique(self): """ Calls the instance's validate_unique() method and updates the form's validation errors if any were raised. """ exclude = self._get_validation_exclusions() try: self.instance.validate_unique(exclude=exclude) except ValidationError as e: self._update_errors(e)
def visible_fields(
self)
Inheritance:
MediaItemForm
.visible_fields
Returns a list of BoundField objects that aren't hidden fields. The opposite of the hidden_fields() method.
def visible_fields(self): """ Returns a list of BoundField objects that aren't hidden fields. The opposite of the hidden_fields() method. """ return [field for field in self if not field.is_hidden]