Server
- Server.get_running_views_count()
- Server.view_is_already_running()
- Server.get_connection_count()
- Server.get_connected_user_count()
- Server.get_template()
- Server.render_string()
- Server.render_template()
- Server.get_view_class()
- Server.get_views()
- Server.reverse()
- Server.fire_view_event()
- Server.run_coroutine_sync()
- Server.run_function_async()
- Server.embed_shell()
Server.get_running_views_count()
lona.server.Server.get_running_views_count( self, user: 'Any', ) -> intReturns the count of running views for the given user as integer.
Server.view_is_already_running()
lona.server.Server.view_is_already_running( self, request: 'Request', ) -> boolChecks if a view for the given request is already running and returns a boolean. :request: (lona.request.Request)
Server.get_connection_count()
lona.server.Server.get_connection_count( self, user: 'Any', ) -> intReturns the count of connections for the given user as integer. :user: user object
Server.get_connected_user_count()
lona.server.Server.get_connected_user_count( self, ) -> intReturns the count of connected users as integer.
Server.get_template()
lona.server.Server.get_template( self, template_name: 'str', ) -> TemplateReturns a Jinja2 template object associated with the given template name.
Server.render_string()
lona.server.Server.render_string( self, template_string: 'str', template_context: 'dict | None' = None, ) -> strTakes a Jinja2 template as a string and returns the rendering result as string. If no template context is given, an empty one is used. All values in settings.TEMPLATE_EXTRA_CONTEXT get added to the template context before rendering. :template_string: (str) Jinja2 template as string :template_context: (dict|none) template context as dictionary
Server.render_template()
lona.server.Server.render_template( self, template_name: 'str', template_context: 'dict | None' = None, ) -> strTakes the name of a Jinja2 template as a string, searches for a matching template in settings.TEMPLATE_DIRS and returns the rendering result as string. If no template context is given, an empty one is used. All values in settings.TEMPLATE_EXTRA_CONTEXT get added to the template context before rendering. :template_name: (str) Jinja2 template as string :template_context: (dict|none) template context as dictionary
Server.get_view_class()
lona.server.Server.get_view_class( self, route_name: 'str | None' = None, route: 'Route | None' = None, import_string: 'str | None' = None, url: 'str | None' = None, ) -> type[View] | NoneReturns the lona.view.View subclass associated with the given route_name, route, import string or url. Only one argument can be set at a time.
Server.get_views()
Note
Added in 1.9
lona.server.Server.get_views( self, route_name: 'str | None' = None, route: 'Route | None' = None, import_string: 'str | None' = None, url: 'str | None' = None, user: 'Any' = None, ) -> list[View]Returns a list of all running Lona views associated with the given route_name, route, import string or url. Only one argument to find the view can be set at a time. User can always be set. :route: (lona.Route|none) Lona route associated with the view :import_string: (str|none) import string of the view :url: (str|none) URL to the view :user: (any) User that runs th view (optional)
Server.reverse()
Note
The argument name was renamed to route_name in 1.8
lona.server.Server.reverse( self, route_name: 'str', *args: 'Any', **kwargs: 'dict[str, Any]', ) -> strReturns a routing reverse match as string. :route_name: (str) route name as string :args: route arguments :kwargs: route keyword argument
Server.fire_view_event()
Note
Deprecated since 1.14. Use Channels instead
Note
Added in 1.7.3
lona.server.Server.fire_view_event( self, name: 'str', data: 'dict | None' = None, view_classes: 'type[View] | list[type[View]] | None' = None, ) -> NoneSends a view event to all objects of the given View class. If view_classes is not set, the event becomes a broadcast event and gets send to all view classes. :name: has to be a str, data is optional but has to be a dict if set. :view_classes: can be a single view class or a list of view classes. Examples: # broadcast event server.fire_view_event('foo', {'foo': 'bar'}) # event for all view objects behind the URL '/foo' server.fire_view_event( 'foo', {'foo': 'bar'}, view_classes=server.get_view_class(url='/foo'), )
Server.run_coroutine_sync()
lona.server.Server.run_coroutine_sync( self, coroutine: 'Awaitable[T]', wait: 'None | bool' = True, ) -> Future[T] | TTakes a coroutine, runs it thread-safe on `Server.loop` and returns a `concurrent.futures.Future`. If `wait` is set to `True`, the method blocks until the coroutine is done, and its return value is returned, instead of the future. :coroutine: (Awaitable) coroutine :wait: (bool) Wait for the coroutine to return
Server.run_function_async()
lona.server.Server.run_function_async( self, function: 'Callable', *args: 'Any', executor_name: 'str' = 'worker', **kwargs: 'Any', ) -> FutureTakes a function or callable, runs it asynchronously in an thread executor and returns an awaitable future for the result of the given function. :function: (callable) callable :args: (list|tuple) args for the callable :executor_name: (str) name of the worker pool (default is 'worker') :kwargs: (dict) keyword argument for the callable