turbo_helper¶
Subpackages¶
Submodules¶
Package Contents¶
Classes¶
Functions¶
|
Sends an HTTP 303 redirect. |
|
Inspired by Rails |
|
|
|
|
|
|
|
Generate a unique identifier for a Django model instance, class, or even Python object. |
Attributes¶
- turbo_helper.get_current_request()¶
- class turbo_helper.TurboStreamResponse(*args, **kwargs)¶
Bases:
django.http.HttpResponse
- turbo_helper.redirect_303(to, *args, **kwargs)¶
Sends an HTTP 303 redirect.
All arguments are forwarded to django.shortcuts.resolve_url to generate the redirect URL.
- Parameters:
to (Union[str, django.db.models.Model])
- Return type:
- turbo_helper.respond_to(request)¶
Inspired by Rails
https://www.writesoftwarewell.com/how-respond_to-method-works-rails/
- respond_to do |format|
format.turbo_stream { render turbo_stream: turbo_stream_template }
end
- turbo_helper.after_create_commit(sender)¶
- turbo_helper.after_delete_commit(sender)¶
- turbo_helper.after_update_commit(sender)¶
- turbo_helper.register_turbo_stream_action(name)¶
- turbo_helper.turbo_stream¶
- turbo_helper.dom_id(instance, prefix='')¶
Generate a unique identifier for a Django model instance, class, or even Python object.
- Args:
instance (Any): The instance or class for which the identifier is generated. prefix (Optional[str]): An optional prefix to prepend to the identifier. Defaults to an empty string.
- Returns:
str: The generated identifier.
- Raises:
Exception: If the model instance does not have either the to_key or pk attribute.
- Note:
If instance is a Django model instance, the identifier is generated based on the to_key or pk attribute.
If instance is a Django model class, the identifier is generated as new_<class_name>.
If instance is neither a model instance nor a model class, the identifier is generated based on the to_key attribute if available, otherwise it uses the string representation of the instance.
The prefix argument can be used to prepend a prefix to the generated identifier.
- Parameters:
instance (Any)
prefix (Optional[str])
- Return type:
str