Logs Terminal Emulator React App

Backend for the terminal emulator view in the dashboard logs app.

This module provides the Django view that renders a browser-based terminal emulation window styled after macOS Terminal.app. The terminal is backed by a React component and is used in the web console to give users direct access to Linux command-line tools such as curl without leaving the browser.

The rendered page connects to a WebSocket endpoint that streams log data and accepts command input, with authentication enforced via Django’s session and CSRF mechanisms.

Classes:
TerminalEmulatorLogView: Authenticated view that renders the React-based

terminal emulator page.

Example

Wire up the view in your URL configuration:

from smarter.apps.dashboard.views.terminal_emulator.reactapp import TerminalEmulatorLogView

urlpatterns = [
    path("terminal/", TerminalEmulatorLogView.as_view(), name="smarter-terminal-emulator"),
]
class smarter.apps.dashboard.views.terminal_emulator.reactapp.TerminalEmulatorLogView(**kwargs)[source]

Bases: SmarterAuthenticatedNeverCachedWebView

Authenticated view that renders the React-based terminal emulator page.

Extends SmarterAuthenticatedNeverCachedWebView to ensure that only authenticated users can access the terminal and that responses are never served from cache.

On a GET request the view builds a context dictionary containing the WebSocket API URL and the relevant cookie/session names required by the React frontend, then renders react/terminal-emulator.html.

template_path

Set at request time to "react/terminal-emulator.html".

Type:

str

Context keys passed to the template:

{
    "terminal": {
        "root_id": str,                  # DOM element id for the React root
        "csrf_cookie_name": str,          # Django CSRF cookie name
        "django_session_cookie_name": str,# Django session cookie name
        "cookie_domain": str,             # Session cookie domain
        "api_url": str,                   # WebSocket endpoint URL
    }
}
property formatted_class_name: str

Returns a formatted string of the class name for logging purposes.

get(request, *args, **kwargs)[source]

Render the terminal emulator page for the authenticated user.

Builds a context dictionary that wires the React frontend to the correct WebSocket API endpoint and supplies the cookie/session names needed for CSRF and session authentication. The context is then passed to react/terminal-emulator.html.

Parameters:
  • request (HttpRequest) – The incoming HTTP GET request from the client.

  • args – Additional positional arguments forwarded by the URL dispatcher.

  • kwargs – Additional keyword arguments forwarded by the URL dispatcher.

Returns:

An HTTP 200 response rendering react/terminal-emulator.html with the terminal context dictionary.

Return type:

HttpResponse