Skip to content

Commit d3534b0

Browse files
committed
Rebuild assets as a view
1 parent fdaeba3 commit d3534b0

File tree

35 files changed

+831
-2870
lines changed

35 files changed

+831
-2870
lines changed

plain-auth/README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ INSTALLED_PACKAGES = [
2424

2525
MIDDLEWARE = [
2626
"plain.middleware.security.SecurityMiddleware",
27-
"plain.assets.whitenoise.middleware.WhiteNoiseMiddleware",
2827
"plain.sessions.middleware.SessionMiddleware", # <--
2928
"plain.middleware.common.CommonMiddleware",
3029
"plain.csrf.middleware.CsrfViewMiddleware",

plain-auth/plain/auth/README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ INSTALLED_PACKAGES = [
2222

2323
MIDDLEWARE = [
2424
"plain.middleware.security.SecurityMiddleware",
25-
"plain.assets.whitenoise.middleware.WhiteNoiseMiddleware",
2625
"plain.sessions.middleware.SessionMiddleware", # <--
2726
"plain.middleware.common.CommonMiddleware",
2827
"plain.csrf.middleware.CsrfViewMiddleware",

plain-importmap/test_project/settings.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,3 @@
5959
USE_L10N = True
6060

6161
USE_TZ = True
62-
63-
64-
# Static files (CSS, JavaScript, Images)
65-
66-
ASSETS_URL = "/assets/"

plain-oauth/tests/settings.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@
4040
USE_TZ = True
4141
TIME_ZONE = "UTC"
4242

43-
ASSETS_URL = "/assets/"
44-
4543
AUTH_LOGIN_URL = "login"
4644
LOGOUT_REDIRECT_URL = "/"
4745

plain-pytest/plain/pytest/cli.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ def cli(pytest_args):
2929
# pytest_args.append("-W")
3030
# pytest_args.append("error::DeprecationWarning")
3131

32+
# has to happen before setup() to be more useful? initial setup() may fail if doesn't have the required variables
33+
# or don't set it by default at all... could warn on != TEST?
3234
os.environ.setdefault("PLAIN_ENV", "test")
3335

3436
click.secho(f"Running pytest with PLAIN_ENV={os.environ['PLAIN_ENV']}", bold=True)

plain-staff/README.md

Lines changed: 263 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,266 @@
11
<!-- This file is compiled from plain-staff/plain/staff/README.md. Do not edit this file directly. -->
22

33
# 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+
![Django query stats](https://user-images.githubusercontent.com/649496/213781593-54197bb6-36a8-4c9d-8294-5b43bd86a4c9.png)
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+
![Plain staff toolbar](https://user-images.githubusercontent.com/649496/213781915-a2094f54-99b8-4a05-a36e-dee107405229.png)
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+
[![Django request log](https://user-images.githubusercontent.com/649496/213781414-417ad043-de67-4836-9ef1-2b91404336c3.png)](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+
![](/docs/img/impersonate-admin.png)
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+
![](/docs/img/impersonate-bar.png)
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+
``` -->

plain-staff/tests/app/settings.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,3 @@
2121
]
2222
AUTH_LOGIN_URL = "login"
2323
AUTH_USER_MODEL = "users.User"
24-
ASSETS_BACKEND = "plain.assets.storage.StaticFilesStorage"

plain-staff/tests/app/urls.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import plain.assets.urls
12
import plain.staff.urls
23
from plain.urls import include, path
34
from plain.views import View
@@ -15,6 +16,7 @@ def get(self):
1516

1617
urlpatterns = [
1718
path("staff/", include(plain.staff.urls)),
19+
path("assets/", include(plain.assets.urls)),
1820
path("login/", LoginView, name="login"),
1921
path("logout/", LogoutView, name="logout"),
2022
]

plain/LICENSE

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -59,27 +59,3 @@ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
5959
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
6060
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
6161
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
62-
63-
64-
## This package contains code forked from github.com/evansd/whitenoise
65-
66-
The MIT License (MIT)
67-
68-
Copyright (c) 2013 David Evans
69-
70-
Permission is hereby granted, free of charge, to any person obtaining a copy of
71-
this software and associated documentation files (the "Software"), to deal in
72-
the Software without restriction, including without limitation the rights to
73-
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
74-
the Software, and to permit persons to whom the Software is furnished to do so,
75-
subject to the following conditions:
76-
77-
The above copyright notice and this permission notice shall be included in all
78-
copies or substantial portions of the Software.
79-
80-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
81-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
82-
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
83-
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
84-
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
85-
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

0 commit comments

Comments
 (0)