wagtail_reactadmin 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (23) hide show
  1. wagtail_reactadmin-0.1.0/MANIFEST.in +4 -0
  2. wagtail_reactadmin-0.1.0/PKG-INFO +25 -0
  3. wagtail_reactadmin-0.1.0/README.md +1 -0
  4. wagtail_reactadmin-0.1.0/setup.cfg +4 -0
  5. wagtail_reactadmin-0.1.0/setup.py +40 -0
  6. wagtail_reactadmin-0.1.0/wagtail_reactadmin/__init__.py +2 -0
  7. wagtail_reactadmin-0.1.0/wagtail_reactadmin/adapters.py +41 -0
  8. wagtail_reactadmin-0.1.0/wagtail_reactadmin/apps.py +7 -0
  9. wagtail_reactadmin-0.1.0/wagtail_reactadmin/bridge.py +69 -0
  10. wagtail_reactadmin-0.1.0/wagtail_reactadmin/context_providers.py +60 -0
  11. wagtail_reactadmin-0.1.0/wagtail_reactadmin/static/.gitignore +2 -0
  12. wagtail_reactadmin-0.1.0/wagtail_reactadmin/static/.vite/manifest.json +11 -0
  13. wagtail_reactadmin-0.1.0/wagtail_reactadmin/static/assets/main-BEpbLBv8.js +73 -0
  14. wagtail_reactadmin-0.1.0/wagtail_reactadmin/static/assets/main-BOcqHZ4q.css +1 -0
  15. wagtail_reactadmin-0.1.0/wagtail_reactadmin/templates/wagtail_reactadmin/shell.html +122 -0
  16. wagtail_reactadmin-0.1.0/wagtail_reactadmin/templates/wagtail_reactadmin/shellframe.html +152 -0
  17. wagtail_reactadmin-0.1.0/wagtail_reactadmin/templates/wagtailadmin/base.html +20 -0
  18. wagtail_reactadmin-0.1.0/wagtail_reactadmin/urls.py +17 -0
  19. wagtail_reactadmin-0.1.0/wagtail_reactadmin.egg-info/PKG-INFO +25 -0
  20. wagtail_reactadmin-0.1.0/wagtail_reactadmin.egg-info/SOURCES.txt +21 -0
  21. wagtail_reactadmin-0.1.0/wagtail_reactadmin.egg-info/dependency_links.txt +1 -0
  22. wagtail_reactadmin-0.1.0/wagtail_reactadmin.egg-info/not-zip-safe +1 -0
  23. wagtail_reactadmin-0.1.0/wagtail_reactadmin.egg-info/top_level.txt +1 -0
@@ -0,0 +1,4 @@
1
+ include LICENSE *.rst *.txt *.md
2
+ graft wagtail_reactadmin
3
+ global-exclude __pycache__
4
+ global-exclude *.py[co]
@@ -0,0 +1,25 @@
1
+ Metadata-Version: 2.4
2
+ Name: wagtail_reactadmin
3
+ Version: 0.1.0
4
+ Summary: React Admin for Wagtail CMS
5
+ Home-page:
6
+ Author:
7
+ Author-email:
8
+ Classifier: Development Status :: 3 - Alpha
9
+ Classifier: Intended Audience :: Developers
10
+ Classifier: License :: OSI Approved :: BSD License
11
+ Classifier: Operating System :: OS Independent
12
+ Classifier: Programming Language :: Python
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3.13
15
+ Classifier: Programming Language :: Python :: 3.14
16
+ Classifier: Framework :: Django
17
+ Classifier: Framework :: Django :: 6
18
+ Classifier: Framework :: Wagtail
19
+ Description-Content-Type: text/markdown
20
+ Dynamic: classifier
21
+ Dynamic: description
22
+ Dynamic: description-content-type
23
+ Dynamic: summary
24
+
25
+ # Wagtail ReactAdmin
@@ -0,0 +1 @@
1
+ # Wagtail ReactAdmin
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,40 @@
1
+ #!/usr/bin/env python
2
+
3
+ from os import path
4
+
5
+ from setuptools import find_packages, setup
6
+ from wagtail_reactadmin import __version__
7
+
8
+ this_directory = path.abspath(path.dirname(__file__))
9
+ with open(path.join(this_directory, "README.md"), encoding="utf-8") as f:
10
+ long_description = f.read()
11
+
12
+ setup(
13
+ name="wagtail_reactadmin",
14
+ version=__version__,
15
+ description="React Admin for Wagtail CMS",
16
+ long_description=long_description,
17
+ long_description_content_type="text/markdown",
18
+ author="",
19
+ author_email="",
20
+ url="",
21
+ packages=find_packages(),
22
+ include_package_data=True,
23
+ license="",
24
+ classifiers=[
25
+ "Development Status :: 3 - Alpha",
26
+ "Intended Audience :: Developers",
27
+ "License :: OSI Approved :: BSD License",
28
+ "Operating System :: OS Independent",
29
+ "Programming Language :: Python",
30
+ "Programming Language :: Python :: 3",
31
+ "Programming Language :: Python :: 3.13",
32
+ "Programming Language :: Python :: 3.14",
33
+ "Framework :: Django",
34
+ "Framework :: Django :: 6",
35
+ "Framework :: Wagtail",
36
+ ],
37
+ install_requires=[],
38
+ extras_require={},
39
+ zip_safe=False,
40
+ )
@@ -0,0 +1,2 @@
1
+ VERSION = (0, 1, 0)
2
+ __version__ = ".".join(map(str, VERSION))
@@ -0,0 +1,41 @@
1
+ from django_bridge.adapters.registry import Adapter, register
2
+ from wagtail.admin.ui.sidebar import (
3
+ ActionMenuItem,
4
+ BaseSidebarAdapter,
5
+ LinkMenuItem,
6
+ MainMenuModule,
7
+ PageExplorerMenuItem,
8
+ SearchModule,
9
+ SubMenuItem,
10
+ WagtailBrandingModule,
11
+ )
12
+
13
+
14
+ def adapter(cls, js_constructor, base=Adapter):
15
+ ClassAdapter = type(
16
+ cls.__name__ + "Adapter",
17
+ (base,),
18
+ {
19
+ "js_constructor": js_constructor,
20
+ "js_args": lambda self, obj: obj.js_args(),
21
+ },
22
+ )
23
+
24
+ register(ClassAdapter(), cls)
25
+
26
+
27
+ adapter(LinkMenuItem, "wagtail.sidebar.LinkMenuItem", base=BaseSidebarAdapter)
28
+ adapter(ActionMenuItem, "wagtail.sidebar.ActionMenuItem", base=BaseSidebarAdapter)
29
+ adapter(SubMenuItem, "wagtail.sidebar.SubMenuItem", base=BaseSidebarAdapter)
30
+ adapter(
31
+ PageExplorerMenuItem,
32
+ "wagtail.sidebar.PageExplorerMenuItem",
33
+ base=BaseSidebarAdapter,
34
+ )
35
+ adapter(
36
+ WagtailBrandingModule,
37
+ "wagtail.sidebar.WagtailBrandingModule",
38
+ base=BaseSidebarAdapter,
39
+ )
40
+ adapter(SearchModule, "wagtail.sidebar.SearchModule", base=BaseSidebarAdapter)
41
+ adapter(MainMenuModule, "wagtail.sidebar.MainMenuModule", base=BaseSidebarAdapter)
@@ -0,0 +1,7 @@
1
+ from django.apps import AppConfig
2
+
3
+
4
+ class WagtailReactAdminAppConfig(AppConfig):
5
+ label = "wagtail_reactadmin"
6
+ name = "wagtail_reactadmin"
7
+ verbose_name = "Wagtail React Admin"
@@ -0,0 +1,69 @@
1
+ import functools
2
+ import os
3
+ import pathlib
4
+
5
+ from django.middleware.csrf import get_token
6
+ from django.template.response import TemplateResponse
7
+ from django.urls import reverse
8
+ from rest_framework.response import Response as DRFResponse
9
+
10
+ from django_bridge.conf import DjangoBridgeConfig
11
+ from django_bridge.response import Response, process_response
12
+
13
+ from . import context_providers
14
+
15
+ VITE_DEVSERVER_URL = os.environ.get("VITE_DEVSERVER_URL")
16
+ config = DjangoBridgeConfig(
17
+ bootstrap_template="wagtail_reactadmin/shell.html",
18
+ framework="react",
19
+ entry_point="src/main.tsx",
20
+ vite_devserver_url=VITE_DEVSERVER_URL,
21
+ vite_bundle_dir=pathlib.Path(__file__).parent / "static"
22
+ if VITE_DEVSERVER_URL is None
23
+ else None,
24
+ context_providers={
25
+ "csrf_token": get_token,
26
+ "urls": context_providers.urls,
27
+ "locales": context_providers.locales,
28
+ "admin_api": context_providers.admin_api,
29
+ "sidebar": context_providers.sidebar_props,
30
+ },
31
+ )
32
+
33
+
34
+ def convert_response_to_django_bridge(view_func):
35
+ """
36
+ Converts legacy HTML responses to Django Bridge responses.
37
+
38
+ This allows the response to be rendered without reloading the page.
39
+ """
40
+
41
+ @functools.wraps(view_func)
42
+ def wrapper(request, *args, **kwargs):
43
+ response = view_func(request, *args, **kwargs)
44
+
45
+ # Ignore Django REST framework responses
46
+ if isinstance(response, DRFResponse):
47
+ return response
48
+
49
+ # TODO: Only wrap responses that have used the admin_base template
50
+ if (
51
+ response.status_code != 302
52
+ and response["Content-Type"].startswith("text/html")
53
+ and not request.META.get("HTTP_X_REQUESTED_WITH") == "XMLHttpRequest"
54
+ ):
55
+ if isinstance(response, TemplateResponse):
56
+ html = response.render().text
57
+ else:
58
+ html = response.content.decode("utf-8")
59
+ response = Response(
60
+ request,
61
+ "HTMLPage",
62
+ {"html": html, "frameUrl": reverse("shell-frame")},
63
+ )
64
+
65
+ # Render the response with Django bridge
66
+ # Note, the render_response helper acts like the django-bridge middleware
67
+ return process_response(request, response, config)
68
+
69
+ return wrapper
@@ -0,0 +1,60 @@
1
+ from django.urls import reverse
2
+ from django.utils.encoding import force_str
3
+ from django.utils.translation import gettext_lazy as _
4
+
5
+ from wagtail.admin.menu import admin_menu
6
+ from wagtail.admin.search import admin_search_areas
7
+ from wagtail.admin.ui import sidebar
8
+ from wagtail.models import Locale
9
+
10
+
11
+ def urls(request):
12
+ return {
13
+ "pages": reverse("wagtailadmin_explore_root"),
14
+ }
15
+
16
+
17
+ def locales(request):
18
+ return [
19
+ {
20
+ "code": locale.language_code,
21
+ "display_name": force_str(locale.get_display_name()),
22
+ }
23
+ for locale in Locale.objects.all()
24
+ ]
25
+
26
+
27
+ def admin_api(request):
28
+ return {
29
+ "pagesBaseUrl": reverse("wagtailadmin_api:pages:listing"),
30
+ "extraChildrenParameters": "",
31
+ }
32
+
33
+
34
+ def sidebar_props(request):
35
+ search_areas = admin_search_areas.search_items_for_request(request)
36
+ if search_areas:
37
+ search_area = search_areas[0]
38
+ else:
39
+ search_area = None
40
+
41
+ account_menu = [
42
+ sidebar.LinkMenuItem(
43
+ "account", _("Account"), reverse("wagtailadmin_account"), icon_name="user"
44
+ ),
45
+ sidebar.ActionMenuItem(
46
+ "logout", _("Log out"), reverse("wagtailadmin_logout"), icon_name="logout"
47
+ ),
48
+ ]
49
+
50
+ modules = [
51
+ sidebar.WagtailBrandingModule(),
52
+ sidebar.SearchModule(search_area) if search_area else None,
53
+ sidebar.MainMenuModule(
54
+ admin_menu.render_component(request), account_menu, request.user
55
+ ),
56
+ ]
57
+ return {
58
+ "enabled": request.user.is_authenticated,
59
+ "modules": [module for module in modules if module is not None],
60
+ }
@@ -0,0 +1,2 @@
1
+ *
2
+ !.gitignore
@@ -0,0 +1,11 @@
1
+ {
2
+ "src/main.tsx": {
3
+ "file": "assets/main-BEpbLBv8.js",
4
+ "name": "main",
5
+ "src": "src/main.tsx",
6
+ "isEntry": true,
7
+ "css": [
8
+ "assets/main-BOcqHZ4q.css"
9
+ ]
10
+ }
11
+ }