Staff
An admin interface for staff users.
The Plain Staff is a new packages built from the ground up. It leverages class-based views and standard URLs and templates to provide a flexible admin where you can quickly create your own pages and cards, in addition to models.
- cards
- dashboards
- diy forms
- detached from login (do your own login (oauth, passkeys, etc))
Installation
- install plain.staff and plain.htmx, add plain.staff.admin and plain.htmx to installed packages
- add url
Models in the admin
Dashboards
{% load toolbar %} <!doctype html>
... {% toolbar %} ... ```More specific settings can be found below.
Tailwind CSS
This package is styled with Tailwind CSS,
and pairs well with plain-tailwind
.
If you are using your own Tailwind implementation, you can modify the "content" in your Tailwind config to include any Plain packages:
// tailwind.config.js
module.exports = {
content: [
// ...
".venv/lib/python*/site-packages/plain*/**/*.{html,js}",
],
// ...
}
If you aren't using Tailwind, and don't intend to, open an issue to discuss other options.
plain.requestlog
The request log stores a local history of HTTP requests and responses during plain work
(Django runserver).
The request history will make it easy to see redirects, 400 and 500 level errors, form submissions, API calls, webhooks, and more.
Requests can be re-submitted by clicking the "replay" button.
Installation
# settings.py
INSTALLED_PACKAGES += [
"plainrequestlog",
]
MIDDLEWARE = MIDDLEWARE + [
# ...
"plainrequestlog.RequestLogMiddleware",
]
The default settings can be customized if needed:
# settings.py
DEV_REQUESTS_IGNORE_PATHS = [
"/sw.js",
"/favicon.ico",
"/staff/jsi18n/",
]
DEV_REQUESTS_MAX = 50
Tailwind CSS
This package is styled with Tailwind CSS,
and pairs well with plain-tailwind
.
If you are using your own Tailwind implementation, you can modify the "content" in your Tailwind config to include any Plain packages:
// tailwind.config.js
module.exports = {
content: [
// ...
".venv/lib/python*/site-packages/plain*/**/*.{html,js}",
],
// ...
}
If you aren't using Tailwind, and don't intend to, open an issue to discuss other options.
plain.impersonate
See what your users see.
A key feature for providing customer support is to be able to view the site through their account.
With impersonate
installed, you can impersonate a user by finding them in the Django admin and clicking the "Impersonate" button.
Then with the staff toolbar enabled, you'll get a notice of the impersonation and a button to exit:
Installation
To impersonate users, you need the app, middleware, and URLs:
# settings.py
INSTALLED_PACKAGES = INSTALLED_PACKAGES + [
"plain.staff.impersonate",
]
MIDDLEWARE = MIDDLEWARE + [
"plain.staff.impersonate.ImpersonateMiddleware",
]
# urls.py
urlpatterns = [
# ...
path("impersonate/", include("plain.staff.impersonate.urls")),
]
Settings
By default, all staff users can impersonate other users.
# settings.py
IMPERSONATE_ALLOWED = lambda user: user.is_staff
``` -->
1from plain.runtime import settings
2from plain.templates import register_template_extension, register_template_filter
3from plain.templates.jinja.extensions import InclusionTagExtension
4from plain.utils.module_loading import import_string
5
6from .views.registry import registry
7
8
9@register_template_extension
10class ToolbarExtension(InclusionTagExtension):
11 tags = {"toolbar"}
12 template_name = "toolbar/toolbar.html"
13
14 def get_context(self, context, *args, **kwargs):
15 if isinstance(settings.TOOLBAR_CLASS, str):
16 cls = import_string(settings.TOOLBAR_CLASS)
17 else:
18 cls = settings.TOOLBAR_CLASS
19 context.vars["toolbar"] = cls(request=context.get("request"))
20 return context
21
22
23@register_template_filter
24def get_admin_model_detail_url(obj):
25 return registry.get_model_detail_url(obj)