Forms
Forms for creating and modifying database objects.
Please refer to django.forms
for general information about Django forms (see also: Working with forms).
Custom Content Model Form
- class integreat_cms.cms.forms.custom_content_model_form.CustomContentModelForm(**kwargs: Any)[source]
Bases:
CustomModelForm
Form for the content model forms for pages, events and POIs.
Form fields:
- Parameters:
kwargs (Any)
- __init__(**kwargs: Any) None [source]
Initialize custom content model form
- Parameters:
**kwargs (Any) – The supplied keyword arguments
- Return type:
None
- add_success_message(request: HttpRequest) None [source]
This adds a success message for a translation form. Requires the attributes “title”, “status” and “foreign_object” on the form instance.
- Parameters:
request (HttpRequest) – The current request submitting the translation form
- Return type:
None
- clean() dict[str, Any] [source]
This method extends the
clean()
-method to verify that a user can modify this content model- Returns:
The cleaned data (see Overriding the clean() method)
- Return type:
- clean_content() str [source]
Validate the content field (see Overriding the clean() method) and applies changes to any element to match the guidelines.
- Raises:
ValidationError – When a heading 1 (
<h1>
) is used in the text content- Returns:
The valid content
- Return type:
- clean_slug() str [source]
Validate the slug field (see Overriding the clean() method)
- Returns:
A unique slug based on the input value
- Return type:
- property media[source]
Return all media required to render the widgets on this form.
Custom Filter Form
- class integreat_cms.cms.forms.custom_filter_form.CustomFilterForm(**kwargs: Any)[source]
Bases:
Form
Base class for filter forms
Form fields:
- Parameters:
kwargs (Any)
- __init__(**kwargs: Any) None [source]
Initialize the custom filter form
- Parameters:
**kwargs (Any) – The supplied keyword arguments
- Return type:
None
- property filters_visible: bool[source]
This function determines whether the filter form is visible by default.
- Returns:
Whether any filters (other than search) were changed
- property is_enabled: bool[source]
This function determines whether the filters are applied.
- Returns:
Whether filtering should be performed
- property media[source]
Return all media required to render the widgets on this form.
Custom Model Form
- class integreat_cms.cms.forms.custom_model_form.CustomModelForm(**kwargs: Any)[source]
Bases:
ModelForm
Form for populating all text widgets of a ModelForm with the default placeholder “Enter … here”. Use this form as base class instead of
django.forms.ModelForm
.Form fields:
- Parameters:
kwargs (Any)
- __init__(**kwargs: Any) None [source]
Initialize placeholder model form
- Parameters:
**kwargs (Any) – The supplied keyword arguments
- Raises:
TypeError – If form is instantiated directly without an inheriting subclass
- Return type:
None
- add_error_messages(request: HttpRequest) None [source]
This function accepts the current request and adds the form’s error messages to the message queue of
django.contrib.messages
.- Parameters:
request (HttpRequest) – The current request submitting the form
- Return type:
None
- clean() dict[str, Any] [source]
This method extends the default
clean()
-method of the baseModelForm
to provide debug logging- Returns:
The cleaned data (see Overriding the clean() method)
- Return type:
- get_error_messages() list[dict[str, str]] [source]
Return all error messages of this form and append labels to field-errors
- property media[source]
Return all media required to render the widgets on this form.
- save(commit: bool = True) Any [source]
This method extends the default
save()
-method of the baseModelForm
to provide debug logging- Parameters:
commit (bool) – Whether or not the changes should be written to the database
- Returns:
The saved object returned by The save() method
- Return type:
Any
Custom Tree Node Form
- class integreat_cms.cms.forms.custom_tree_node_form.CustomTreeNodeForm(**kwargs: Any)[source]
Bases:
MoveNodeForm
Form for creating and modifying tree node objects
Form fields:
_position
: Position (ChoiceField
)_ref_node_id
: Relative to (ChoiceField
)
- Parameters:
kwargs (Any)
- __init__(**kwargs: Any) None [source]
Initialize custom tree node form
- Parameters:
**kwargs (Any) – The supplied keyword arguments
- Return type:
None
- property media[source]
Return all media required to render the widgets on this form.
- classmethod mk_dropdown_tree(model: ModelBase, for_node: None | LanguageTreeNode | Page = None) list [source]
Creates a tree-like list of choices. Overwrites the parent method because the field is hidden anyway and additional queries to render the node titles should be avoided.
- Parameters:
model (ModelBase) – ~integreat_cms.cms.models.abstract_tree_node.AbstractTreeNode
for_node (None | (LanguageTreeNode | Page)) – The instance of this form
- Returns:
A list of select options
- Return type:
Icon Widget
- class integreat_cms.cms.forms.icon_widget.IconWidget(attrs=None)[source]
Bases:
HiddenInput
A custom widget to render the icon field
- get_context(name: str, value: Any | None, attrs: dict[str, Any]) dict[str, dict[str, Any]] [source]
This function gets the context of icon fields
- template_name = 'icon_widget.html'[source]
The template to use for this widget
Machine Translation Form
- class integreat_cms.cms.forms.machine_translation_form.MachineTranslationForm(**kwargs: Any)[source]
Bases:
CustomContentModelForm
Form for selecting target languages for machine translation of a content object. It should be used as base class for translation forms which enable machine translations.
Form fields:
mt_translations_to_create
: Create new translations: (ModelMultipleChoiceField
)mt_translations_to_update
: Update existing translations: (ModelMultipleChoiceField
)
- Parameters:
kwargs (Any)
- __init__(**kwargs: Any) None [source]
Initialize MT translation form. If request and language kwargs are missing, MTs are disabled.
- Parameters:
**kwargs (Any) – The supplied keyword arguments
- Return type:
None
- clean() dict[str, Any] [source]
Validate form fields which depend on each other, see
django.forms.Form.clean()
- property media[source]
Return all media required to render the widgets on this form.
- mt_form_is_enabled() NS_NodeQuerySet [source]
Helper method to decide if this form should be shown, or if it should be hidden for the current language due to a lack of MT-compatible child language nodes
- Returns:
Whether this form is enabled
- Return type:
NS_NodeQuerySet
Object Search Form
- class integreat_cms.cms.forms.object_search_form.ObjectSearchForm(data=None, files=None, auto_id='id_%s', prefix=None, initial=None, error_class=<class 'django.forms.utils.ErrorList'>, label_suffix=None, empty_permitted=False, field_order=None, use_required_attribute=None, renderer=None)[source]
Bases:
Form
Form for searching objects
Form fields:
query
: Query (CharField
)
- property media[source]
Return all media required to render the widgets on this form.