turbo_response.mixins
#
Module Contents#
Classes#
Handles turbo-stream responses |
|
Handles turbo-stream template responses. |
|
Mixin for handling form validation. Ensures response |
|
This is used when you want to adapt an existing view, |
|
Mixin for handling form validation. Ensures response |
|
Returns a turbo stream when form is invalid. |
|
Returns a turbo stream when form is invalid. |
|
Renders turbo-frame responses |
|
Handles turbo-frame template responses. |
- class turbo_response.mixins.TurboStreamMixin#
- turbo_stream_action: turbo_response.constants.Action | None#
- turbo_stream_target: str | None#
- turbo_stream_multiple: bool = False#
- is_turbo_stream_multiple()#
- Return type:
bool
- get_turbo_stream()#
- Return type:
- get_turbo_stream_action()#
Returns the turbo-stream action parameter
- Returns:
turbo-stream action
- Return type:
Optional[turbo_response.constants.Action]
- get_turbo_stream_target()#
Returns the turbo-stream target parameter
- Returns:
turbo-stream target
- Return type:
Optional[str]
- class turbo_response.mixins.TurboFrameMixin#
- turbo_frame_dom_id: str | None#
- get_turbo_frame()#
- Return type:
- get_turbo_frame_dom_id()#
Should return a valid DOM ID target for the turbo frame.
- Return type:
Optional[str]
- class turbo_response.mixins.TurboStreamResponseMixin#
Bases:
TurboStreamMixin
Handles turbo-stream responses
- turbo_stream_content_safe: bool = False#
- is_turbo_stream_content_safe()#
If content can be rendered without escaping
- Return type:
bool
- get_response_content()#
Returns turbo-stream content.
- Return type:
str
- render_turbo_stream(**kwargs)#
Returns a turbo-stream response.
- Return type:
django.http.HttpResponse
- class turbo_response.mixins.TurboStreamTemplateResponseMixin#
Bases:
TurboStreamMixin
Handles turbo-stream template responses.
- request: django.http.HttpRequest#
- template_engine: django.template.engine.Engine#
- get_template_names: Callable#
- render_turbo_stream(context, **kwargs)#
Renders a turbo-stream template response.
- Parameters:
context (Dict[str, Any]) – template context
- Return type:
django.http.HttpResponse
- class turbo_response.mixins.TurboFormValidationMixin#
Bases:
django.views.generic.edit.FormMixin
- form_invalid(form)#
- Parameters:
form (django.forms.Form) –
- Return type:
django.http.HttpResponse
- class turbo_response.mixins.TurboFormMixin#
Bases:
TurboFormValidationMixin
,django.views.generic.edit.FormMixin
Mixin for handling form validation. Ensures response has 422 status on invalid and 303 on success
- form_valid(form)#
- Parameters:
form (django.forms.Form) –
- Return type:
django.http.HttpResponse
- class turbo_response.mixins.TurboFormAdapterMixin#
Bases:
TurboFormValidationMixin
,django.views.generic.edit.FormMixin
This is used when you want to adapt an existing view, e.g. in 3rd party code.
- form_valid(form)#
- Parameters:
form (django.forms.Form) –
- Return type:
django.http.HttpResponse
- class turbo_response.mixins.TurboFormModelMixin#
Bases:
TurboFormMixin
Mixin for handling form validation. Ensures response has 422 status on invalid and 303 on success
- object: django.db.models.Model | None#
- form_valid(form)#
If the form is valid, save the associated model.
- Parameters:
form (django.forms.Form) –
- Return type:
django.http.HttpResponse
- class turbo_response.mixins.TurboStreamFormMixin#
Bases:
TurboStreamMixin
,TurboFormMixin
Returns a turbo stream when form is invalid.
You should define a partial template corresponding to the template used to render the initial form, for example if your template is posts/post_form.html your partial template is posts/_post_form.html.
The template should then be included in the form:
{% include "_post_form.html" %}
The form or container element should have an ID: this is provided as turbo_stream_target in the template context:
<form method="POST" action=".." id="{{ turbo_stream_target }}">
When the form is posted, if the form is invalid a turbo-stream element wrapping the partial content will be returned, including any validation errors.
- turbo_stream_action: turbo_response.constants.Action#
- turbo_stream_template_prefix: str = '_'#
- turbo_stream_template_name: str | None#
- template_engine: django.template.engine.Engine#
- get_template_names: Callable#
- resolve_turbo_stream_template_name(template_name)#
By default template name will have underscore prefix
- get_turbo_stream_template_names()#
- Return type:
List[str]
- get_context_data(**kwargs)#
- Return type:
Dict[str, Any]
- render_turbo_stream_response(**context)#
- Return type:
django.http.HttpResponse
- form_invalid(form)#
- Parameters:
form (django.forms.Form) –
- Return type:
django.http.HttpResponse
- class turbo_response.mixins.TurboStreamFormModelMixin#
Bases:
TurboStreamFormMixin
Returns a turbo stream when form is invalid.
You should define a partial template corresponding to the template used to render the initial form, for example if your template is posts/post_form.html your partial template is posts/_post_form.html.
The template should then be included in the form:
{% include "_post_form.html" %}
The form or container element should have an ID: this is provided as turbo_stream_target in the template context:
<form method="POST" action=".." id="{{ turbo_stream_target }}">
When the form is posted, if the form is invalid a turbo-stream element wrapping the partial content will be returned, including any validation errors.
- object: django.db.models.Model | None#
- model: Type[django.db.models.Model]#
- get_turbo_stream_target()#
Returns the turbo-stream target parameter
- Returns:
turbo-stream target
- Return type:
Optional[str]
- form_valid(form)#
- Parameters:
form (django.forms.Form) –
- Return type:
django.http.HttpResponse
- class turbo_response.mixins.TurboFrameResponseMixin#
Bases:
TurboFrameMixin
Renders turbo-frame responses
- turbo_frame_content_safe: bool = False#
- is_turbo_frame_content_safe()#
If content can be rendered without escaping
- Return type:
bool
- get_response_content()#
- Return type:
str
- render_turbo_frame(**kwargs)#
Renders a turbo frame to response.
- Return type:
django.http.HttpResponse
- class turbo_response.mixins.TurboFrameTemplateResponseMixin#
Bases:
TurboFrameMixin
Handles turbo-frame template responses.
- request: django.http.HttpRequest#
- template_engine: django.template.engine.Engine#
- get_template_names: Callable#
- render_turbo_frame(context, **kwargs)#
Returns a turbo-frame response.
- Parameters:
context (Dict[str, Any]) – template context
- Return type:
django.http.HttpResponse