Skip to content

Make django_idom an installable app #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 36 commits into from
Aug 19, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
30a481f
create barebones templatetags
Archmonger Jul 22, 2021
8b0b363
styling fix
Archmonger Jul 22, 2021
4bcd9bf
idom_view
Archmonger Jul 26, 2021
f8f094e
skeleton of django installable app
rmorshea Jul 26, 2021
937da20
get test_app runserver to work
rmorshea Jul 26, 2021
e76408b
fix MANIFEST.in to include static/templates
rmorshea Jul 28, 2021
f008f6b
fix style
rmorshea Jul 28, 2021
b4f256b
require a my_app.idom.components attribute
rmorshea Jul 28, 2021
a0b75e0
parametrized components + serve web modules
rmorshea Jul 28, 2021
cd12a7c
add IDOM_IGNORED_DJANGO_APPS option
rmorshea Jul 29, 2021
9f4412d
add basic docs to README
rmorshea Jul 29, 2021
34452e4
minor doc improvements
rmorshea Jul 29, 2021
3e07d5a
more doc updates
rmorshea Jul 29, 2021
0ff84ec
make logger private
rmorshea Aug 5, 2021
fbb0037
use string path to template
rmorshea Aug 5, 2021
407b506
rename URL resolver functions
rmorshea Aug 5, 2021
fa95bb1
fix flake8
rmorshea Aug 5, 2021
9da3de8
correct template tag description
rmorshea Aug 5, 2021
a05d0ef
update app organization in README
rmorshea Aug 5, 2021
937244c
switch to decorator collection method
rmorshea Aug 11, 2021
af6601d
load components using template names
rmorshea Aug 12, 2021
60384af
minor README tweaks
rmorshea Aug 12, 2021
f72b2d6
remove unused config option
rmorshea Aug 12, 2021
4bcdeb5
use different param name in README ex
rmorshea Aug 12, 2021
536968a
cache and asyncify web module loading
rmorshea Aug 19, 2021
aee70a7
rename idom_view to idom_component
rmorshea Aug 19, 2021
7093252
README rename your_template to your_view
rmorshea Aug 19, 2021
66b7cb3
fix README typo
rmorshea Aug 19, 2021
4a4fa74
make websocket and web module paths consts
rmorshea Aug 19, 2021
b209995
correct terminology
rmorshea Aug 19, 2021
b9934de
slim down README asgi.py description
rmorshea Aug 19, 2021
fa70766
better summarize what IDOM is
rmorshea Aug 19, 2021
a15c334
bump copyright year
rmorshea Aug 19, 2021
aed7fc7
fix template formatting
rmorshea Aug 19, 2021
68aa643
rename your_app to your_project
rmorshea Aug 19, 2021
83e3f7c
add CODEOWNERS
rmorshea Aug 19, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
make websocket and web module paths consts
  • Loading branch information
rmorshea committed Aug 19, 2021
commit 4a4fa74c7746af947655ed029cbc2ba9405f45b1
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ your_app/
To start, we'll need to use [`channels`](https://channels.readthedocs.io/en/stable/) to
create a `ProtocolTypeRouter` that will become the top of our ASGI application stack.
Under the `"websocket"` protocol, we'll then add a path for IDOM's websocket consumer
using `idom_websocket_path`. If you wish to change the route where this
using `IDOM_WEB_MODULES_PATH`. If you wish to change the route where this
websocket is served from, see the available [settings](#settings.py).

```python
Expand All @@ -65,7 +65,7 @@ import os

from django.core.asgi import get_asgi_application

from django_idom import idom_websocket_path
from django_idom import IDOM_WEB_MODULES_PATH

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

Expand All @@ -79,7 +79,7 @@ application = ProtocolTypeRouter(
"http": http_asgi_app,
"websocket": URLRouter(
# add a path for IDOM's websocket
[idom_websocket_path()]
[IDOM_WEB_MODULES_PATH]
),
}
)
Expand Down Expand Up @@ -119,15 +119,15 @@ CACHES = {

## `urls.py`

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

```python
from django_idom import idom_web_modules_path
from django_idom import IDOM_WEB_MODULES_PATH

urlpatterns = [
idom_web_modules_path(),
IDOM_WEB_MODULES_PATH,
...
]
```
Expand Down
4 changes: 2 additions & 2 deletions src/django_idom/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from .paths import idom_web_modules_path, idom_websocket_path
from .paths import IDOM_WEB_MODULES_PATH, IDOM_WEBSOCKET_PATH


__version__ = "0.0.1"
__all__ = ["idom_websocket_path", "idom_web_modules_path"]
__all__ = ["IDOM_WEB_MODULES_PATH", "IDOM_WEBSOCKET_PATH"]
2 changes: 1 addition & 1 deletion src/django_idom/config.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from typing import Dict

from django.conf import settings
from idom.core.proto import ComponentConstructor
from django.core.cache import DEFAULT_CACHE_ALIAS
from idom.core.proto import ComponentConstructor


IDOM_REGISTERED_COMPONENTS: Dict[str, ComponentConstructor] = {}
Expand Down
40 changes: 16 additions & 24 deletions src/django_idom/paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,23 @@
from .websocket_consumer import IdomAsyncWebSocketConsumer


def idom_websocket_path(*args, **kwargs):
"""Return a URL resolver for :class:`IdomAsyncWebSocketConsumer`
IDOM_WEBSOCKET_PATH = path(
IDOM_WEBSOCKET_URL + "<view_id>/", IdomAsyncWebSocketConsumer.as_asgi()
)
"""A URL resolver for :class:`IdomAsyncWebSocketConsumer`

While this is relatively uncommon in most Django apps, because the URL of the
websocket must be defined by the setting ``IDOM_WEBSOCKET_URL``. There's no need
to allow users to configure the URL themselves.
"""
return path(
IDOM_WEBSOCKET_URL + "<view_id>/",
IdomAsyncWebSocketConsumer.as_asgi(),
*args,
**kwargs,
)
While this is relatively uncommon in most Django apps, because the URL of the
websocket must be defined by the setting ``IDOM_WEBSOCKET_URL``. There's no need
to allow users to configure the URL themselves.
"""


def idom_web_modules_path(*args, **kwargs):
"""Return a URL resolver for static web modules required by IDOM
IDOM_WEB_MODULES_PATH = path(
IDOM_WEB_MODULES_URL + "<path:file>", views.web_modules_file
)
"""A URL resolver for static web modules required by IDOM

While this is relatively uncommon in most Django apps, because the URL of the
websocket must be defined by the setting ``IDOM_WEBSOCKET_URL``. There's no need
to allow users to configure the URL themselves.
"""
return path(
IDOM_WEB_MODULES_URL + "<path:file>",
views.web_modules_file,
*args,
**kwargs,
)
While this is relatively uncommon in most Django apps, because the URL of the
websocket must be defined by the setting ``IDOM_WEBSOCKET_URL``. There's no need
to allow users to configure the URL themselves.
"""
4 changes: 2 additions & 2 deletions src/django_idom/views.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import os
import asyncio
import functools
import os

from django.core.cache import caches
from django.http import HttpRequest, HttpResponse
from idom.config import IDOM_WED_MODULES_DIR
from django.core.cache import caches

from .config import IDOM_WEB_MODULE_CACHE, IDOM_WEB_MODULE_LRU_CACHE_SIZE

Expand Down
4 changes: 2 additions & 2 deletions tests/test_app/asgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

from django.core.asgi import get_asgi_application

from django_idom import idom_websocket_path
from django_idom import IDOM_WEBSOCKET_PATH


os.environ.setdefault("DJANGO_SETTINGS_MODULE", "test_app.settings")
Expand All @@ -25,6 +25,6 @@
application = ProtocolTypeRouter(
{
"http": http_asgi_app,
"websocket": URLRouter([idom_websocket_path()]),
"websocket": URLRouter([IDOM_WEBSOCKET_PATH]),
}
)
7 changes: 2 additions & 5 deletions tests/test_app/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,9 @@
"""
from django.urls import path

from django_idom import idom_web_modules_path
from django_idom import IDOM_WEB_MODULES_PATH

from .views import base_template


urlpatterns = [
path("", base_template),
idom_web_modules_path(),
]
urlpatterns = [path("", base_template), IDOM_WEB_MODULES_PATH]