Skip to content

Commit

Permalink
feat: Channels/terminal/xterm sample
Browse files Browse the repository at this point in the history
  • Loading branch information
adinhodovic committed Feb 20, 2024
1 parent d3dc7ca commit 03e6b2e
Show file tree
Hide file tree
Showing 6 changed files with 504 additions and 26 deletions.
24 changes: 24 additions & 0 deletions config/asgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import os

from channels.auth import AuthMiddlewareStack
from channels.routing import ProtocolTypeRouter, URLRouter
from channels.security.websocket import AllowedHostsOriginValidator
from django.core.asgi import get_asgi_application

from django_web_repl.urls import websocket_urlpatterns

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings.production")
# Initialize Django ASGI application early to ensure the AppRegistry
# is populated before importing code that may import ORM models.
django_asgi_app = get_asgi_application()

import django_web_repl.urls

application = ProtocolTypeRouter(
{
"http": django_asgi_app,
"websocket": AllowedHostsOriginValidator(
AuthMiddlewareStack(URLRouter(websocket_urlpatterns))
),
}
)
13 changes: 13 additions & 0 deletions config/settings/base.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Base settings to build other settings files upon.
"""

from pathlib import Path

import environ
Expand Down Expand Up @@ -60,6 +61,7 @@
# APPS
# ------------------------------------------------------------------------------
DJANGO_APPS = [
"daphne",
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
Expand Down Expand Up @@ -87,6 +89,7 @@
"django_user_agents",
"django_json_ld",
"django_custom_error_views",
"django_web_repl",
"health_check",
"meta",
"modelcluster",
Expand Down Expand Up @@ -437,3 +440,13 @@

# Django-prometheus
PROMETHEUS_EXPORT_MIGRATIONS = env.bool("PROMETHEUS_EXPORT_MIGRATIONS", True)

ASGI_APPLICATION = "config.asgi.application"
CHANNEL_LAYERS = {
"default": {
"BACKEND": "channels_redis.core.RedisChannelLayer",
"CONFIG": {
"hosts": [("127.0.0.1", 6379)],
},
},
}
1 change: 1 addition & 0 deletions config/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@


urlpatterns: list[Any] = [
path("admin/terminal/", include("django_web_repl.urls")),
# Django Admin, use {% url 'admin:index' %}
path(settings.ADMIN_URL, admin.site.urls),
# User management
Expand Down
32 changes: 31 additions & 1 deletion django_wtf/customadmin/apps.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,40 @@
from admin_site_search.views import AdminSiteSearchView
from django.contrib import admin
from django.contrib.admin.apps import AdminConfig
from django.urls import path
from django_web_repl.views import TerminalView


class CustomAdminSite(AdminSiteSearchView, admin.AdminSite):
pass
def get_urls(self):

urls = super().get_urls()
urls.insert(
0,
path(
"terminal/",
self.admin_view(TerminalView.as_view()),
name="terminal",
),
)
return urls

def get_app_list(self, request, app_label=None):
app_list = [
{
"name": "Terminal",
"app_label": "terminal",
"models": [
{
"name": "Terminal",
"object_name": "Terminal",
"admin_url": "/admin/terminal/",
"view_only": True,
}
],
}
] + super().get_app_list(request)
return app_list


class CustomAdminConfig(AdminConfig):
Expand Down
Loading

0 comments on commit 03e6b2e

Please sign in to comment.