django_unicorn.components.unicorn_view
#
Module Contents#
- django_unicorn.components.unicorn_view.location_cache#
- django_unicorn.components.unicorn_view.views_cache#
- django_unicorn.components.unicorn_view.constructed_views_cache#
- django_unicorn.components.unicorn_view.COMPONENTS_MODULE_CACHE_ENABLED#
- django_unicorn.components.unicorn_view.STANDARD_COMPONENT_KWARG_KEYS#
- django_unicorn.components.unicorn_view.construct_component(component_class, component_id, component_name, component_key, parent, request, component_args, **kwargs)#
Constructs a class instance.
- class django_unicorn.components.unicorn_view.UnicornView(component_args: Optional[List] = None, **kwargs)#
Bases:
django.views.generic.base.TemplateView
Render a template. Pass keyword arguments from the URLconf to the context.
- component_args: List#
- component_kwargs: Dict#
- reset()#
- call(function_name, *args)#
Add a JavaScript method name and arguments to be called after the component is rendered.
- mount()#
Hook that gets called when the component is first created.
- hydrate()#
Hook that gets called when the component’s data is hydrated.
- complete()#
Hook that gets called after all component methods are executed.
- rendered(html)#
Hook that gets called after the component has been rendered.
- parent_rendered(html)#
Hook that gets called after the component’s parent has been rendered.
- updating(name, value)#
Hook that gets called when a component’s data is about to get updated.
- updated(name, value)#
Hook that gets called when a component’s data is updated.
- calling(name, args)#
Hook that gets called when a component’s method is about to get called.
- called(name, args)#
Hook that gets called when a component’s method is called.
- render(*, init_js=False, extra_context=None, request=None) str #
Renders a UnicornView component with the public properties available. Delegates to a UnicornTemplateResponse to actually render a response.
- Parameters:
init_js (param) – Whether or not to include the Javascript required to initialize the component.
extra_context (param) –
request (param) – Set the request for rendering. Usually it will be in the context, but it is missing when the component is re-rendered as a direct view, so it needs to be set explicitly.
- dispatch(request, *args, **kwargs)#
Called by the as_view class method when utilizing a component directly as a view.
- get_frontend_context_variables() str #
Get publicly available properties and output them in a string-encoded JSON object.
- get_context_data(**kwargs)#
Overrides the standard get_context_data to add in publicly available properties and methods.
- validate(model_names: Optional[List] = None) Dict #
Validates the data using the form_class set on the component.
- Parameters:
model_names – Only include validation errors for specified fields. If none, validate everything.
- static create(*, component_id: str, component_name: str, component_key: str = '', parent: UnicornView = None, request: django.http.HttpRequest = None, use_cache=True, component_args: Optional[List] = None, kwargs: Optional[Dict[str, Any]] = None) UnicornView #
Find and instantiate a component class based on component_name.
- Parameters:
component_id (param) – Id of the component. Required.
component_name (param) – Name of the component. Used to locate the correct UnicornView component class and template if necessary. Required.
component_key (param) – Key of the component to allow multiple components of the same name to be differentiated. Optional.
parent (param) – The parent component of the current component.
component_args (param) – Arguments for the component passed in from the template. Defaults to [].
kwargs (param) – Keyword arguments for the component passed in from the template. Defaults to {}.
- Returns:
Instantiated UnicornView component. Raises ComponentModuleLoadError or ComponentClassLoadError if the component could not be loaded.
- classmethod as_view(**initkwargs)#
Main entry point for a request-response process.