|
1 | 1 | <!-- This file is compiled from plain-staff/plain/staff/README.md. Do not edit this file directly. -->
|
2 | 2 |
|
3 | 3 | # Staff
|
| 4 | + |
| 5 | +An admin interface for staff users. |
| 6 | + |
| 7 | +The Plain Staff is a new packages built from the ground up. |
| 8 | +It leverages class-based views and standard URLs and templates to provide a flexible admin where |
| 9 | +you can quickly create your own pages and cards, |
| 10 | +in addition to models. |
| 11 | + |
| 12 | +- cards |
| 13 | +- dashboards |
| 14 | +- diy forms |
| 15 | +- detached from login (do your own login (oauth, passkeys, etc)) |
| 16 | + |
| 17 | +## Installation |
| 18 | + |
| 19 | +- install plain.staff and plain.htmx, add plain.staff.admin and plain.htmx to installed packages |
| 20 | +- add url |
| 21 | + |
| 22 | +## Models in the admin |
| 23 | + |
| 24 | +## Dashboards |
| 25 | + |
| 26 | +<!-- # plain.querystats |
| 27 | +
|
| 28 | +On-page database query stats in development and production. |
| 29 | +
|
| 30 | +On each page, the query stats will display how many database queries were performed and how long they took. |
| 31 | +
|
| 32 | +[Watch on YouTube](https://www.youtube.com/watch?v=NX8VXxVJm08) |
| 33 | +
|
| 34 | +Clicking the stats in the toolbar will show the full SQL query log with tracebacks and timings. |
| 35 | +This is even designed to work in production, |
| 36 | +making it much easier to discover and debug performance issues on production data! |
| 37 | +
|
| 38 | + |
| 39 | +
|
| 40 | +It will also point out duplicate queries, |
| 41 | +which can typically be removed by using `select_related`, |
| 42 | +`prefetch_related`, or otherwise refactoring your code. |
| 43 | +
|
| 44 | +## Installation |
| 45 | +
|
| 46 | +```python |
| 47 | +# settings.py |
| 48 | +INSTALLED_PACKAGES = [ |
| 49 | + # ... |
| 50 | + "plain.staff.querystats", |
| 51 | +] |
| 52 | +
|
| 53 | +MIDDLEWARE = [ |
| 54 | + "plain.middleware.security.SecurityMiddleware", |
| 55 | + "plain.sessions.middleware.SessionMiddleware", |
| 56 | + "plain.middleware.common.CommonMiddleware", |
| 57 | + "plain.csrf.middleware.CsrfViewMiddleware", |
| 58 | + "plain.auth.middleware.AuthenticationMiddleware", |
| 59 | + "plain.middleware.clickjacking.XFrameOptionsMiddleware", |
| 60 | +
|
| 61 | + "plain.staff.querystats.QueryStatsMiddleware", |
| 62 | + # Put additional middleware below querystats |
| 63 | + # ... |
| 64 | +] |
| 65 | +``` |
| 66 | +
|
| 67 | +We strongly recommend using the plain-toolbar along with this, |
| 68 | +but if you aren't, |
| 69 | +you can add the querystats to your frontend templates with this include: |
| 70 | +
|
| 71 | +```html |
| 72 | +{% include "querystats/button.html" %} |
| 73 | +``` |
| 74 | +
|
| 75 | +*Note that you will likely want to surround this with an if `DEBUG` or `is_staff` check.* |
| 76 | +
|
| 77 | +To view querystats you need to send a POST request to `?querystats=store` (i.e. via a `<form>`), |
| 78 | +and the template include is the easiest way to do that. |
| 79 | +
|
| 80 | +## Tailwind CSS |
| 81 | +
|
| 82 | +This package is styled with [Tailwind CSS](https://tailwindcss.com/), |
| 83 | +and pairs well with [`plain-tailwind`](https://github.com/plainpackages/plain-tailwind). |
| 84 | +
|
| 85 | +If you are using your own Tailwind implementation, |
| 86 | +you can modify the "content" in your Tailwind config to include any Plain packages: |
| 87 | +
|
| 88 | +```js |
| 89 | +// tailwind.config.js |
| 90 | +module.exports = { |
| 91 | + content: [ |
| 92 | + // ... |
| 93 | + ".venv/lib/python*/site-packages/plain*/**/*.{html,js}", |
| 94 | + ], |
| 95 | + // ... |
| 96 | +} |
| 97 | +``` |
| 98 | +
|
| 99 | +If you aren't using Tailwind, and don't intend to, open an issue to discuss other options. |
| 100 | +
|
| 101 | +
|
| 102 | +# plain.toolbar |
| 103 | +
|
| 104 | +The staff toolbar is enabled for every user who `is_staff`. |
| 105 | +
|
| 106 | + |
| 107 | +
|
| 108 | +## Installation |
| 109 | +
|
| 110 | +Add `plaintoolbar` to your `INSTALLED_PACKAGES`, |
| 111 | +and the `{% toolbar %}` to your base template: |
| 112 | +
|
| 113 | +```python |
| 114 | +# settings.py |
| 115 | +INSTALLED_PACKAGES += [ |
| 116 | + "plaintoolbar", |
| 117 | +] |
| 118 | +``` |
| 119 | +
|
| 120 | +```html |
| 121 | +<!-- base.template.html --> |
| 122 | +{% load toolbar %} |
| 123 | +<!doctype html> |
| 124 | +<html lang="en"> |
| 125 | + <head> |
| 126 | + ... |
| 127 | + </head> |
| 128 | + <body> |
| 129 | + {% toolbar %} |
| 130 | + ... |
| 131 | + </body> |
| 132 | +``` |
| 133 | +
|
| 134 | +More specific settings can be found below. |
| 135 | +
|
| 136 | +## Tailwind CSS |
| 137 | +
|
| 138 | +This package is styled with [Tailwind CSS](https://tailwindcss.com/), |
| 139 | +and pairs well with [`plain-tailwind`](https://github.com/plainpackages/plain-tailwind). |
| 140 | +
|
| 141 | +If you are using your own Tailwind implementation, |
| 142 | +you can modify the "content" in your Tailwind config to include any Plain packages: |
| 143 | +
|
| 144 | +```js |
| 145 | +// tailwind.config.js |
| 146 | +module.exports = { |
| 147 | + content: [ |
| 148 | + // ... |
| 149 | + ".venv/lib/python*/site-packages/plain*/**/*.{html,js}", |
| 150 | + ], |
| 151 | + // ... |
| 152 | +} |
| 153 | +``` |
| 154 | + |
| 155 | +If you aren't using Tailwind, and don't intend to, open an issue to discuss other options. |
| 156 | + |
| 157 | + |
| 158 | +# plain.requestlog |
| 159 | + |
| 160 | +The request log stores a local history of HTTP requests and responses during `plain work` (Django runserver). |
| 161 | + |
| 162 | +The request history will make it easy to see redirects, |
| 163 | +400 and 500 level errors, |
| 164 | +form submissions, |
| 165 | +API calls, |
| 166 | +webhooks, |
| 167 | +and more. |
| 168 | + |
| 169 | +[Watch on YouTube](https://www.youtube.com/watch?v=AwI7Pt5oZnM) |
| 170 | + |
| 171 | +Requests can be re-submitted by clicking the "replay" button. |
| 172 | + |
| 173 | +[](https://user-images.githubusercontent.com/649496/213781414-417ad043-de67-4836-9ef1-2b91404336c3.png) |
| 174 | + |
| 175 | +## Installation |
| 176 | + |
| 177 | +```python |
| 178 | +# settings.py |
| 179 | +INSTALLED_PACKAGES += [ |
| 180 | + "plainrequestlog", |
| 181 | +] |
| 182 | + |
| 183 | +MIDDLEWARE = MIDDLEWARE + [ |
| 184 | + # ... |
| 185 | + "plainrequestlog.RequestLogMiddleware", |
| 186 | +] |
| 187 | +``` |
| 188 | + |
| 189 | +The default settings can be customized if needed: |
| 190 | + |
| 191 | +```python |
| 192 | +# settings.py |
| 193 | +DEV_REQUESTS_IGNORE_PATHS = [ |
| 194 | + "/sw.js", |
| 195 | + "/favicon.ico", |
| 196 | + "/staff/jsi18n/", |
| 197 | +] |
| 198 | +DEV_REQUESTS_MAX = 50 |
| 199 | +``` |
| 200 | + |
| 201 | +## Tailwind CSS |
| 202 | + |
| 203 | +This package is styled with [Tailwind CSS](https://tailwindcss.com/), |
| 204 | +and pairs well with [`plain-tailwind`](https://github.com/plainpackages/plain-tailwind). |
| 205 | + |
| 206 | +If you are using your own Tailwind implementation, |
| 207 | +you can modify the "content" in your Tailwind config to include any Plain packages: |
| 208 | + |
| 209 | +```js |
| 210 | +// tailwind.config.js |
| 211 | +module.exports = { |
| 212 | + content: [ |
| 213 | + // ... |
| 214 | + ".venv/lib/python*/site-packages/plain*/**/*.{html,js}", |
| 215 | + ], |
| 216 | + // ... |
| 217 | +} |
| 218 | +``` |
| 219 | + |
| 220 | +If you aren't using Tailwind, and don't intend to, open an issue to discuss other options. |
| 221 | + |
| 222 | + |
| 223 | +# plain.impersonate |
| 224 | + |
| 225 | +See what your users see. |
| 226 | + |
| 227 | +A key feature for providing customer support is to be able to view the site through their account. |
| 228 | +With `impersonate` installed, you can impersonate a user by finding them in the Django admin and clicking the "Impersonate" button. |
| 229 | + |
| 230 | + |
| 231 | + |
| 232 | +Then with the [staff toolbar](/docs/plain-toolbar/) enabled, you'll get a notice of the impersonation and a button to exit: |
| 233 | + |
| 234 | + |
| 235 | + |
| 236 | +## Installation |
| 237 | + |
| 238 | +To impersonate users, you need the app, middleware, and URLs: |
| 239 | + |
| 240 | +```python |
| 241 | +# settings.py |
| 242 | +INSTALLED_PACKAGES = INSTALLED_PACKAGES + [ |
| 243 | + "plain.staff.impersonate", |
| 244 | +] |
| 245 | + |
| 246 | +MIDDLEWARE = MIDDLEWARE + [ |
| 247 | + "plain.staff.impersonate.ImpersonateMiddleware", |
| 248 | +] |
| 249 | +``` |
| 250 | + |
| 251 | +```python |
| 252 | +# urls.py |
| 253 | +urlpatterns = [ |
| 254 | + # ... |
| 255 | + path("impersonate/", include("plain.staff.impersonate.urls")), |
| 256 | +] |
| 257 | +``` |
| 258 | + |
| 259 | +## Settings |
| 260 | + |
| 261 | +By default, all staff users can impersonate other users. |
| 262 | + |
| 263 | +```python |
| 264 | +# settings.py |
| 265 | +IMPERSONATE_ALLOWED = lambda user: user.is_staff |
| 266 | +``` --> |
0 commit comments