Skip to content

Commit

Permalink
Merge pull request #198 from honeylogic-io/asgi-channels-sample
Browse files Browse the repository at this point in the history
feat: Channels/terminal/xterm sample
  • Loading branch information
adinhodovic authored Feb 22, 2024
2 parents d3dc7ca + 11627d8 commit 5df5c15
Show file tree
Hide file tree
Showing 9 changed files with 499 additions and 49 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

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()

from django_admin_shellx.urls import ( # pylint: disable=wrong-import-position
websocket_urlpatterns,
)

application = ProtocolTypeRouter(
{
"http": django_asgi_app,
"websocket": AllowedHostsOriginValidator(
AuthMiddlewareStack(URLRouter(websocket_urlpatterns))
),
}
)
15 changes: 15 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_admin_shellx",
"health_check",
"meta",
"modelcluster",
Expand Down Expand Up @@ -437,3 +440,15 @@

# 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": [env("REDIS_URL")],
},
},
}

DJANGO_WEB_REPL_SUPERUSER_ONLY = True
8 changes: 4 additions & 4 deletions django_wtf/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ def get_queryset(self):


class Profile(TimeStampedModel):
objects = models.Manager() # type: ignore
contributes_to_valid_repos = ProfileContributesToValidProjectsManager() # type: ignore
objects = models.Manager()
contributes_to_valid_repos = ProfileContributesToValidProjectsManager()
github_id = models.PositiveIntegerField()
login = models.CharField(max_length=100, unique=True)
type = models.CharField(
Expand Down Expand Up @@ -104,8 +104,8 @@ def get_queryset(self):


class Repository(TimeStampedModel):
objects = models.Manager() # type: ignore
valid = RepositoryManager() # type: ignore
objects = models.Manager()
valid = RepositoryManager()
github_id = models.PositiveIntegerField()
owner = models.ForeignKey(
Profile,
Expand Down
2 changes: 1 addition & 1 deletion django_wtf/core/sitemap_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def location(self, item):


category_sitemap = GenericSitemap( # type: ignore
{"queryset": Category.objects.all(), "changefreq": "daily"}
{"queryset": Category.objects.all(), "changefreq": "daily"} # type: ignore
)


Expand Down
2 changes: 1 addition & 1 deletion django_wtf/core/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def trending_repositories(**filters):
)
if stars_in_the_last_week > 0:
setattr(repo, "stars_lately", stars_in_the_last_week)
setattr(repo, "stars_quota", repo.stars_lately / repo.stars)
setattr(repo, "stars_quota", repo.stars_lately / repo.stars) # type: ignore
trending.append(repo)

return sorted(trending, key=lambda e: e.stars_quota, reverse=True)
Expand Down
8 changes: 8 additions & 0 deletions django_wtf/customadmin/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from admin_site_search.views import AdminSiteSearchView
from django_admin_shellx_custom_admin.admin import (
CustomAdminSite as ShellXCustomAdminSite,
)


class CustomAdminSite(AdminSiteSearchView, ShellXCustomAdminSite):
pass
8 changes: 1 addition & 7 deletions django_wtf/customadmin/apps.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
from admin_site_search.views import AdminSiteSearchView
from django.contrib import admin
from django.contrib.admin.apps import AdminConfig


class CustomAdminSite(AdminSiteSearchView, admin.AdminSite):
pass


class CustomAdminConfig(AdminConfig):
default_site = "django_wtf.customadmin.apps.CustomAdminSite"
default_site = "django_wtf.customadmin.admin.CustomAdminSite"
Loading

0 comments on commit 5df5c15

Please sign in to comment.