Skip to content

Commit

Permalink
view_to_iframe component (#188)
Browse files Browse the repository at this point in the history
-   The `compatibility` argument on `reactpy_django.components.view_to_component` is deprecated.
-   Using `reactpy_django.components.view_to_component` as a decorator is deprecated.
-   `reactpy_django.utils.register_iframe` function has been added.
-   `reactpy_django.components.view_to_iframe` component has been added
-   It is now recommended to call `as_view()` when using `view_to_component` or `view_to_iframe` with Class Based Views.
-   Thread sensitivity has been enabled in all locations where ORM queries are possible.
  • Loading branch information
Archmonger authored Sep 25, 2023
1 parent 67dc1eb commit 6f79c4c
Show file tree
Hide file tree
Showing 48 changed files with 814 additions and 416 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,19 @@ Using the following categories, list your changes in this order:
- ReactPy components can now use SEO compatible rendering!
- `settings.py:REACTPY_PRERENDER` can be set to `True` to enable this behavior by default
- Or, you can enable it on individual components via the template tag: `{% component "..." prerender="True" %}`
- `reactpy_django.components.view_to_iframe` component has been added, which uses an `<iframe>` to render a Django view.
- `reactpy_django.utils.register_iframe` function has been added, which is mandatory to use alongside `reactpy_django.components.view_to_iframe`.

### Changed

- Renamed undocumented utility function `reactpy_django.utils.ComponentPreloader` to `reactpy_django.utils.RootComponentFinder`.
- It is now recommended to call `as_view()` when using `view_to_component` or `view_to_iframe` with Class Based Views.
- Thread sensitivity has been enabled in all locations where ORM queries are possible.

### Deprecated

- The `compatibility` argument on `reactpy_django.components.view_to_component` is deprecated. Use `reactpy_django.components.view_to_iframe` instead.
- Using `reactpy_django.components.view_to_component` as a decorator is deprecated. Check the docs on the new suggested usage.

## [3.5.1] - 2023-09-07

Expand Down
11 changes: 11 additions & 0 deletions docs/python/hello_world_app_config_cbv.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from django.apps import AppConfig
from reactpy_django.utils import register_iframe

from . import views


class ExampleAppConfig(AppConfig):
name = "example"

def ready(self):
register_iframe(views.HelloWorld)
11 changes: 11 additions & 0 deletions docs/python/hello_world_app_config_fbv.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from django.apps import AppConfig
from reactpy_django.utils import register_iframe

from . import views


class ExampleAppConfig(AppConfig):
name = "example"

def ready(self):
register_iframe(views.hello_world)
5 changes: 5 additions & 0 deletions docs/python/hello_world_args_kwargs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.http import HttpResponse


def hello_world(request, arg1, arg2, kwarg1=None, kwarg2=None):
return HttpResponse(f"Hello World! {arg1} {arg2} {kwarg1} {kwarg2}")
7 changes: 7 additions & 0 deletions docs/python/hello_world_cbv.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from django.http import HttpResponse
from django.views import View


class HelloWorld(View):
def get(self, request):
return HttpResponse("Hello World!")
5 changes: 5 additions & 0 deletions docs/python/hello_world_fbv.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.http import HttpResponse


def hello_world(request):
return HttpResponse("Hello World!")
5 changes: 5 additions & 0 deletions docs/python/hello_world_fbv_with_id.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.http import HttpResponse


def hello_world(request):
return HttpResponse('<div id="hello-world"> Hello World! </div>')
5 changes: 3 additions & 2 deletions docs/python/register-component.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
from reactpy_django.utils import register_component


class ExampleConfig(AppConfig):
class ExampleAppConfig(AppConfig):
name = "example"

def ready(self):
# Add components to the ReactPy component registry when Django is ready
register_component("example_project.my_app.components.hello_world")
2 changes: 1 addition & 1 deletion docs/python/use-mutation-thread-sensitive.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from reactpy_django.types import MutationOptions


def execute_thread_safe_mutation():
def execute_thread_safe_mutation(text):
"""This is an example mutation function that does some thread-safe operation."""
pass

Expand Down
7 changes: 7 additions & 0 deletions docs/python/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from .hello_world_cbv import HelloWorld
from .hello_world_fbv import hello_world

__all__ = [
"HelloWorld",
"hello_world",
]
21 changes: 0 additions & 21 deletions docs/python/vtc-args-kwargs.py

This file was deleted.

23 changes: 23 additions & 0 deletions docs/python/vtc-args.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from django.http import HttpRequest
from reactpy import component, html
from reactpy_django.components import view_to_component

from . import views

hello_world_component = view_to_component(views.hello_world)


@component
def my_component():
request = HttpRequest()
request.method = "GET"

return html.div(
hello_world_component(
request, # This request object is optional.
"value_1",
"value_2",
kwarg1="abc",
kwarg2="123",
),
)
10 changes: 0 additions & 10 deletions docs/python/vtc-cbv-compatibility.py

This file was deleted.

12 changes: 3 additions & 9 deletions docs/python/vtc-cbv.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
from django.http import HttpResponse
from django.views import View
from reactpy import component, html
from reactpy_django.components import view_to_component

from . import views

class HelloWorldView(View):
def get(self, request):
return HttpResponse("Hello World!")


vtc = view_to_component(HelloWorldView)
hello_world_component = view_to_component(views.HelloWorld.as_view())


@component
def my_component():
return html.div(
vtc(),
hello_world_component(),
)
15 changes: 0 additions & 15 deletions docs/python/vtc-compatibility.py

This file was deleted.

8 changes: 0 additions & 8 deletions docs/python/vtc-fbv-compat.py

This file was deleted.

12 changes: 0 additions & 12 deletions docs/python/vtc-func.py

This file was deleted.

20 changes: 0 additions & 20 deletions docs/python/vtc-request.py

This file was deleted.

8 changes: 3 additions & 5 deletions docs/python/vtc-strict-parsing.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
from django.http import HttpResponse
from reactpy import component, html
from reactpy_django.components import view_to_component

from . import views

@view_to_component(strict_parsing=False)
def hello_world_view(request):
return HttpResponse("<my-tag> Hello World </my-tag>")
hello_world_component = view_to_component(views.hello_world)


@component
def my_component():
return html.div(
hello_world_view(),
hello_world_component(),
)
13 changes: 7 additions & 6 deletions docs/python/vtc-transforms.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
from django.http import HttpResponse
from reactpy import component, html
from reactpy_django.components import view_to_component

from . import views


def example_transform(vdom):
attributes = vdom.get("attributes")
if attributes and attributes.get("id") == "hello-world":
vdom["children"][0] = "Good Bye World!"
vdom["children"][0] = "Farewell World!"


@view_to_component(transforms=[example_transform])
def hello_world_view(request):
return HttpResponse("<div id='hello-world'> Hello World! <div>")
hello_world_component = view_to_component(
views.hello_world, transforms=[example_transform]
)


@component
def my_component():
return html.div(
hello_world_view(),
hello_world_component(),
)
8 changes: 3 additions & 5 deletions docs/python/vtc.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
from django.http import HttpResponse
from reactpy import component, html
from reactpy_django.components import view_to_component

from . import views

@view_to_component
def hello_world_view(request):
return HttpResponse("Hello World!")
hello_world_component = view_to_component(views.hello_world)


@component
def my_component():
return html.div(
hello_world_view(),
hello_world_component(),
)
20 changes: 20 additions & 0 deletions docs/python/vti-args.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from reactpy import component, html
from reactpy_django.components import view_to_iframe

from . import views

hello_world_iframe = view_to_iframe(
views.hello_world,
)


@component
def my_component():
return html.div(
hello_world_iframe(
"value_1",
"value_2",
kwarg1="abc",
kwarg2="123",
),
)
13 changes: 13 additions & 0 deletions docs/python/vti-cbv.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from reactpy import component, html
from reactpy_django.components import view_to_iframe

from . import views

hello_world_iframe = view_to_iframe(views.HelloWorld.as_view())


@component
def my_component():
return html.div(
hello_world_iframe(),
)
15 changes: 15 additions & 0 deletions docs/python/vti-extra-props.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from reactpy import component, html
from reactpy_django.components import view_to_iframe

from . import views

hello_world_iframe = view_to_iframe(
views.hello_world, extra_props={"title": "Hello World!"}
)


@component
def my_component():
return html.div(
hello_world_iframe(),
)
13 changes: 13 additions & 0 deletions docs/python/vti.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from reactpy import component, html
from reactpy_django.components import view_to_iframe

from . import views

hello_world_iframe = view_to_iframe(views.hello_world)


@component
def my_component():
return html.div(
hello_world_iframe(),
)
Loading

0 comments on commit 6f79c4c

Please sign in to comment.