You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- Change type hint on `view_to_component` callable to have `request` argument be optional.
- More DRY way of async view rendering.
- Have docs demonstrate how to use Django-IDOM with `channels>=4.0.0`.
- Concatenate some examples on the `view_to_component` docs
- Add note to docs about potential information exposure via `view_to_component` when using `compatibility=True`.
- Clean up docs on running tests
Copy file name to clipboardExpand all lines: docs/src/contribute/running-tests.md
+17-6Lines changed: 17 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -1,15 +1,26 @@
1
-
This repo uses [Nox](https://nox.thea.codes/en/stable/) to run scripts which can be found in `noxfile.py`. For a full test of available scripts run `nox -l`. To run the full test suite simple execute:
1
+
This repo uses [Nox](https://nox.thea.codes/en/stable/) to run tests. For a full test of available scripts run `nox -l`.
2
+
3
+
If you plan to run tests, you'll need to install the following dependencies first:
Then, by running the command below you can run the full test suite:
2
17
3
18
```
4
19
nox -s test
5
20
```
6
21
7
-
If you do not want to run the tests in the background:
22
+
Or, if you want to run the tests in the foreground:
8
23
9
24
```
10
25
nox -s test -- --headed
11
26
```
12
-
13
-
!!! warning "Most tests will not run on Windows"
14
-
15
-
Due to [bugs within Django Channels](https://github.com/django/channels/issues/1207), functional tests are not run on Windows. In order for Windows users to test Django-IDOM functionality, you will need to run tests via [Windows Subsystem for Linux](https://code.visualstudio.com/docs/remote/wsl).
Copy file name to clipboardExpand all lines: docs/src/features/components.md
+82-39Lines changed: 82 additions & 39 deletions
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,7 @@
4
4
5
5
## View To Component
6
6
7
-
Convert any Django view into a IDOM component by usng this decorator. Compatible with sync/async [Function Based Views](https://docs.djangoproject.com/en/dev/topics/http/views/) and [Class Based Views](https://docs.djangoproject.com/en/dev/topics/class-based-views/).
7
+
Convert any Django view into a IDOM component by usng this decorator. Compatible with [Function Based Views](https://docs.djangoproject.com/en/dev/topics/http/views/) and [Class Based Views](https://docs.djangoproject.com/en/dev/topics/class-based-views/). Views can be sync or async.
8
8
9
9
=== "components.py"
10
10
@@ -41,11 +41,42 @@ Convert any Django view into a IDOM component by usng this decorator. Compatible
41
41
| --- | --- |
42
42
| `_ViewComponentConstructor` | A function that takes `request: HttpRequest | None, *args: Any, key: Key | None, **kwargs: Any` and returns an IDOM component. |
43
43
44
-
??? warning "Existing limitations"
44
+
??? Warning "Potential information exposure when using `compatibility = True`"
45
+
46
+
When using `compatibility` mode, IDOM automatically exposes a URL to your view.
47
+
48
+
It is your responsibility to ensure priveledged information is not leaked via this method.
49
+
50
+
This can be done via directly writing conditionals into your view, or by adding decorators such as [user_passes_test](https://docs.djangoproject.com/en/dev/topics/auth/default/#django.contrib.auth.decorators.user_passes_test) to your views prior to using `view_to_component`.
??? question "How do I use `strict_parseing`, `compatibility`, and `transforms`?"
155
190
156
-
For views that rely on HTTP responses other than `GET` (such as `PUT`, `POST`, `PATCH`, etc), you should consider using compatibility mode to render your view within an iframe.
191
+
<font size="4">**`strict_parsing`**</font>
157
192
158
-
Any view can be rendered within compatibility mode. However, the `transforms`, `strict_parsing`, `request`, `args`, and `kwargs` arguments do not apply to compatibility mode.
193
+
By default, an exception will be generated if your view's HTML does not perfectly adhere to HTML5.
159
194
160
-
Please note that by default the iframe is unstyled, and thus won't look pretty until you add some CSS.
195
+
However, there are some circumstances where you may not have control over the original HTML, so you may be unable to fix it. Or you may be relying on non-standard HTML tags such as `#!html <my-tag> Hello World </my-tag>`.
196
+
197
+
In these scenarios, you may want to rely on best-fit parsing by setting the `strict_parsing` parameter to `False`.
198
+
199
+
Note that best-fit parsing is designed to be similar to how web browsers would handle non-standard or broken HTML.
161
200
162
201
=== "components.py"
163
202
@@ -166,9 +205,9 @@ Convert any Django view into a IDOM component by usng this decorator. Compatible
166
205
from django.http import HttpResponse
167
206
from django_idom.components import view_to_component
168
207
169
-
@view_to_component(compatibility=True)
208
+
@view_to_component(strict_parsing=False)
170
209
def hello_world_view(request):
171
-
return HttpResponse("Hello World!")
210
+
return HttpResponse("<my-tag> Hello World </my-tag>")
172
211
173
212
@component
174
213
def my_component():
@@ -177,13 +216,17 @@ Convert any Django view into a IDOM component by usng this decorator. Compatible
177
216
)
178
217
```
179
218
180
-
??? question "What is `strict_parsing`?"
181
219
182
-
By default, an exception will be generated if your view's HTML does not perfectly adhere to HTML5.
183
220
184
-
However, there are some circumstances where you may not have control over the original HTML, so you may be unable to fix it. Or you may be relying on non-standard HTML tags such as `#!html <my-tag> Hello World </my-tag>`.
221
+
---
185
222
186
-
In these scenarios, you may want to rely on best-fit parsing by setting the `strict_parsing` parameter to `False`.
223
+
<font size="4">**`compatibility`**</font>
224
+
225
+
For views that rely on HTTP responses other than `GET` (such as `PUT`, `POST`, `PATCH`, etc), you should consider using compatibility mode to render your view within an iframe.
226
+
227
+
Any view can be rendered within compatibility mode. However, the `transforms`, `strict_parsing`, `request`, `args`, and `kwargs` arguments do not apply to compatibility mode.
228
+
229
+
Please note that by default the iframe is unstyled, and thus won't look pretty until you add some CSS.
187
230
188
231
=== "components.py"
189
232
@@ -192,9 +235,9 @@ Convert any Django view into a IDOM component by usng this decorator. Compatible
192
235
from django.http import HttpResponse
193
236
from django_idom.components import view_to_component
194
237
195
-
@view_to_component(strict_parsing=False)
238
+
@view_to_component(compatibility=True)
196
239
def hello_world_view(request):
197
-
return HttpResponse("<my-tag> Hello World </my-tag>")
240
+
return HttpResponse("Hello World!")
198
241
199
242
@component
200
243
def my_component():
@@ -203,9 +246,9 @@ Convert any Django view into a IDOM component by usng this decorator. Compatible
203
246
)
204
247
```
205
248
206
-
Note that best-fit parsing is very similar to how web browsers will handle broken HTML.
249
+
---
207
250
208
-
??? question "What is `transforms`?"
251
+
<font size="4">**`transforms`**</font>
209
252
210
253
After your view has been turned into [VDOM](https://idom-docs.herokuapp.com/docs/reference/specifications.html#vdom) (python dictionaries), `view_to_component` will call your `transforms` functions on every VDOM node.
Copy file name to clipboardExpand all lines: docs/src/installation/index.md
+2-2Lines changed: 2 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -29,15 +29,15 @@ In your settings you'll need to add `django_idom` to [`INSTALLED_APPS`](https://
29
29
30
30
Django-IDOM requires ASGI in order to use Websockets.
31
31
32
-
If you haven't enabled ASGI on your **Django project** yet, you'll need to add `channels` to `INSTALLED_APPS` and set your `ASGI_APPLICATION` variable.
32
+
If you haven't enabled ASGI on your **Django project** yet, you'll need to install `channels[daphne]`, add `daphne` to `INSTALLED_APPS`, then set your `ASGI_APPLICATION` variable.
33
33
34
34
Read the [Django Channels Docs](https://channels.readthedocs.io/en/stable/installation.html) for more info.
0 commit comments