Pages

Forms for creating and modifying page and page translation objects

Mirrored Page Field Widget

class integreat_cms.cms.forms.pages.mirrored_page_field_widget.MirroredPageFieldWidget(attrs=None, choices=())[source]

Bases: Select

This Widget class is used to append the url for retrieving the preview of the mirrored page to the data attributes of the options

__init__(attrs=None, choices=())[source]
add_id_index = False[source]
allow_multiple_selected = False[source]
build_attrs(base_attrs, extra_attrs=None)[source]

Build an attribute dictionary.

checked_attribute = {'selected': True}[source]
create_option(name: str, value: int, label: str, selected: bool, index: int, subindex: int | None = None, attrs: dict | None = None) dict[source]

This function creates an option which can be selected in the parent field

Parameters:
  • name (str) – The name of the option

  • value (int) – the value of the option (the page id)

  • label (str) – The label of the option

  • selected (bool) – Whether or not the option is selected

  • index (int) – The index of the option

  • subindex (int | None) – The subindex of the option

  • attrs (dict | None) – The attributes of the option

Returns:

The option dict

Return type:

dict

form: PageForm | None = None[source]

The form this field is bound to

format_value(value)[source]

Return selected values as a list.

get_context(name, value, attrs)[source]
id_for_label(id_, index='0')[source]

Use an incremented id for each option where the main widget references the zero index.

input_type = 'select'[source]
property is_hidden[source]
is_localized = False[source]
is_required = False[source]
language_slug: str | None = None[source]

The current language slug

property media[source]
needs_multipart_form = False[source]
optgroups(name, value, attrs=None)[source]

Return a list of optgroups for this widget.

option_inherits_attrs = False[source]
option_template_name = 'django/forms/widgets/select_option.html'[source]
options(name, value, attrs=None)[source]

Yield a flat list of options for this widget.

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

Render the widget as an HTML string.

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

Yield all “subwidgets” of this widget. Used to enable iterating options from a BoundField for choice widgets.

supports_microseconds = True[source]
template_name = 'django/forms/widgets/select.html'[source]
use_fieldset = False[source]
use_required_attribute(initial)[source]

Don’t render ‘required’ if the first <option> has a value, as that’s invalid HTML.

value_from_datadict(data, files, name)[source]

Given a dictionary of data and this widget’s name, return the value of this widget or None if it’s not provided.

value_omitted_from_data(data, files, name)[source]

Page Filter Form

class integreat_cms.cms.forms.pages.page_filter_form.PageFilterForm(**kwargs: Any)[source]

Bases: CustomFilterForm

Form for filtering page objects

Form fields:

Parameters:

kwargs (Any)

__init__(**kwargs: Any) None[source]

Initialize page filter form

Parameters:

**kwargs (Any) – The supplied keyword arguments

Return type:

None

add_error(field, error)[source]

Update the content of self._errors.

The field argument is the name of the field to which the errors should be added. If it’s None, treat the errors as NON_FIELD_ERRORS.

The error argument can be a single error, a list of errors, or a dictionary that maps field names to lists of errors. An “error” can be either a simple string or an instance of ValidationError with its message attribute set and a “list or dictionary” can be an actual list or dict or an instance of ValidationError with its error_list or error_dict attribute set.

If error is a dictionary, the field argument must be None and errors will be added to the fields that correspond to the keys of the dictionary.

add_initial_prefix(field_name)[source]

Add an ‘initial’ prefix for checking dynamic initial values.

add_prefix(field_name)[source]

Return the field name with a prefix appended, if this Form has a prefix set.

Subclasses may wish to override.

apply(pages: list[Page], language_slug: str) list[Page][source]

Filter the pages list according to the given filter data

Parameters:
  • pages (list[Page]) – The list of pages

  • language_slug (str) – The slug of the current language

Returns:

The filtered page list

Return type:

list[Page]

as_div()[source]

Render as <div> elements.

as_p()[source]

Render as <p> elements.

as_table()[source]

Render as <tr> elements excluding the surrounding <table> tag.

as_ul()[source]

Render as <li> elements excluding the surrounding <ul> tag.

changed_data[source]
clean()[source]

Hook for doing any extra form-wide cleaning after Field.clean() has 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__’.

default_renderer = None[source]
property errors[source]

Return an ErrorDict for the data provided for the form.

field_order = None[source]
filter_by_end_date(pages: list[Page], language_slug: str) list[Page][source]

Filter the pages list by end date

Parameters:
  • pages (list[Page]) – The list of pages

  • language_slug (str) – The slug of the current language

Returns:

The filtered page list

Return type:

list[Page]

filter_by_pages_with_content(pages: list[Page], language_slug: str) list[Page][source]

Filter only by pages that have content (including empty pages with live content) :param pages: The list of pages :param language_slug: The slug of the current language :return: pages that have content

Parameters:
Return type:

list[Page]

filter_by_publication_status(pages: list[Page], language_slug: str) list[Page][source]

Filter the pages list by publication status

Parameters:
  • pages (list[Page]) – The list of pages

  • language_slug (str) – The slug of the current language

Returns:

The filtered page list

Return type:

list[Page]

filter_by_query(pages: list[Page], language_slug: str) list[Page][source]

Filter the pages list by a given search query

Parameters:
  • pages (list[Page]) – The list of pages

  • language_slug (str) – The slug of the current language

Returns:

The filtered page list

Return type:

list[Page]

filter_by_start_date(pages: list[Page], language_slug: str) list[Page][source]

Filter the pages list by start date

Parameters:
  • pages (list[Page]) – The list of pages

  • language_slug (str) – The slug of the current language

Returns:

The filtered page list

Return type:

list[Page]

filter_by_translation_status(pages: list[Page], language_slug: str) list[Page][source]

Filter the pages list by a given translation status

Parameters:
  • pages (list[Page]) – The list of pages

  • language_slug (str) – The slug of the current language

Returns:

The filtered page list

Return type:

list[Page]

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

full_clean()[source]

Clean all of self.data and populate self._errors and self.cleaned_data.

get_context()[source]
get_initial_for_field(field, field_name)[source]

Return initial data for field on form. Use initial data from the form or the field, in that order. Evaluate callable values.

has_changed()[source]

Return True if data differs from initial.

has_error(field, code=None)[source]
hidden_fields()[source]

Return a list of all the BoundField objects that are hidden fields. Useful for manual form layout in templates.

property is_enabled: bool[source]

This function determines whether the filters are applied.

Returns:

Whether filtering should be performed

is_multipart()[source]

Return True if the form needs to be multipart-encoded, i.e. it has FileInput, or False otherwise.

is_valid()[source]

Return True if the form has no errors, or False otherwise.

property media[source]

Return all media required to render the widgets on this form.

non_field_errors()[source]

Return an ErrorList of errors that aren’t associated with a particular field – i.e., from Form.clean(). Return an empty ErrorList if there are none.

order_fields(field_order)[source]

Rearrange the fields according to field_order.

field_order is a list of field names specifying the order. Append fields not included in the list in the default order for backward compatibility with subclasses not overriding field_order. If field_order is None, keep all fields in the order defined in the class. Ignore unknown fields in field_order to allow disabling fields in form subclasses without redefining ordering.

prefix = None[source]
render(template_name=None, context=None, renderer=None)[source]
property template_name[source]
template_name_div = 'django/forms/div.html'[source]
template_name_label = 'django/forms/label.html'[source]
template_name_p = 'django/forms/p.html'[source]
template_name_table = 'django/forms/table.html'[source]
template_name_ul = 'django/forms/ul.html'[source]
use_required_attribute = True[source]
visible_fields()[source]

Return a list of BoundField objects that aren’t hidden fields. The opposite of the hidden_fields() method.

Page Form

class integreat_cms.cms.forms.pages.page_form.PageForm(**kwargs: Any)[source]

Bases: CustomModelForm, CustomTreeNodeForm

Form for creating and modifying page objects

Form fields:

Parameters:

kwargs (Any)

__init__(**kwargs: Any) None[source]

Initialize page form

Parameters:

**kwargs (Any) – The supplied keyword arguments

Return type:

None

add_error(field, error)[source]

Update the content of self._errors.

The field argument is the name of the field to which the errors should be added. If it’s None, treat the errors as NON_FIELD_ERRORS.

The error argument can be a single error, a list of errors, or a dictionary that maps field names to lists of errors. An “error” can be either a simple string or an instance of ValidationError with its message attribute set and a “list or dictionary” can be an actual list or dict or an instance of ValidationError with its error_list or error_dict attribute set.

If error is a dictionary, the field argument must be None and errors will be added to the fields that correspond to the keys of the dictionary.

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

add_initial_prefix(field_name)[source]

Add an ‘initial’ prefix for checking dynamic initial values.

add_prefix(field_name)[source]

Return the field name with a prefix appended, if this Form has a prefix set.

Subclasses may wish to override.

classmethod add_subtree(for_node, node, options)[source]

Recursively build options tree.

as_div()[source]

Render as <div> elements.

as_p()[source]

Render as <p> elements.

as_table()[source]

Render as <tr> elements excluding the surrounding <table> tag.

as_ul()[source]

Render as <li> elements excluding the surrounding <ul> tag.

changed_data[source]
clean() dict[str, Any][source]

This method extends the default clean()-method of the base ModelForm to provide debug logging

Returns:

The cleaned data (see Overriding the clean() method)

Return type:

dict[str, Any]

default_renderer = None[source]
property errors[source]

Return an ErrorDict for the data provided for the form.

field_order = None[source]
full_clean()[source]

Clean all of self.data and populate self._errors and self.cleaned_data.

get_author_queryset() QuerySet[source]

This method retrieves all users, who are eligible to be defined as page authors because they don’t yet have the permission to edit this page.

Returns:

All potential page authors

Return type:

QuerySet

get_context()[source]
get_editor_queryset() QuerySet[source]

This method retrieves all users, who are eligible to be defined as page editors because they don’t yet have the permission to publish this page.

Returns:

All potential page editors

Return type:

QuerySet

get_error_messages() list[dict[str, str]][source]

Return all error messages of this form and append labels to field-errors

Returns:

The errors of this form

Return type:

list[dict[str, str]]

get_initial_for_field(field, field_name)[source]

Return initial data for field on form. Use initial data from the form or the field, in that order. Evaluate callable values.

has_changed()[source]

Return True if data differs from initial.

has_error(field, code=None)[source]
hidden_fields()[source]

Return a list of all the BoundField objects that are hidden fields. Useful for manual form layout in templates.

static is_loop_safe(for_node, possible_parent)[source]
is_multipart()[source]

Return True if the form needs to be multipart-encoded, i.e. it has FileInput, or False otherwise.

is_valid()[source]

Return True if the form has no errors, or False otherwise.

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:

list

static mk_indent(level)[source]
non_field_errors()[source]

Return an ErrorList of errors that aren’t associated with a particular field – i.e., from Form.clean(). Return an empty ErrorList if there are none.

order_fields(field_order)[source]

Rearrange the fields according to field_order.

field_order is a list of field names specifying the order. Append fields not included in the list in the default order for backward compatibility with subclasses not overriding field_order. If field_order is None, keep all fields in the order defined in the class. Ignore unknown fields in field_order to allow disabling fields in form subclasses without redefining ordering.

prefix = None[source]
render(template_name=None, context=None, renderer=None)[source]
save(commit: bool = True) Any[source]

This method extends the default save()-method of the base ModelForm 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

property template_name[source]
template_name_div = 'django/forms/div.html'[source]
template_name_label = 'django/forms/label.html'[source]
template_name_p = 'django/forms/p.html'[source]
template_name_table = 'django/forms/table.html'[source]
template_name_ul = 'django/forms/ul.html'[source]
use_required_attribute = True[source]
validate_unique()[source]

Call the instance’s validate_unique() method and update the form’s validation errors if any were raised.

visible_fields()[source]

Return a list of BoundField objects that aren’t hidden fields. The opposite of the hidden_fields() method.

Page Translation Form

class integreat_cms.cms.forms.pages.page_translation_form.PageTranslationForm(**kwargs: Any)[source]

Bases: MachineTranslationForm

Form for creating and modifying page translation objects

Form fields:

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

add_error(field, error)[source]

Update the content of self._errors.

The field argument is the name of the field to which the errors should be added. If it’s None, treat the errors as NON_FIELD_ERRORS.

The error argument can be a single error, a list of errors, or a dictionary that maps field names to lists of errors. An “error” can be either a simple string or an instance of ValidationError with its message attribute set and a “list or dictionary” can be an actual list or dict or an instance of ValidationError with its error_list or error_dict attribute set.

If error is a dictionary, the field argument must be None and errors will be added to the fields that correspond to the keys of the dictionary.

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

add_initial_prefix(field_name)[source]

Add an ‘initial’ prefix for checking dynamic initial values.

add_prefix(field_name)[source]

Return the field name with a prefix appended, if this Form has a prefix set.

Subclasses may wish to override.

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

as_div()[source]

Render as <div> elements.

as_p()[source]

Render as <p> elements.

as_table()[source]

Render as <tr> elements excluding the surrounding <table> tag.

as_ul()[source]

Render as <li> elements excluding the surrounding <ul> tag.

changed_data[source]
clean() dict[str, Any][source]

Validate form fields which depend on each other, see django.forms.Form.clean()

Returns:

The cleaned form data

Return type:

dict[str, Any]

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:

str

clean_slug() str[source]

Validate the slug field (see Overriding the clean() method)

Returns:

A unique slug based on the input value

Return type:

str

default_renderer = None[source]
property errors[source]

Return an ErrorDict for the data provided for the form.

field_order = None[source]
full_clean()[source]

Clean all of self.data and populate self._errors and self.cleaned_data.

get_context()[source]
get_error_messages() list[dict[str, str]][source]

Return all error messages of this form and append labels to field-errors

Returns:

The errors of this form

Return type:

list[dict[str, str]]

get_initial_for_field(field, field_name)[source]

Return initial data for field on form. Use initial data from the form or the field, in that order. Evaluate callable values.

has_changed()[source]

Return True if data differs from initial.

has_error(field, code=None)[source]
hidden_fields()[source]

Return a list of all the BoundField objects that are hidden fields. Useful for manual form layout in templates.

is_multipart()[source]

Return True if the form needs to be multipart-encoded, i.e. it has FileInput, or False otherwise.

is_valid()[source]

Return True if the form has no errors, or False otherwise.

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

non_field_errors()[source]

Return an ErrorList of errors that aren’t associated with a particular field – i.e., from Form.clean(). Return an empty ErrorList if there are none.

order_fields(field_order)[source]

Rearrange the fields according to field_order.

field_order is a list of field names specifying the order. Append fields not included in the list in the default order for backward compatibility with subclasses not overriding field_order. If field_order is None, keep all fields in the order defined in the class. Ignore unknown fields in field_order to allow disabling fields in form subclasses without redefining ordering.

prefix = None[source]
render(template_name=None, context=None, renderer=None)[source]
save(commit: bool = True, foreign_form_changed: bool = False)[source]

Create machine translations and save them to the database

Parameters:
  • commit (bool) – Whether or not the changes should be written to the database

  • foreign_form_changed (bool) – Whether or not the foreign form of this translation form was changed

Returns:

The saved content translation object

Return type:

EventTranslation | (PageTranslation | POITranslation)

property template_name[source]
template_name_div = 'django/forms/div.html'[source]
template_name_label = 'django/forms/label.html'[source]
template_name_p = 'django/forms/p.html'[source]
template_name_table = 'django/forms/table.html'[source]
template_name_ul = 'django/forms/ul.html'[source]
use_required_attribute = True[source]
validate_unique()[source]

Call the instance’s validate_unique() method and update the form’s validation errors if any were raised.

visible_fields()[source]

Return a list of BoundField objects that aren’t hidden fields. The opposite of the hidden_fields() method.

Parent Field Widget

class integreat_cms.cms.forms.pages.parent_field_widget.ParentFieldWidget(attrs=None, choices=())[source]

Bases: Select

This Widget class is used to append the url for retrieving the page order tables to the data attributes of the options

__init__(attrs=None, choices=())[source]
add_id_index = False[source]
allow_multiple_selected = False[source]
build_attrs(base_attrs, extra_attrs=None)[source]

Build an attribute dictionary.

checked_attribute = {'selected': True}[source]
create_option(name: str, value: int | str, label: SafeString | str, selected: bool, index: int, subindex: Any | None = None, attrs: dict[str, Any] | None = None) dict[str, Any][source]

This function creates an option which can be selected in the parent field

Parameters:
  • name (str) – The name of the option

  • value (int | str) – the value of the option (the page id)

  • label (SafeString | str) – The label of the option

  • selected (bool) – Whether or not the option is selected

  • index (int) – The index of the option

  • subindex (Any | None) – The subindex of the option

  • attrs (dict[str, Any] | None) – The attributes of the option

Returns:

The option dict

Return type:

dict[str, Any]

form = None[source]

The form this field is bound to

format_value(value)[source]

Return selected values as a list.

get_context(name, value, attrs)[source]
id_for_label(id_, index='0')[source]

Use an incremented id for each option where the main widget references the zero index.

input_type = 'select'[source]
property is_hidden[source]
is_localized = False[source]
is_required = False[source]
property media[source]
needs_multipart_form = False[source]
optgroups(name, value, attrs=None)[source]

Return a list of optgroups for this widget.

option_inherits_attrs = False[source]
option_template_name = 'django/forms/widgets/select_option.html'[source]
options(name, value, attrs=None)[source]

Yield a flat list of options for this widget.

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

Render the widget as an HTML string.

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

Yield all “subwidgets” of this widget. Used to enable iterating options from a BoundField for choice widgets.

supports_microseconds = True[source]
template_name = 'django/forms/widgets/select.html'[source]
use_fieldset = False[source]
use_required_attribute(initial)[source]

Don’t render ‘required’ if the first <option> has a value, as that’s invalid HTML.

value_from_datadict(data, files, name)[source]

Given a dictionary of data and this widget’s name, return the value of this widget or None if it’s not provided.

value_omitted_from_data(data, files, name)[source]