2
2
3
3
import json
4
4
import os
5
- from typing import Any , Callable , Sequence , Union , cast , overload
5
+ from typing import Any , Callable , Sequence , Union , cast
6
6
from urllib .parse import urlencode
7
7
from uuid import uuid4
8
- from warnings import warn
9
8
10
9
from django .contrib .staticfiles .finders import find
11
10
from django .core .cache import caches
26
25
)
27
26
28
27
29
- # Type hints for:
30
- # 1. example = view_to_component(my_view, ...)
31
- # 2. @view_to_component
32
- @overload
33
28
def view_to_component (
34
29
view : Callable | View | str ,
35
- compatibility : bool = False ,
36
30
transforms : Sequence [Callable [[VdomDict ], Any ]] = (),
37
31
strict_parsing : bool = True ,
38
- ) -> Any : ...
39
-
40
-
41
- # Type hints for:
42
- # 1. @view_to_component(...)
43
- @overload
44
- def view_to_component (
45
- view : None = ...,
46
- compatibility : bool = False ,
47
- transforms : Sequence [Callable [[VdomDict ], Any ]] = (),
48
- strict_parsing : bool = True ,
49
- ) -> Callable [[Callable ], Any ]: ...
50
-
51
-
52
- def view_to_component (
53
- view : Callable | View | str | None = None ,
54
- compatibility : bool = False ,
55
- transforms : Sequence [Callable [[VdomDict ], Any ]] = (),
56
- strict_parsing : bool = True ,
57
- ) -> Any | Callable [[Callable ], Any ]:
32
+ ) -> Any :
58
33
"""Converts a Django view to a ReactPy component.
59
34
60
35
Keyword Args:
61
36
view: The view to convert, or the view's dotted path as a string.
62
- compatibility: **DEPRECATED.** Use `view_to_iframe` instead.
63
37
transforms: A list of functions that transforms the newly generated VDOM. \
64
38
The functions will be called on each VDOM node.
65
39
strict_parsing: If True, an exception will be generated if the HTML does not \
@@ -69,37 +43,23 @@ def view_to_component(
69
43
A function that takes `request, *args, key, **kwargs` and returns a ReactPy component.
70
44
"""
71
45
72
- def decorator (view : Callable | View | str ):
73
- if not view :
74
- raise ValueError ("A view must be provided to `view_to_component`" )
75
-
76
- def constructor (
77
- request : HttpRequest | None = None ,
78
- * args ,
79
- key : Key | None = None ,
80
- ** kwargs ,
81
- ):
82
- return _view_to_component (
83
- view = view ,
84
- compatibility = compatibility ,
85
- transforms = transforms ,
86
- strict_parsing = strict_parsing ,
87
- request = request ,
88
- args = args ,
89
- kwargs = kwargs ,
90
- key = key ,
91
- )
92
-
93
- return constructor
94
-
95
- if not view :
96
- warn (
97
- "Using `view_to_component` as a decorator is deprecated. "
98
- "This functionality will be removed in a future version." ,
99
- DeprecationWarning ,
46
+ def constructor (
47
+ request : HttpRequest | None = None ,
48
+ * args ,
49
+ key : Key | None = None ,
50
+ ** kwargs ,
51
+ ):
52
+ return _view_to_component (
53
+ view = view ,
54
+ transforms = transforms ,
55
+ strict_parsing = strict_parsing ,
56
+ request = request ,
57
+ args = args ,
58
+ kwargs = kwargs ,
59
+ key = key ,
100
60
)
101
61
102
- return decorator ( view ) if view else decorator
62
+ return constructor
103
63
104
64
105
65
def view_to_iframe (
@@ -180,7 +140,6 @@ def pyscript_component(
180
140
@component
181
141
def _view_to_component (
182
142
view : Callable | View | str ,
183
- compatibility : bool ,
184
143
transforms : Sequence [Callable [[VdomDict ], Any ]],
185
144
strict_parsing : bool ,
186
145
request : HttpRequest | None ,
@@ -209,10 +168,6 @@ def _view_to_component(
209
168
)
210
169
async def async_render ():
211
170
"""Render the view in an async hook to avoid blocking the main thread."""
212
- # Compatibility mode doesn't require a traditional render
213
- if compatibility :
214
- return
215
-
216
171
# Render the view
217
172
response = await render_view (resolved_view , _request , _args , _kwargs )
218
173
set_converted_view (
@@ -224,17 +179,6 @@ async def async_render():
224
179
)
225
180
)
226
181
227
- # Render in compatibility mode, if needed
228
- if compatibility :
229
- # Warn the user that compatibility mode is deprecated
230
- warn (
231
- "view_to_component(compatibility=True) is deprecated and will be removed in a future version. "
232
- "Please use `view_to_iframe` instead." ,
233
- DeprecationWarning ,
234
- )
235
-
236
- return view_to_iframe (resolved_view )(* _args , ** _kwargs )
237
-
238
182
# Return the view if it's been rendered via the `async_render` hook
239
183
return converted_view
240
184
0 commit comments