Skip to content

Commit e49d54b

Browse files
committed
Move admin toolbar to a new package plain-toolbar
1 parent 57fb948 commit e49d54b

File tree

24 files changed

+199
-86
lines changed

24 files changed

+199
-86
lines changed

demos/full/app/settings.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"plain.sessions",
2121
"plain.support",
2222
"plain.tailwind",
23+
"plain.toolbar",
2324
"plain.worker",
2425
"plain.redirection",
2526
"plain.observer",

demos/full/pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ dependencies = [
2727
"plain-sessions",
2828
"plain-support",
2929
"plain-tailwind",
30+
"plain-toolbar",
3031
"plain-tunnel",
3132
"plain-vendor",
3233
"plain-worker",

plain-admin/plain/admin/README.md

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -178,23 +178,3 @@ class AppRouter(Router):
178178
# other urls...
179179
]
180180
```
181-
182-
Typically you will also want to add the admin `{% toolbar %}` to the bottom of your base template. The toolbar will appear when `settings.DEBUG` or when `request.user.is_admin` (including in production!).
183-
184-
```html
185-
<!-- app/templates/base.html -->
186-
<!DOCTYPE html>
187-
<html lang="en">
188-
<head>
189-
<meta charset="UTF-8">
190-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
191-
<title>{{ html_title|default("My App") }}</title>
192-
{% tailwind_css %}
193-
</head>
194-
<body>
195-
{% block content required %}{% endblock %}
196-
197-
{% toolbar %}
198-
</body>
199-
</html>
200-
```

plain-admin/plain/admin/templates.py

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,8 @@
1-
from plain.runtime import settings
2-
from plain.templates import register_template_extension, register_template_filter
3-
from plain.templates.jinja.extensions import InclusionTagExtension
1+
from plain.templates import register_template_filter
42

5-
from .toolbar import Toolbar
63
from .views.registry import registry
74

85

9-
@register_template_extension
10-
class ToolbarExtension(InclusionTagExtension):
11-
tags = {"toolbar"}
12-
template_name = "toolbar/toolbar.html"
13-
14-
def get_context(self, context, *args, **kwargs):
15-
context.vars["toolbar"] = Toolbar(request=context["request"])
16-
context.vars["app_name"] = settings.APP_NAME
17-
return context
18-
19-
206
@register_template_filter
217
def get_admin_model_detail_url(obj):
228
return registry.get_model_detail_url(obj)

plain-admin/plain/admin/templates/admin/base.html

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,5 @@ <h1 class="font-semibold text-sm">{% block title %}{{ title }}{% endblock %}</h1
247247
</div>
248248

249249
</div>
250-
251-
{% toolbar %}
252250
</body>
253251
</html>

plain-observer/plain/observer/admin.py

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
1-
from functools import cached_property
2-
3-
from plain.admin.toolbar import ToolbarPanel, register_toolbar_panel
41
from plain.admin.views import (
52
AdminModelDetailView,
63
AdminModelListView,
74
AdminViewset,
85
register_viewset,
96
)
107

11-
from .core import Observer
128
from .models import Span, Trace
139

1410

@@ -81,20 +77,3 @@ def get_initial_queryset(self):
8177

8278
class DetailView(AdminModelDetailView):
8379
model = Span
84-
85-
86-
@register_toolbar_panel
87-
class ObserverToolbarPanel(ToolbarPanel):
88-
name = "Observer"
89-
template_name = "toolbar/observer.html"
90-
button_template_name = "toolbar/observer_button.html"
91-
92-
@cached_property
93-
def observer(self):
94-
"""Get the Observer instance for this request."""
95-
return Observer(self.request)
96-
97-
def get_template_context(self):
98-
context = super().get_template_context()
99-
context["observer"] = self.observer
100-
return context
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from functools import cached_property
2+
3+
from plain.toolbar import ToolbarPanel, register_toolbar_panel
4+
5+
from .core import Observer
6+
7+
8+
@register_toolbar_panel
9+
class ObserverToolbarPanel(ToolbarPanel):
10+
name = "Observer"
11+
template_name = "toolbar/observer.html"
12+
button_template_name = "toolbar/observer_button.html"
13+
14+
@cached_property
15+
def observer(self):
16+
"""Get the Observer instance for this request."""
17+
return Observer(self.request)
18+
19+
def get_template_context(self):
20+
context = super().get_template_context()
21+
context["observer"] = self.observer
22+
return context

plain-sessions/plain/sessions/admin.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from plain.admin.toolbar import ToolbarPanel, register_toolbar_panel
21
from plain.admin.views import (
32
AdminModelDetailView,
43
AdminModelListView,
@@ -9,12 +8,6 @@
98
from .models import Session
109

1110

12-
@register_toolbar_panel
13-
class SessionToolbarPanel(ToolbarPanel):
14-
name = "Session"
15-
template_name = "toolbar/session.html"
16-
17-
1811
@register_viewset
1912
class SessionAdmin(AdminViewset):
2013
class ListView(AdminModelListView):
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from plain.toolbar import ToolbarPanel, register_toolbar_panel
2+
3+
4+
@register_toolbar_panel
5+
class SessionToolbarPanel(ToolbarPanel):
6+
name = "Session"
7+
template_name = "toolbar/session.html"

plain-toolbar/LICENSE

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
BSD 3-Clause License
2+
3+
Copyright (c) 2023, Dropseed, LLC
4+
5+
Redistribution and use in source and binary forms, with or without
6+
modification, are permitted provided that the following conditions are met:
7+
8+
1. Redistributions of source code must retain the above copyright notice, this
9+
list of conditions and the following disclaimer.
10+
11+
2. Redistributions in binary form must reproduce the above copyright notice,
12+
this list of conditions and the following disclaimer in the documentation
13+
and/or other materials provided with the distribution.
14+
15+
3. Neither the name of the copyright holder nor the names of its
16+
contributors may be used to endorse or promote products derived from
17+
this software without specific prior written permission.
18+
19+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

0 commit comments

Comments
 (0)