dorm-plg 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.
dorm_plg-0.1.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 DORM Contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,4 @@
1
+ recursive-include dorm/templates *.html
2
+ recursive-include dorm/static *.css *.js
3
+ include README.md
4
+ include LICENSE
@@ -0,0 +1,99 @@
1
+ Metadata-Version: 2.4
2
+ Name: dorm-plg
3
+ Version: 0.1.0
4
+ Summary: Django ORM playground — dev-only web UI for ORM queries
5
+ Author-email: almamydev <almamydev10@gmail.com>
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/almamydev/dorm
8
+ Project-URL: Repository, https://github.com/almamydev/dorm
9
+ Project-URL: Bug Tracker, https://github.com/almamydev/dorm/issues
10
+ Keywords: django,orm,playground,developer-tools,debugging
11
+ Classifier: Development Status :: 3 - Alpha
12
+ Classifier: Environment :: Web Environment
13
+ Classifier: Framework :: Django
14
+ Classifier: Framework :: Django :: 4.2
15
+ Classifier: Framework :: Django :: 5.0
16
+ Classifier: Framework :: Django :: 5.1
17
+ Classifier: Framework :: Django :: 5.2
18
+ Classifier: Intended Audience :: Developers
19
+ Classifier: Operating System :: OS Independent
20
+ Classifier: Programming Language :: Python :: 3
21
+ Classifier: Programming Language :: Python :: 3.10
22
+ Classifier: Programming Language :: Python :: 3.11
23
+ Classifier: Programming Language :: Python :: 3.12
24
+ Classifier: Topic :: Internet :: WWW/HTTP
25
+ Classifier: Topic :: Software Development :: Debuggers
26
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
27
+ Requires-Python: >=3.10
28
+ Description-Content-Type: text/markdown
29
+ License-File: LICENSE
30
+ Requires-Dist: Django>=4.2
31
+ Requires-Dist: django-htmx>=1.17
32
+ Provides-Extra: dev
33
+ Requires-Dist: pytest; extra == "dev"
34
+ Requires-Dist: pytest-django; extra == "dev"
35
+ Requires-Dist: build; extra == "dev"
36
+ Requires-Dist: twine; extra == "dev"
37
+ Dynamic: license-file
38
+
39
+ # DORM
40
+
41
+ A Django ORM playground — a dev-only web UI to run ORM queries against your connected database.
42
+
43
+ ## Install
44
+
45
+ ```bash
46
+ pip install dorm-plg
47
+ ```
48
+
49
+ ## Setup
50
+
51
+ ```python
52
+ # settings.py
53
+ INSTALLED_APPS = [..., "django_htmx", "dorm"]
54
+ MIDDLEWARE = [..., "django_htmx.middleware.HtmxMiddleware"]
55
+ ```
56
+
57
+ ```python
58
+ # urls.py
59
+ from django.urls import path, include
60
+
61
+ urlpatterns = [
62
+ ...
63
+ path("__dorm__/", include("dorm.urls", namespace="dorm")),
64
+ ]
65
+ ```
66
+
67
+ Open `/__dorm__/` in your browser and start writing ORM queries.
68
+
69
+ > **Warning**: DORM executes arbitrary Python code in your Django process. It is gated behind `DEBUG=True` and must never be used in production.
70
+
71
+ ## Usage
72
+
73
+ In the playground editor, write any Django ORM expression. All models from your `INSTALLED_APPS` are available without importing them:
74
+
75
+ ```python
76
+ # Get all users
77
+ User.objects.all()
78
+
79
+ # Filter with related fields
80
+ Book.objects.filter(author__name="Tolkien").select_related("author")
81
+
82
+ # Aggregations
83
+ from django.db.models import Count
84
+ Author.objects.annotate(book_count=Count("books")).order_by("-book_count")
85
+ ```
86
+
87
+ Press **Ctrl+Enter** or click **Run** to execute. Results are rendered as a table.
88
+
89
+ ## Development
90
+
91
+ ```bash
92
+ git clone https://github.com/yourname/dorm
93
+ cd dorm
94
+ python3.10 -m venv .venv
95
+ source .venv/bin/activate
96
+ pip install -e ".[dev]"
97
+ cd sandbox && python manage.py migrate && python manage.py runserver
98
+ # Open: http://127.0.0.1:8000/__dorm__/
99
+ ```
@@ -0,0 +1,61 @@
1
+ # DORM
2
+
3
+ A Django ORM playground — a dev-only web UI to run ORM queries against your connected database.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ pip install dorm-plg
9
+ ```
10
+
11
+ ## Setup
12
+
13
+ ```python
14
+ # settings.py
15
+ INSTALLED_APPS = [..., "django_htmx", "dorm"]
16
+ MIDDLEWARE = [..., "django_htmx.middleware.HtmxMiddleware"]
17
+ ```
18
+
19
+ ```python
20
+ # urls.py
21
+ from django.urls import path, include
22
+
23
+ urlpatterns = [
24
+ ...
25
+ path("__dorm__/", include("dorm.urls", namespace="dorm")),
26
+ ]
27
+ ```
28
+
29
+ Open `/__dorm__/` in your browser and start writing ORM queries.
30
+
31
+ > **Warning**: DORM executes arbitrary Python code in your Django process. It is gated behind `DEBUG=True` and must never be used in production.
32
+
33
+ ## Usage
34
+
35
+ In the playground editor, write any Django ORM expression. All models from your `INSTALLED_APPS` are available without importing them:
36
+
37
+ ```python
38
+ # Get all users
39
+ User.objects.all()
40
+
41
+ # Filter with related fields
42
+ Book.objects.filter(author__name="Tolkien").select_related("author")
43
+
44
+ # Aggregations
45
+ from django.db.models import Count
46
+ Author.objects.annotate(book_count=Count("books")).order_by("-book_count")
47
+ ```
48
+
49
+ Press **Ctrl+Enter** or click **Run** to execute. Results are rendered as a table.
50
+
51
+ ## Development
52
+
53
+ ```bash
54
+ git clone https://github.com/yourname/dorm
55
+ cd dorm
56
+ python3.10 -m venv .venv
57
+ source .venv/bin/activate
58
+ pip install -e ".[dev]"
59
+ cd sandbox && python manage.py migrate && python manage.py runserver
60
+ # Open: http://127.0.0.1:8000/__dorm__/
61
+ ```
@@ -0,0 +1,7 @@
1
+ __version__ = "0.1.0"
2
+
3
+
4
+ def get_url_prefix() -> str:
5
+ """Return the URL prefix for DORM, read from settings.DORM_URL (default: '__dorm__')."""
6
+ from django.conf import settings
7
+ return getattr(settings, "DORM_URL_NAME", "__dorm__")
@@ -0,0 +1,16 @@
1
+ from django.apps import AppConfig
2
+
3
+
4
+ class DormConfig(AppConfig):
5
+ name = "dorm"
6
+ default_auto_field = "django.db.models.BigAutoField"
7
+
8
+ def ready(self):
9
+ import logging
10
+ from django.conf import settings
11
+
12
+ if not settings.DEBUG:
13
+ logging.getLogger("dorm").warning(
14
+ "DORM is installed but DEBUG=False — all requests will return 404. "
15
+ "Consider removing 'dorm' from INSTALLED_APPS in production."
16
+ )
@@ -0,0 +1,6 @@
1
+ class DormNotDebugError(Exception):
2
+ pass
3
+
4
+
5
+ class DormExecutionError(Exception):
6
+ pass
@@ -0,0 +1,63 @@
1
+ import ast
2
+ import traceback as tb
3
+
4
+
5
+ def _build_namespace() -> dict:
6
+ from django.apps import apps
7
+ from django.db.models import Avg, Count, F, Max, Min, OuterRef, Q, Subquery, Sum, Value
8
+
9
+ namespace: dict = {
10
+ "Q": Q, "F": F,
11
+ "Count": Count, "Sum": Sum, "Avg": Avg, "Max": Max, "Min": Min,
12
+ "Value": Value, "OuterRef": OuterRef, "Subquery": Subquery,
13
+ }
14
+ for model in apps.get_models():
15
+ namespace[model.__name__] = model
16
+ return namespace
17
+
18
+
19
+ def execute(code: str, extra_locals: dict | None = None) -> dict:
20
+ """
21
+ Execute a multi-line ORM code string.
22
+
23
+ The last expression in the code block is captured as the result,
24
+ mimicking REPL behaviour. Returns:
25
+ {"success": True, "result": <any>}
26
+ {"success": False, "error_type": str, "error": str, "traceback": str}
27
+ """
28
+ namespace = _build_namespace()
29
+ if extra_locals:
30
+ namespace.update(extra_locals)
31
+
32
+ try:
33
+ tree = ast.parse(code)
34
+ except SyntaxError as e:
35
+ return {
36
+ "success": False,
37
+ "error_type": "SyntaxError",
38
+ "error": str(e),
39
+ "traceback": "",
40
+ }
41
+
42
+ try:
43
+ result = None
44
+ if tree.body and isinstance(tree.body[-1], ast.Expr):
45
+ # Split: exec all statements, eval the last expression
46
+ exec_tree = ast.Module(body=tree.body[:-1], type_ignores=[])
47
+ eval_tree = ast.Expression(body=tree.body[-1].value)
48
+ ast.fix_missing_locations(exec_tree)
49
+ ast.fix_missing_locations(eval_tree)
50
+ exec(compile(exec_tree, "<dorm>", "exec"), namespace)
51
+ result = eval(compile(eval_tree, "<dorm>", "eval"), namespace)
52
+ else:
53
+ exec(compile(tree, "<dorm>", "exec"), namespace)
54
+
55
+ return {"success": True, "result": result}
56
+
57
+ except Exception as e:
58
+ return {
59
+ "success": False,
60
+ "error_type": type(e).__name__,
61
+ "error": str(e),
62
+ "traceback": tb.format_exc(),
63
+ }
@@ -0,0 +1,383 @@
1
+ /* DORM — Django ORM Playground */
2
+
3
+ :root {
4
+ --bg: #e0e0e0;
5
+ --surface: #ffffff;
6
+ --border: #cccccc;
7
+ --header-bg: #111111;
8
+ --header-text: #ffffff;
9
+ --pane-bar-bg: #f4f4f4;
10
+ --pane-bar-border: #e0e0e0;
11
+ --text: #000000;
12
+ --text-muted: #666666;
13
+ --divider: #c0c0c0;
14
+ --divider-hover: #555555;
15
+ --btn-bg: #000000;
16
+ --btn-text: #ffffff;
17
+ --btn-hover: #333333;
18
+ --th-bg: #1a1a1a;
19
+ --th-text: #ffffff;
20
+ --td-border: #eeeeee;
21
+ --row-hover: #fafafa;
22
+ --value-bg: #f8f8f8;
23
+ --error-bg: #fff8f8;
24
+ --error-border: #e0b0b0;
25
+ --error-text: #cc0000;
26
+ --kbd-bg: rgba(255,255,255,0.18);
27
+ }
28
+
29
+ *, *::before, *::after {
30
+ box-sizing: border-box;
31
+ margin: 0;
32
+ padding: 0;
33
+ }
34
+
35
+ html, body {
36
+ height: 100%;
37
+ overflow: hidden;
38
+ font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
39
+ background: var(--bg);
40
+ color: var(--text);
41
+ }
42
+
43
+ /* ── Root shell ──────────────────────────────────────────── */
44
+
45
+ .dorm-root {
46
+ display: flex;
47
+ flex-direction: column;
48
+ height: 100vh;
49
+ overflow: hidden;
50
+ }
51
+
52
+ /* ── Header ──────────────────────────────────────────────── */
53
+
54
+ .dorm-header {
55
+ flex: 0 0 auto;
56
+ display: flex;
57
+ align-items: center;
58
+ justify-content: space-between;
59
+ padding: 0 1rem;
60
+ height: 44px;
61
+ background: var(--header-bg);
62
+ color: var(--header-text);
63
+ }
64
+
65
+ .dorm-logo {
66
+ font-size: 0.95rem;
67
+ font-weight: 700;
68
+ letter-spacing: 0.18em;
69
+ color: var(--header-text);
70
+ }
71
+
72
+ /* ── Layout toggle buttons ───────────────────────────────── */
73
+
74
+ .dorm-layout-toggle {
75
+ display: flex;
76
+ gap: 2px;
77
+ background: rgba(255,255,255,0.08);
78
+ border-radius: 5px;
79
+ padding: 3px;
80
+ }
81
+
82
+ .dorm-layout-opt {
83
+ display: flex;
84
+ align-items: center;
85
+ justify-content: center;
86
+ width: 30px;
87
+ height: 26px;
88
+ background: transparent;
89
+ border: none;
90
+ border-radius: 3px;
91
+ color: #888;
92
+ cursor: pointer;
93
+ transition: background 0.1s, color 0.1s;
94
+ }
95
+
96
+ .dorm-layout-opt:hover {
97
+ color: #ccc;
98
+ }
99
+
100
+ .dorm-layout-opt.active {
101
+ background: #ffffff;
102
+ color: #000000;
103
+ }
104
+
105
+ /* ── Split layout container ──────────────────────────────── */
106
+
107
+ .dorm-layout {
108
+ flex: 1;
109
+ display: flex;
110
+ min-height: 0;
111
+ gap: 0;
112
+ }
113
+
114
+ .dorm-layout[data-dir="row"] { flex-direction: row; }
115
+ .dorm-layout[data-dir="col"] { flex-direction: column; }
116
+
117
+ /* ── Panes ───────────────────────────────────────────────── */
118
+
119
+ .dorm-pane {
120
+ display: flex;
121
+ flex-direction: column;
122
+ overflow: hidden;
123
+ min-width: 0;
124
+ min-height: 0;
125
+ background: var(--surface);
126
+ }
127
+
128
+ #dorm-pane-a { flex: 0 0 50%; }
129
+ #dorm-pane-b { flex: 1 1 0; }
130
+
131
+ /* ── Pane top bar ────────────────────────────────────────── */
132
+
133
+ .dorm-pane-bar {
134
+ flex: 0 0 auto;
135
+ display: flex;
136
+ align-items: center;
137
+ justify-content: space-between;
138
+ padding: 0 0.875rem;
139
+ height: 36px;
140
+ background: var(--pane-bar-bg);
141
+ border-bottom: 1px solid var(--pane-bar-border);
142
+ }
143
+
144
+ .dorm-pane-label {
145
+ font-size: 0.72rem;
146
+ font-weight: 600;
147
+ letter-spacing: 0.1em;
148
+ text-transform: uppercase;
149
+ color: var(--text-muted);
150
+ }
151
+
152
+ /* ── Editor (input pane) ─────────────────────────────────── */
153
+
154
+ #dorm-form {
155
+ flex: 1;
156
+ display: flex;
157
+ flex-direction: column;
158
+ min-height: 0;
159
+ }
160
+
161
+ .dorm-editor {
162
+ flex: 1;
163
+ width: 100%;
164
+ padding: 0.875rem 1rem;
165
+ background: var(--surface);
166
+ color: var(--text);
167
+ font-family: "JetBrains Mono", "Fira Code", Consolas, "Courier New", monospace;
168
+ font-size: 0.875rem;
169
+ line-height: 1.65;
170
+ border: none;
171
+ outline: none;
172
+ resize: none;
173
+ }
174
+
175
+ /* ── Verbose names checkbox ──────────────────────────────── */
176
+
177
+ .dorm-verbose-label {
178
+ display: flex;
179
+ align-items: center;
180
+ gap: 0.35rem;
181
+ font-size: 0.72rem;
182
+ font-weight: 500;
183
+ color: var(--text-muted);
184
+ cursor: pointer;
185
+ user-select: none;
186
+ }
187
+
188
+ .dorm-verbose-label input[type="checkbox"] {
189
+ accent-color: var(--btn-bg);
190
+ cursor: pointer;
191
+ width: 13px;
192
+ height: 13px;
193
+ }
194
+
195
+ /* ── Run button ──────────────────────────────────────────── */
196
+
197
+ .dorm-run-btn {
198
+ display: inline-flex;
199
+ align-items: center;
200
+ gap: 0.45rem;
201
+ padding: 0.3rem 0.9rem;
202
+ background: var(--btn-bg);
203
+ color: var(--btn-text);
204
+ border: none;
205
+ border-radius: 4px;
206
+ font-size: 0.8rem;
207
+ font-weight: 600;
208
+ cursor: pointer;
209
+ transition: background 0.12s;
210
+ }
211
+
212
+ .dorm-run-btn:hover { background: var(--btn-hover); }
213
+ .dorm-run-btn:active { background: #555; }
214
+
215
+ kbd {
216
+ font-size: 0.7rem;
217
+ padding: 0.1em 0.35em;
218
+ background: var(--kbd-bg);
219
+ border-radius: 3px;
220
+ font-family: inherit;
221
+ }
222
+
223
+ /* ── Divider ─────────────────────────────────────────────── */
224
+
225
+ .dorm-divider {
226
+ flex: 0 0 5px;
227
+ background: var(--divider);
228
+ transition: background 0.12s;
229
+ position: relative;
230
+ }
231
+
232
+ .dorm-layout[data-dir="row"] .dorm-divider { cursor: col-resize; }
233
+ .dorm-layout[data-dir="col"] .dorm-divider { cursor: row-resize; }
234
+
235
+ .dorm-divider:hover { background: var(--divider-hover); }
236
+
237
+ /* Expand hit area by 4px on each side */
238
+ .dorm-layout[data-dir="row"] .dorm-divider::after {
239
+ content: "";
240
+ position: absolute;
241
+ inset: 0 -4px;
242
+ }
243
+ .dorm-layout[data-dir="col"] .dorm-divider::after {
244
+ content: "";
245
+ position: absolute;
246
+ inset: -4px 0;
247
+ }
248
+
249
+ /* ── Result body ─────────────────────────────────────────── */
250
+
251
+ .dorm-result-body {
252
+ flex: 1;
253
+ overflow: auto;
254
+ padding: 0.875rem 1rem;
255
+ }
256
+
257
+ /* ── Result bar (meta + export buttons) ─────────────────── */
258
+
259
+ .dorm-result-bar {
260
+ display: flex;
261
+ align-items: center;
262
+ justify-content: space-between;
263
+ margin-bottom: 0.5rem;
264
+ }
265
+
266
+ .dorm-result-meta {
267
+ font-size: 0.75rem;
268
+ color: var(--text-muted);
269
+ margin-bottom: 0.5rem;
270
+ }
271
+
272
+ .dorm-export-btns {
273
+ display: flex;
274
+ gap: 4px;
275
+ }
276
+
277
+ .dorm-export-btn {
278
+ padding: 0.2rem 0.6rem;
279
+ background: transparent;
280
+ color: var(--text-muted);
281
+ border: 1px solid var(--border);
282
+ border-radius: 3px;
283
+ font-size: 0.72rem;
284
+ font-weight: 600;
285
+ cursor: pointer;
286
+ transition: background 0.1s, color 0.1s, border-color 0.1s;
287
+ }
288
+
289
+ .dorm-export-btn:hover {
290
+ background: var(--btn-bg);
291
+ color: var(--btn-text);
292
+ border-color: var(--btn-bg);
293
+ }
294
+
295
+ .dorm-table-wrapper {
296
+ overflow-x: auto;
297
+ border: 1px solid var(--border);
298
+ border-radius: 4px;
299
+ }
300
+
301
+ .dorm-table {
302
+ width: 100%;
303
+ border-collapse: collapse;
304
+ font-size: 0.8rem;
305
+ }
306
+
307
+ .dorm-table th {
308
+ padding: 0.5rem 0.875rem;
309
+ background: var(--th-bg);
310
+ color: var(--th-text);
311
+ text-align: left;
312
+ font-weight: 600;
313
+ white-space: nowrap;
314
+ border-bottom: none;
315
+ }
316
+
317
+ .dorm-table td {
318
+ padding: 0.4rem 0.875rem;
319
+ border-bottom: 1px solid var(--td-border);
320
+ color: var(--text);
321
+ font-family: "JetBrains Mono", Consolas, monospace;
322
+ white-space: nowrap;
323
+ }
324
+
325
+ .dorm-table tr:last-child td { border-bottom: none; }
326
+ .dorm-table tr:hover td { background: var(--row-hover); }
327
+
328
+ /* ── Value output ────────────────────────────────────────── */
329
+
330
+ .dorm-value {
331
+ padding: 0.875rem 1rem;
332
+ background: var(--value-bg);
333
+ border: 1px solid var(--border);
334
+ border-radius: 4px;
335
+ color: var(--text);
336
+ font-family: "JetBrains Mono", Consolas, monospace;
337
+ font-size: 0.8rem;
338
+ white-space: pre-wrap;
339
+ word-break: break-word;
340
+ }
341
+
342
+ /* ── Error output ────────────────────────────────────────── */
343
+
344
+ .dorm-error {
345
+ padding: 0.875rem 1rem;
346
+ background: var(--error-bg);
347
+ border: 1px solid var(--error-border);
348
+ border-radius: 4px;
349
+ }
350
+
351
+ .dorm-error-title {
352
+ font-family: "JetBrains Mono", Consolas, monospace;
353
+ font-size: 0.8rem;
354
+ font-weight: 700;
355
+ color: var(--error-text);
356
+ margin-bottom: 0.5rem;
357
+ }
358
+
359
+ .dorm-error-traceback {
360
+ font-family: "JetBrains Mono", Consolas, monospace;
361
+ font-size: 0.75rem;
362
+ color: var(--error-text);
363
+ white-space: pre-wrap;
364
+ word-break: break-word;
365
+ opacity: 0.75;
366
+ }
367
+
368
+ /* ── Drag state ──────────────────────────────────────────── */
369
+
370
+ body.is-resizing-row {
371
+ cursor: col-resize !important;
372
+ user-select: none;
373
+ }
374
+ body.is-resizing-col {
375
+ cursor: row-resize !important;
376
+ user-select: none;
377
+ }
378
+
379
+ /* Prevent pane content from stealing the cursor during drag */
380
+ body.is-resizing-row .dorm-pane,
381
+ body.is-resizing-col .dorm-pane {
382
+ pointer-events: none;
383
+ }