forms.py

Standard baseclass form definitions & some widget definitions

Class definitions:

class core.forms.QuerysetWrapper(objects)[source]

Bases: object

Queryset wrapper for caching the choices coupled to a ManyToManyField. The querysetwrapper provides functions which otherwise should be called on the queryset directly.

Dramatically reduces the amount of queries needed when rendering form fieldsets via a fieldset template.

all()[source]
Returns:
All stored objects
none()[source]
Returns:
An empty list
filter(**kwargs)[source]

Filter function which accepts pk and pk__in filters.

Returns:
A list of objects
class core.forms.BaseClassForm[source]

Bases: object

Base class form which holds the functions shared among all forms. Automatically adds placeholders

add_placeholders_to_fields()[source]

Automatically add the ‘placeholder’ attribute to appropiate HTML input elements

get_fields()[source]
Returns:
array of all the fields in the fieldset definition for form param
fieldsets()[source]

Instead of using fields on forms, fieldsets are used. This allows ordening the fields in sets and hiding/showing different sets based on selected values

queryset_speed_up()[source]

Dramatically decreases the amount of queries necessary in template rendering of ManyToManyFields by replacing the queryset with a QuerysetWrapper instance.

If not replaced, every time the (BoundField) ‘field’ variable is used in the template the choices are retrieved from the database, resulting in some cases in 40+ queries.

Execute this function in the __init__ of forms that have one or more instances of ModelMultipleChoiceField

class core.forms.BaseForm(*args, **kwargs)[source]

Bases: django.forms.forms.Form, core.forms.BaseClassForm

Baseclass form which is based on forms.Form

class core.forms.BaseModelForm(*args, **kwargs)[source]

Bases: django.forms.models.ModelForm, core.forms.BaseClassForm

Baseclass form which is based on forms.ModelForm

class core.forms.DisplayWidget(attrs=None)[source]

Bases: django.forms.widgets.Widget

Widget for displaying values

class core.forms.ImageField(*args, **kwargs)[source]

Bases: django.forms.fields.ImageField

Override ImageField to allow setting a maximum upload size and checking mime_type with help of the ‘magic’ package.

class core.forms.MultipleChoiceField(choices=(), required=True, widget=None, label=None, initial=None, help_text=u'', *args, **kwargs)[source]

Bases: django.forms.fields.MultipleChoiceField

Django formfield for multiple selections

class core.forms.ModelMultipleChoiceField(queryset, required=True, widget=None, label=None, initial=None, help_text=u'', *args, **kwargs)[source]

Bases: django.forms.models.ModelMultipleChoiceField

Django formfield for multiple selections

class core.forms.ChoiceOtherWidget(choices, other_field, maxlength=128, attrs=None)[source]

Bases: django.forms.widgets.MultiWidget

Django widget for choice other fields

Displays a select box with the option for ‘other’ allowing to specify a value via a textinput

choices()[source]
Returns:
The widget choices
decompress(value)[source]
Returns:
an array with the value or [‘other’, value]
format_output(rendered_widgets)[source]
Returns:
the rendered widgets seperated by a breakline
class core.forms.ChoiceOtherField(choices=[], *args, **kwargs)[source]

Bases: django.forms.fields.MultiValueField

Django formfield for choice other fields

fix_value_from_post(post_data, field_name)[source]

Used for fixing post data so it can be temporarily stored in the database and later used as form initial data

get_value_from_post(post_data, field_name)[source]

Get the value from the dropbox except when ‘other’ is selected if ‘other’ use the value from the textinput

clean(value)[source]

Raise error messages if needed

compress(data_list)[source]

data_list is a list of two items. The first item is the value from the TypeChoiceField and the second one is from the text input.

class core.forms.FormRadioSelect(attrs=None, choices=())[source]

Bases: django.forms.widgets.RadioSelect

Django formfield which overrides the radio select field

class core.forms.SelectDateWidgetCustom(attrs=None, years=None, format=None, required=True)[source]

Bases: core.widgets.SelectDateWidget

Base class for SelectDateWidget, SelectDateTimeWidget and SelectTimeWidget.

render(name, value, attrs=None)[source]

Return the html code of the widget.

class core.forms.DateWidget(attrs=None, years=None, format=None, required=True)[source]

Bases: core.forms.SelectDateWidgetCustom

Django Widget for selecting dates

render(name, value, attrs=None)[source]

Render datewidget

class core.forms.FormDateField(*args, **kwargs)[source]

Bases: django.forms.fields.DateField

Django Formfield for dates

widget

alias of DateWidget

fix_value_from_post(post_data, field_name)[source]

Used for fixing post data so it can be temporarily stored in the database and later used as form initial data

get_value_from_post(post_data, field_name)[source]

Try to get the value from post_data, used to temporarily store the value.

clean(value)[source]

Date validation checks

widget_attrs(widget)[source]

Add datefield CSS class by default

class core.forms.YesNoChoiceField(*args, **kwargs)[source]

Bases: django.forms.fields.NullBooleanField

Django formfield for yes/no selections

widget

alias of NullBooleanSelect