telemeta.forms.language module
# -*- coding: utf-8 -*- # Copyright (C) 2011 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> from django.forms import ModelForm from telemeta.models import * class LanguageForm(ModelForm): class Meta: model = Language
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 LanguageForm
class LanguageForm(ModelForm): class Meta: model = Language
Ancestors (in MRO)
- LanguageForm
- 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]