Skip to content

Commit 4a4fa74

Browse files
committed
make websocket and web module paths consts
1 parent 66b7cb3 commit 4a4fa74

File tree

7 files changed

+32
-43
lines changed

7 files changed

+32
-43
lines changed

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ your_app/
5656
To start, we'll need to use [`channels`](https://channels.readthedocs.io/en/stable/) to
5757
create a `ProtocolTypeRouter` that will become the top of our ASGI application stack.
5858
Under the `"websocket"` protocol, we'll then add a path for IDOM's websocket consumer
59-
using `idom_websocket_path`. If you wish to change the route where this
59+
using `IDOM_WEB_MODULES_PATH`. If you wish to change the route where this
6060
websocket is served from, see the available [settings](#settings.py).
6161

6262
```python
@@ -65,7 +65,7 @@ import os
6565

6666
from django.core.asgi import get_asgi_application
6767

68-
from django_idom import idom_websocket_path
68+
from django_idom import IDOM_WEB_MODULES_PATH
6969

7070
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "test_app.settings")
7171

@@ -79,7 +79,7 @@ application = ProtocolTypeRouter(
7979
"http": http_asgi_app,
8080
"websocket": URLRouter(
8181
# add a path for IDOM's websocket
82-
[idom_websocket_path()]
82+
[IDOM_WEB_MODULES_PATH]
8383
),
8484
}
8585
)
@@ -119,15 +119,15 @@ CACHES = {
119119

120120
## `urls.py`
121121

122-
You'll need to include IDOM's static web modules path using `idom_web_modules_path`.
123-
Similarly to the `idom_websocket_path()`. If you wish to change the route where this
122+
You'll need to include IDOM's static web modules path using `IDOM_WEB_MODULES_PATH`.
123+
Similarly to the `IDOM_WEBSOCKET_PATH`. If you wish to change the route where this
124124
websocket is served from, see the available [settings](#settings.py).
125125

126126
```python
127-
from django_idom import idom_web_modules_path
127+
from django_idom import IDOM_WEB_MODULES_PATH
128128

129129
urlpatterns = [
130-
idom_web_modules_path(),
130+
IDOM_WEB_MODULES_PATH,
131131
...
132132
]
133133
```

src/django_idom/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
from .paths import idom_web_modules_path, idom_websocket_path
1+
from .paths import IDOM_WEB_MODULES_PATH, IDOM_WEBSOCKET_PATH
22

33

44
__version__ = "0.0.1"
5-
__all__ = ["idom_websocket_path", "idom_web_modules_path"]
5+
__all__ = ["IDOM_WEB_MODULES_PATH", "IDOM_WEBSOCKET_PATH"]

src/django_idom/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
from typing import Dict
22

33
from django.conf import settings
4-
from idom.core.proto import ComponentConstructor
54
from django.core.cache import DEFAULT_CACHE_ALIAS
5+
from idom.core.proto import ComponentConstructor
66

77

88
IDOM_REGISTERED_COMPONENTS: Dict[str, ComponentConstructor] = {}

src/django_idom/paths.py

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,23 @@
55
from .websocket_consumer import IdomAsyncWebSocketConsumer
66

77

8-
def idom_websocket_path(*args, **kwargs):
9-
"""Return a URL resolver for :class:`IdomAsyncWebSocketConsumer`
8+
IDOM_WEBSOCKET_PATH = path(
9+
IDOM_WEBSOCKET_URL + "<view_id>/", IdomAsyncWebSocketConsumer.as_asgi()
10+
)
11+
"""A URL resolver for :class:`IdomAsyncWebSocketConsumer`
1012
11-
While this is relatively uncommon in most Django apps, because the URL of the
12-
websocket must be defined by the setting ``IDOM_WEBSOCKET_URL``. There's no need
13-
to allow users to configure the URL themselves.
14-
"""
15-
return path(
16-
IDOM_WEBSOCKET_URL + "<view_id>/",
17-
IdomAsyncWebSocketConsumer.as_asgi(),
18-
*args,
19-
**kwargs,
20-
)
13+
While this is relatively uncommon in most Django apps, because the URL of the
14+
websocket must be defined by the setting ``IDOM_WEBSOCKET_URL``. There's no need
15+
to allow users to configure the URL themselves.
16+
"""
2117

2218

23-
def idom_web_modules_path(*args, **kwargs):
24-
"""Return a URL resolver for static web modules required by IDOM
19+
IDOM_WEB_MODULES_PATH = path(
20+
IDOM_WEB_MODULES_URL + "<path:file>", views.web_modules_file
21+
)
22+
"""A URL resolver for static web modules required by IDOM
2523
26-
While this is relatively uncommon in most Django apps, because the URL of the
27-
websocket must be defined by the setting ``IDOM_WEBSOCKET_URL``. There's no need
28-
to allow users to configure the URL themselves.
29-
"""
30-
return path(
31-
IDOM_WEB_MODULES_URL + "<path:file>",
32-
views.web_modules_file,
33-
*args,
34-
**kwargs,
35-
)
24+
While this is relatively uncommon in most Django apps, because the URL of the
25+
websocket must be defined by the setting ``IDOM_WEBSOCKET_URL``. There's no need
26+
to allow users to configure the URL themselves.
27+
"""

src/django_idom/views.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import os
21
import asyncio
32
import functools
3+
import os
44

5+
from django.core.cache import caches
56
from django.http import HttpRequest, HttpResponse
67
from idom.config import IDOM_WED_MODULES_DIR
7-
from django.core.cache import caches
88

99
from .config import IDOM_WEB_MODULE_CACHE, IDOM_WEB_MODULE_LRU_CACHE_SIZE
1010

tests/test_app/asgi.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
from django.core.asgi import get_asgi_application
1313

14-
from django_idom import idom_websocket_path
14+
from django_idom import IDOM_WEBSOCKET_PATH
1515

1616

1717
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "test_app.settings")
@@ -25,6 +25,6 @@
2525
application = ProtocolTypeRouter(
2626
{
2727
"http": http_asgi_app,
28-
"websocket": URLRouter([idom_websocket_path()]),
28+
"websocket": URLRouter([IDOM_WEBSOCKET_PATH]),
2929
}
3030
)

tests/test_app/urls.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,9 @@
1919
"""
2020
from django.urls import path
2121

22-
from django_idom import idom_web_modules_path
22+
from django_idom import IDOM_WEB_MODULES_PATH
2323

2424
from .views import base_template
2525

2626

27-
urlpatterns = [
28-
path("", base_template),
29-
idom_web_modules_path(),
30-
]
27+
urlpatterns = [path("", base_template), IDOM_WEB_MODULES_PATH]

0 commit comments

Comments
 (0)