Skip to content

Commit da083ac

Browse files
authored
Support for non-serializable component parameters (#120)
- Database backed component parameters - The `component` template tag now supports both positional and keyword arguments. - The `component` template tag now supports non-serializable arguments. - It is now mandatory to run `manage.py migrate` after installing IDOM - `IDOM_WS_MAX_RECONNECT_TIMEOUT` has been renamed to `IDOM_RECONNECT_MAX` and is now used as the default timeout for component parameters - Bumped the minimum IDOM version to 0.43.0 - `idom.backend.hooks` support. - `django_idom.types.IdomWebsocket` has been renamed to `Connection` and modified to fit the new schema - `view_to_component` utility will now automatically use `del_html_head_body_transform` - Set `IDOM_DEBUG_MODE` to `settings.py:DEBUG` - The react client is now set to production rather than development - Make a harmless utils public but undocumented - Documentation for `django_query_postprocessor`
1 parent da5248e commit da083ac

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+1245
-852
lines changed

CHANGELOG.md

+25
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,35 @@ Using the following categories, list your changes in this order:
2222

2323
## [Unreleased]
2424

25+
### Added
26+
27+
- The `idom` client will automatically configure itself to debug mode depending on `settings.py:DEBUG`.
28+
- `use_connection` hook for returning the browser's active `Connection`
29+
30+
### Changed
31+
32+
- The `component` template tag now supports both positional and keyword arguments.
33+
- The `component` template tag now supports non-serializable arguments.
34+
- `IDOM_WS_MAX_RECONNECT_TIMEOUT` setting has been renamed to `IDOM_RECONNECT_MAX`.
35+
- It is now mandatory to run `manage.py migrate` after installing IDOM.
36+
- Bumped the minimum IDOM version to 0.43.0
37+
38+
### Removed
39+
40+
- `django_idom.hooks.use_websocket` has been removed. The similar replacement is `django_idom.hooks.use_connection`.
41+
- `django_idom.types.IdomWebsocket` has been removed. The similar replacement is `django_idom.types.Connection`
42+
2543
### Fixed
2644

45+
- `view_to_component` will now retain any HTML that was defined in a `<head>` tag.
46+
- React client is now set to `production` rather than `development`.
2747
- `use_query` will now utilize `field.related_name` when postprocessing many-to-one relationships
2848

49+
### Security
50+
51+
- Fixed a potential method of component template tag argument spoofing.
52+
- Exception information will no longer be displayed on the page, based on the value of `settings.py:DEBUG`.
53+
2954
## [2.2.1] - 2022-01-09
3055

3156
### Fixed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def hello_world(recipient: str):
4646

4747
In your **Django app**'s HTML template, you can now embed your IDOM component using the `component` template tag. Within this tag, you will need to type in your dotted path to the component function as the first argument.
4848

49-
Additionally, you can pass in keyword arguments into your component function. For example, after reading the code below, pay attention to how the function definition for `hello_world` (_in the previous example_) accepts a `recipient` argument.
49+
Additionally, you can pass in `args` and `kwargs` into your component function. For example, after reading the code below, pay attention to how the function definition for `hello_world` (_in the previous example_) accepts a `recipient` argument.
5050

5151
<!--html-header-end-->
5252
<!--html-code-start-->

docs/src/contribute/code.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ If you plan to make code changes to this repository, you will need to install th
1010

1111
Once done, you should clone this repository:
1212

13-
```bash
13+
```bash linenums="0"
1414
git clone https://github.com/idom-team/django-idom.git
1515
cd django-idom
1616
```
@@ -20,13 +20,13 @@ Then, by running the command below you can:
2020
- Install an editable version of the Python code
2121
- Download, build, and install Javascript dependencies
2222

23-
```bash
23+
```bash linenums="0"
2424
pip install -e . -r requirements.txt
2525
```
2626

2727
Finally, to verify that everything is working properly, you can manually run the development webserver.
2828

29-
```bash
29+
```bash linenums="0"
3030
cd tests
3131
python manage.py runserver
3232
```

docs/src/contribute/docs.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ If you plan to make changes to this documentation, you will need to install the
55

66
Once done, you should clone this repository:
77

8-
```bash
8+
```bash linenums="0"
99
git clone https://github.com/idom-team/django-idom.git
1010
cd django-idom
1111
```
@@ -15,13 +15,13 @@ Then, by running the command below you can:
1515
- Install an editable version of the documentation
1616
- Self-host a test server for the documentation
1717

18-
```bash
18+
```bash linenums="0"
1919
pip install -r ./requirements/build-docs.txt --upgrade
2020
```
2121

2222
Finally, to verify that everything is working properly, you can manually run the docs preview webserver.
2323

24-
```bash
24+
```bash linenums="0"
2525
mkdocs serve
2626
```
2727

docs/src/contribute/running-tests.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,20 @@ If you plan to run tests, you will need to install the following dependencies fi
77

88
Once done, you should clone this repository:
99

10-
```bash
10+
```bash linenums="0"
1111
git clone https://github.com/idom-team/django-idom.git
1212
cd django-idom
1313
pip install -r ./requirements/test-run.txt --upgrade
1414
```
1515

1616
Then, by running the command below you can run the full test suite:
1717

18-
```
18+
```bash linenums="0"
1919
nox -s test
2020
```
2121

2222
Or, if you want to run the tests in the foreground:
2323

24-
```
24+
```bash linenums="0"
2525
nox -s test -- --headed
2626
```

docs/src/dictionary.txt

+3
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,6 @@ idom
2525
asgi
2626
postfixed
2727
postprocessing
28+
serializable
29+
postprocessor
30+
preprocessor

docs/src/features/components.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,7 @@ Convert any Django view into a IDOM component by using this decorator. Compatibl
7777

7878
- Requires manual intervention to change request methods beyond `GET`.
7979
- IDOM events cannot conveniently be attached to converted view HTML.
80-
- Does not currently load any HTML contained with a `<head>` tag
81-
- Has no option to automatically intercept local anchor link (such as `#!html <a href='example/'></a>`) click events
80+
- Has no option to automatically intercept local anchor link (such as `#!html <a href='example/'></a>`) click events.
8281

8382
_Please note these limitations do not exist when using `compatibility` mode._
8483

docs/src/features/decorators.md

+1-7
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,16 @@
44

55
## Auth Required
66

7-
You can limit access to a component to users with a specific `auth_attribute` by using this decorator.
7+
You can limit access to a component to users with a specific `auth_attribute` by using this decorator (with or without parentheses).
88

99
By default, this decorator checks if the user is logged in, and his/her account has not been deactivated.
1010

1111
This decorator is commonly used to selectively render a component only if a user [`is_staff`](https://docs.djangoproject.com/en/dev/ref/contrib/auth/#django.contrib.auth.models.User.is_staff) or [`is_superuser`](https://docs.djangoproject.com/en/dev/ref/contrib/auth/#django.contrib.auth.models.User.is_superuser).
1212

13-
This decorator can be used with or without parentheses.
14-
1513
=== "components.py"
1614

1715
```python
1816
from django_idom.decorators import auth_required
19-
from django_idom.hooks import use_websocket
2017
from idom import component, html
2118

2219
@component
@@ -70,7 +67,6 @@ This decorator can be used with or without parentheses.
7067

7168
```python
7269
from django_idom.decorators import auth_required
73-
from django_idom.hooks import use_websocket
7470
from idom import component, html
7571

7672
@component
@@ -87,7 +83,6 @@ This decorator can be used with or without parentheses.
8783

8884
```python
8985
from django_idom.decorators import auth_required
90-
from django_idom.hooks import use_websocket
9186
from idom import component, html
9287

9388

@@ -120,7 +115,6 @@ This decorator can be used with or without parentheses.
120115

121116
```python
122117
from django_idom.decorators import auth_required
123-
from django_idom.hooks import use_websocket
124118
from idom import component, html
125119

126120
@component

docs/src/features/hooks.md

+33-33
Original file line numberDiff line numberDiff line change
@@ -399,20 +399,22 @@ The function you provide into this hook will have no return value.
399399

400400
{% include-markdown "../../includes/orm.md" start="<!--orm-excp-start-->" end="<!--orm-excp-end-->" %}
401401

402-
## Use Websocket
402+
## Use Origin
403+
404+
This is a shortcut that returns the Websocket's `origin`.
403405

404-
You can fetch the Django Channels [websocket](https://channels.readthedocs.io/en/stable/topics/consumers.html#asyncjsonwebsocketconsumer) at any time by using `use_websocket`.
406+
You can expect this hook to provide strings such as `http://example.com`.
405407

406408
=== "components.py"
407409

408410
```python
409411
from idom import component, html
410-
from django_idom.hooks import use_websocket
412+
from django_idom.hooks import use_origin
411413

412414
@component
413415
def my_component():
414-
my_websocket = use_websocket()
415-
return html.div(my_websocket)
416+
my_origin = use_origin()
417+
return html.div(my_origin)
416418
```
417419

418420
??? example "See Interface"
@@ -425,22 +427,22 @@ You can fetch the Django Channels [websocket](https://channels.readthedocs.io/en
425427

426428
| Type | Description |
427429
| --- | --- |
428-
| `IdomWebsocket` | The component's websocket. |
430+
| `str | None` | A string containing the browser's current origin, obtained from websocket headers (if available). |
429431

430-
## Use Scope
432+
## Use Connection
431433

432-
This is a shortcut that returns the Websocket's [`scope`](https://channels.readthedocs.io/en/stable/topics/consumers.html#scope).
434+
You can fetch the Django Channels [websocket](https://channels.readthedocs.io/en/stable/topics/consumers.html#asyncjsonwebsocketconsumer) at any time by using `use_connection`.
433435

434436
=== "components.py"
435437

436438
```python
437439
from idom import component, html
438-
from django_idom.hooks import use_scope
440+
from django_idom.hooks import use_connection
439441

440442
@component
441443
def my_component():
442-
my_scope = use_scope()
443-
return html.div(my_scope)
444+
my_connection = use_connection()
445+
return html.div(my_connection)
444446
```
445447

446448
??? example "See Interface"
@@ -453,24 +455,22 @@ This is a shortcut that returns the Websocket's [`scope`](https://channels.readt
453455

454456
| Type | Description |
455457
| --- | --- |
456-
| `dict[str, Any]` | The websocket's `scope`. |
458+
| `Connection` | The component's websocket. |
457459

458-
## Use Location
459-
460-
This is a shortcut that returns the Websocket's `path`.
460+
## Use Scope
461461

462-
You can expect this hook to provide strings such as `/idom/my_path`.
462+
This is a shortcut that returns the Websocket's [`scope`](https://channels.readthedocs.io/en/stable/topics/consumers.html#scope).
463463

464464
=== "components.py"
465465

466466
```python
467467
from idom import component, html
468-
from django_idom.hooks import use_location
468+
from django_idom.hooks import use_scope
469469

470470
@component
471471
def my_component():
472-
my_location = use_location()
473-
return html.div(my_location)
472+
my_scope = use_scope()
473+
return html.div(my_scope)
474474
```
475475

476476
??? example "See Interface"
@@ -483,30 +483,24 @@ You can expect this hook to provide strings such as `/idom/my_path`.
483483

484484
| Type | Description |
485485
| --- | --- |
486-
| `Location` | A object containing the current URL's `pathname` and `search` query. |
486+
| `MutableMapping[str, Any]` | The websocket's `scope`. |
487487

488-
??? info "This hook's behavior will be changed in a future update"
489-
490-
This hook will be updated to return the browser's currently active path. This change will come in alongside IDOM URL routing support.
491-
492-
Check out [idom-team/idom-router#2](https://github.com/idom-team/idom-router/issues/2) for more information.
493-
494-
## Use Origin
488+
## Use Location
495489

496-
This is a shortcut that returns the Websocket's `origin`.
490+
This is a shortcut that returns the Websocket's `path`.
497491

498-
You can expect this hook to provide strings such as `http://example.com`.
492+
You can expect this hook to provide strings such as `/idom/my_path`.
499493

500494
=== "components.py"
501495

502496
```python
503497
from idom import component, html
504-
from django_idom.hooks import use_origin
498+
from django_idom.hooks import use_location
505499

506500
@component
507501
def my_component():
508-
my_origin = use_origin()
509-
return html.div(my_origin)
502+
my_location = use_location()
503+
return html.div(my_location)
510504
```
511505

512506
??? example "See Interface"
@@ -519,4 +513,10 @@ You can expect this hook to provide strings such as `http://example.com`.
519513

520514
| Type | Description |
521515
| --- | --- |
522-
| `str | None` | A string containing the browser's current origin, obtained from websocket headers (if available). |
516+
| `Location` | A object containing the current URL's `pathname` and `search` query. |
517+
518+
??? info "This hook's behavior will be changed in a future update"
519+
520+
This hook will be updated to return the browser's currently active path. This change will come in alongside IDOM URL routing support.
521+
522+
Check out [idom-team/idom-router#2](https://github.com/idom-team/idom-router/issues/2) for more information.

docs/src/features/settings.md

+6-5
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,17 @@
99
<!--settings-start-->
1010

1111
```python
12-
# If "idom" cache is not configured, then we will use "default" instead
12+
# If "idom" cache is not configured, then "default" will be used
13+
# IDOM expects a multiprocessing-safe and thread-safe cache backend.
1314
CACHES = {
1415
"idom": {"BACKEND": ...},
1516
}
1617

17-
# Maximum seconds between two reconnection attempts that would cause the client give up.
18-
# 0 will disable reconnection.
19-
IDOM_WS_MAX_RECONNECT_TIMEOUT = 604800
18+
# Maximum seconds between reconnection attempts before giving up.
19+
# Use `0` to prevent component reconnection.
20+
IDOM_RECONNECT_MAX = 259200
2021

21-
# The URL for IDOM to serve websockets
22+
# The URL for IDOM to serve the component rendering websocket
2223
IDOM_WEBSOCKET_URL = "idom/"
2324

2425
# Dotted path to the default postprocessor function, or `None`

0 commit comments

Comments
 (0)