@cubocicloide/stack-react-django 3.0.4
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.
- package/LICENSE +33 -0
- package/README.md +66 -0
- package/dist/commands/lint/checks/BE/001.d.ts +6 -0
- package/dist/commands/lint/checks/BE/001.js +94 -0
- package/dist/commands/lint/checks/BE/001.js.map +1 -0
- package/dist/commands/lint/checks/BE/002.d.ts +6 -0
- package/dist/commands/lint/checks/BE/002.js +136 -0
- package/dist/commands/lint/checks/BE/002.js.map +1 -0
- package/dist/commands/lint/checks/BE/003.d.ts +6 -0
- package/dist/commands/lint/checks/BE/003.js +89 -0
- package/dist/commands/lint/checks/BE/003.js.map +1 -0
- package/dist/commands/lint/checks/BE/004.d.ts +6 -0
- package/dist/commands/lint/checks/BE/004.js +68 -0
- package/dist/commands/lint/checks/BE/004.js.map +1 -0
- package/dist/commands/lint/checks/BE/005.d.ts +6 -0
- package/dist/commands/lint/checks/BE/005.js +55 -0
- package/dist/commands/lint/checks/BE/005.js.map +1 -0
- package/dist/commands/lint/checks/BE/006.d.ts +6 -0
- package/dist/commands/lint/checks/BE/006.js +95 -0
- package/dist/commands/lint/checks/BE/006.js.map +1 -0
- package/dist/commands/lint/checks/BE/007.d.ts +6 -0
- package/dist/commands/lint/checks/BE/007.js +53 -0
- package/dist/commands/lint/checks/BE/007.js.map +1 -0
- package/dist/commands/lint/checks/BE/008.d.ts +6 -0
- package/dist/commands/lint/checks/BE/008.js +70 -0
- package/dist/commands/lint/checks/BE/008.js.map +1 -0
- package/dist/commands/lint/checks/BE/009.d.ts +6 -0
- package/dist/commands/lint/checks/BE/009.js +112 -0
- package/dist/commands/lint/checks/BE/009.js.map +1 -0
- package/dist/commands/lint/checks/BE/010.d.ts +6 -0
- package/dist/commands/lint/checks/BE/010.js +76 -0
- package/dist/commands/lint/checks/BE/010.js.map +1 -0
- package/dist/commands/lint/checks/BE/011.d.ts +6 -0
- package/dist/commands/lint/checks/BE/011.js +76 -0
- package/dist/commands/lint/checks/BE/011.js.map +1 -0
- package/dist/commands/lint/checks/BE/012.d.ts +6 -0
- package/dist/commands/lint/checks/BE/012.js +61 -0
- package/dist/commands/lint/checks/BE/012.js.map +1 -0
- package/dist/commands/lint/checks/BE/013.d.ts +6 -0
- package/dist/commands/lint/checks/BE/013.js +98 -0
- package/dist/commands/lint/checks/BE/013.js.map +1 -0
- package/dist/commands/lint/checks/BE/014.d.ts +6 -0
- package/dist/commands/lint/checks/BE/014.js +64 -0
- package/dist/commands/lint/checks/BE/014.js.map +1 -0
- package/dist/commands/lint/checks/E2E/001.d.ts +6 -0
- package/dist/commands/lint/checks/E2E/001.js +35 -0
- package/dist/commands/lint/checks/E2E/001.js.map +1 -0
- package/dist/commands/lint/checks/E2E/002.d.ts +6 -0
- package/dist/commands/lint/checks/E2E/002.js +37 -0
- package/dist/commands/lint/checks/E2E/002.js.map +1 -0
- package/dist/commands/lint/checks/E2E/003.d.ts +6 -0
- package/dist/commands/lint/checks/E2E/003.js +42 -0
- package/dist/commands/lint/checks/E2E/003.js.map +1 -0
- package/dist/commands/lint/checks/E2E/004.d.ts +6 -0
- package/dist/commands/lint/checks/E2E/004.js +37 -0
- package/dist/commands/lint/checks/E2E/004.js.map +1 -0
- package/dist/commands/lint/checks/E2E/005.d.ts +6 -0
- package/dist/commands/lint/checks/E2E/005.js +47 -0
- package/dist/commands/lint/checks/E2E/005.js.map +1 -0
- package/dist/commands/lint/checks/E2E/006.d.ts +6 -0
- package/dist/commands/lint/checks/E2E/006.js +28 -0
- package/dist/commands/lint/checks/E2E/006.js.map +1 -0
- package/dist/commands/lint/checks/E2E/007.d.ts +6 -0
- package/dist/commands/lint/checks/E2E/007.js +47 -0
- package/dist/commands/lint/checks/E2E/007.js.map +1 -0
- package/dist/commands/lint/checks/FE/001.d.ts +6 -0
- package/dist/commands/lint/checks/FE/001.js +56 -0
- package/dist/commands/lint/checks/FE/001.js.map +1 -0
- package/dist/commands/lint/checks/FE/002.d.ts +6 -0
- package/dist/commands/lint/checks/FE/002.js +80 -0
- package/dist/commands/lint/checks/FE/002.js.map +1 -0
- package/dist/commands/lint/checks/FE/003.d.ts +6 -0
- package/dist/commands/lint/checks/FE/003.js +65 -0
- package/dist/commands/lint/checks/FE/003.js.map +1 -0
- package/dist/commands/lint/checks/FE/004.d.ts +6 -0
- package/dist/commands/lint/checks/FE/004.js +72 -0
- package/dist/commands/lint/checks/FE/004.js.map +1 -0
- package/dist/commands/lint/checks/FE/005.d.ts +6 -0
- package/dist/commands/lint/checks/FE/005.js +103 -0
- package/dist/commands/lint/checks/FE/005.js.map +1 -0
- package/dist/commands/lint/checks/FE/006.d.ts +6 -0
- package/dist/commands/lint/checks/FE/006.js +102 -0
- package/dist/commands/lint/checks/FE/006.js.map +1 -0
- package/dist/commands/lint/checks/FE/007.d.ts +6 -0
- package/dist/commands/lint/checks/FE/007.js +60 -0
- package/dist/commands/lint/checks/FE/007.js.map +1 -0
- package/dist/commands/lint/checks/FE/008.d.ts +6 -0
- package/dist/commands/lint/checks/FE/008.js +115 -0
- package/dist/commands/lint/checks/FE/008.js.map +1 -0
- package/dist/commands/lint/checks/FE/009.d.ts +6 -0
- package/dist/commands/lint/checks/FE/009.js +83 -0
- package/dist/commands/lint/checks/FE/009.js.map +1 -0
- package/dist/commands/lint/checks/FE/010.d.ts +6 -0
- package/dist/commands/lint/checks/FE/010.js +105 -0
- package/dist/commands/lint/checks/FE/010.js.map +1 -0
- package/dist/commands/lint/checks/FE/011.d.ts +6 -0
- package/dist/commands/lint/checks/FE/011.js +43 -0
- package/dist/commands/lint/checks/FE/011.js.map +1 -0
- package/dist/commands/lint/checks/FE/012.d.ts +6 -0
- package/dist/commands/lint/checks/FE/012.js +150 -0
- package/dist/commands/lint/checks/FE/012.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +3436 -0
- package/dist/index.js.map +1 -0
- package/dude.stack.json +13 -0
- package/package.json +43 -0
- package/templates/aws-ecs/backend/Dockerfile.prod +34 -0
- package/templates/aws-ecs/docs/docs/deploy.md.hbs +54 -0
- package/templates/aws-ecs/frontend/Dockerfile.prod +28 -0
- package/templates/aws-ecs/frontend/nginx.conf +21 -0
- package/templates/aws-ecs/iac/README.md.hbs +75 -0
- package/templates/aws-ecs/iac/_gitignore +14 -0
- package/templates/aws-ecs/iac/runner/Dockerfile +35 -0
- package/templates/aws-ecs/iac/terraform/bootstrap/main.tf.hbs +102 -0
- package/templates/aws-ecs/iac/terraform/bootstrap/outputs.tf +19 -0
- package/templates/aws-ecs/iac/terraform/bootstrap/variables.tf.hbs +17 -0
- package/templates/aws-ecs/iac/terraform/environments/dev/backend.hcl.hbs +12 -0
- package/templates/aws-ecs/iac/terraform/environments/dev/terraform.tfvars.hbs +43 -0
- package/templates/aws-ecs/iac/terraform/main.tf.hbs +949 -0
- package/templates/aws-ecs/iac/terraform/outputs.tf.hbs +71 -0
- package/templates/aws-ecs/iac/terraform/providers.tf +19 -0
- package/templates/aws-ecs/iac/terraform/variables.tf.hbs +113 -0
- package/templates/aws-ecs/iac/terraform/versions.tf +19 -0
- package/templates/base/.claude/agents/issue-fixer.md +190 -0
- package/templates/base/.claude/agents/security-fixer.md +250 -0
- package/templates/base/.claude/rules/BE/001.md +19 -0
- package/templates/base/.claude/rules/BE/002.md +21 -0
- package/templates/base/.claude/rules/BE/003.md +19 -0
- package/templates/base/.claude/rules/BE/004.md +16 -0
- package/templates/base/.claude/rules/BE/005.md +23 -0
- package/templates/base/.claude/rules/BE/006.md +13 -0
- package/templates/base/.claude/rules/BE/007.md +24 -0
- package/templates/base/.claude/rules/BE/008.md +19 -0
- package/templates/base/.claude/rules/BE/009.md +18 -0
- package/templates/base/.claude/rules/BE/010.md +15 -0
- package/templates/base/.claude/rules/BE/011.md +17 -0
- package/templates/base/.claude/rules/BE/012.md +18 -0
- package/templates/base/.claude/rules/BE/013.md +22 -0
- package/templates/base/.claude/rules/BE/014.md +15 -0
- package/templates/base/.claude/rules/E2E/001.md +13 -0
- package/templates/base/.claude/rules/E2E/002.md +14 -0
- package/templates/base/.claude/rules/E2E/003.md +10 -0
- package/templates/base/.claude/rules/E2E/004.md +23 -0
- package/templates/base/.claude/rules/E2E/005.md +15 -0
- package/templates/base/.claude/rules/E2E/006.md +13 -0
- package/templates/base/.claude/rules/E2E/007.md +18 -0
- package/templates/base/.claude/rules/FE/001.md +22 -0
- package/templates/base/.claude/rules/FE/002.md +39 -0
- package/templates/base/.claude/rules/FE/003.md +19 -0
- package/templates/base/.claude/rules/FE/004.md +21 -0
- package/templates/base/.claude/rules/FE/005.md +33 -0
- package/templates/base/.claude/rules/FE/006.md +24 -0
- package/templates/base/.claude/rules/FE/007.md +19 -0
- package/templates/base/.claude/rules/FE/008.md +26 -0
- package/templates/base/.claude/rules/FE/009.md +30 -0
- package/templates/base/.claude/rules/FE/010.md +25 -0
- package/templates/base/.claude/rules/FE/011.md +22 -0
- package/templates/base/.claude/rules/FE/012.md +32 -0
- package/templates/base/.claude/settings.json +53 -0
- package/templates/base/.claude/skills/clean-branches/SKILL.md +100 -0
- package/templates/base/.claude/skills/create/SKILL.md +47 -0
- package/templates/base/.claude/skills/create-jira-issue/SKILL.md +174 -0
- package/templates/base/.claude/skills/create-page/SKILL.md +195 -0
- package/templates/base/.claude/skills/create-route/SKILL.md +156 -0
- package/templates/base/.claude/skills/draft-email/SKILL.md +104 -0
- package/templates/base/.claude/skills/fix-issues/SKILL.md +238 -0
- package/templates/base/.claude/skills/security-scan/SKILL.md +297 -0
- package/templates/base/.claude/skills/verify-security-fixes/SKILL.md +180 -0
- package/templates/base/.dude/commands/README.md +85 -0
- package/templates/base/.dude/commands/hello.ts +34 -0
- package/templates/base/.dude/lint/checks/PRJ/001.ts +26 -0
- package/templates/base/.dude/lint/checks/README.md +69 -0
- package/templates/base/.vscode/tasks.json +44 -0
- package/templates/base/.worktreeinclude +2 -0
- package/templates/base/CLAUDE.md.hbs +391 -0
- package/templates/base/README.md.hbs +188 -0
- package/templates/base/_env.example.hbs +39 -0
- package/templates/base/_env.hbs +35 -0
- package/templates/base/_gitignore +31 -0
- package/templates/base/_npmrc +2 -0
- package/templates/base/backend/Dockerfile +16 -0
- package/templates/base/backend/README.md.hbs +90 -0
- package/templates/base/backend/_dockerignore +12 -0
- package/templates/base/backend/apps/__init__.py +0 -0
- package/templates/base/backend/apps/core/__init__.py +0 -0
- package/templates/base/backend/apps/core/apps.py +6 -0
- package/templates/base/backend/apps/core/serializers.py +7 -0
- package/templates/base/backend/apps/core/tests/__init__.py +0 -0
- package/templates/base/backend/apps/core/tests/test_views.py +16 -0
- package/templates/base/backend/apps/core/urls.py +9 -0
- package/templates/base/backend/apps/core/views.py +24 -0
- package/templates/base/backend/apps/users/__init__.py +0 -0
- package/templates/base/backend/apps/users/admin.py +6 -0
- package/templates/base/backend/apps/users/apps.py +6 -0
- package/templates/base/backend/apps/users/migrations/0001_initial.py +41 -0
- package/templates/base/backend/apps/users/migrations/__init__.py +0 -0
- package/templates/base/backend/apps/users/models.py +15 -0
- package/templates/base/backend/apps/users/serializers.py +16 -0
- package/templates/base/backend/apps/users/services.py +25 -0
- package/templates/base/backend/apps/users/tests/__init__.py +0 -0
- package/templates/base/backend/apps/users/tests/test_models.py +30 -0
- package/templates/base/backend/apps/users/tests/test_views.py +55 -0
- package/templates/base/backend/apps/users/urls.py +10 -0
- package/templates/base/backend/apps/users/views.py +20 -0
- package/templates/base/backend/config/__init__.py.hbs +5 -0
- package/templates/base/backend/config/asgi.py +9 -0
- package/templates/base/backend/config/settings/__init__.py +0 -0
- package/templates/base/backend/config/settings/base.py.hbs +197 -0
- package/templates/base/backend/config/settings/local.py +31 -0
- package/templates/base/backend/config/settings/production.py.hbs +37 -0
- package/templates/base/backend/config/urls.py.hbs +22 -0
- package/templates/base/backend/config/wsgi.py +9 -0
- package/templates/base/backend/manage.py +23 -0
- package/templates/base/backend/pyproject.toml.hbs +48 -0
- package/templates/base/backend/start.sh +5 -0
- package/templates/base/docker-compose.yml.hbs +196 -0
- package/templates/base/docs/docs/api.md +21 -0
- package/templates/base/docs/docs/dude.md.hbs +305 -0
- package/templates/base/docs/docs/index.md.hbs +92 -0
- package/templates/base/docs/docs/mkdocs.md +231 -0
- package/templates/base/docs/mkdocs.yml.hbs +52 -0
- package/templates/base/e2e/.prettierrc.json +1 -0
- package/templates/base/e2e/_prettierignore +3 -0
- package/templates/base/e2e/cucumber.js +21 -0
- package/templates/base/e2e/eslint.config.mjs +14 -0
- package/templates/base/e2e/features/example.feature +13 -0
- package/templates/base/e2e/package.json.hbs +30 -0
- package/templates/base/e2e/pages/ExamplePage.ts +16 -0
- package/templates/base/e2e/playwright.config.ts +27 -0
- package/templates/base/e2e/steps/common.steps.ts +32 -0
- package/templates/base/e2e/steps/example.steps.ts +4 -0
- package/templates/base/e2e/support/hooks.ts +72 -0
- package/templates/base/e2e/support/world.ts +24 -0
- package/templates/base/e2e/tsconfig.json +22 -0
- package/templates/base/frontend/.prettierrc.json +6 -0
- package/templates/base/frontend/Dockerfile +10 -0
- package/templates/base/frontend/_dockerignore +4 -0
- package/templates/base/frontend/eslint.config.js +32 -0
- package/templates/base/frontend/index.html.hbs +13 -0
- package/templates/base/frontend/package.json.hbs +38 -0
- package/templates/base/frontend/public/favicon.svg +5 -0
- package/templates/base/frontend/src/$components/Layout/$assets/logo.svg +5 -0
- package/templates/base/frontend/src/$components/Layout/constants.tsx +8 -0
- package/templates/base/frontend/src/$components/Layout/index.tsx +80 -0
- package/templates/base/frontend/src/$components/Layout/types.tsx +9 -0
- package/templates/base/frontend/src/$components/index.tsx +1 -0
- package/templates/base/frontend/src/$hooks/index.tsx +2 -0
- package/templates/base/frontend/src/$hooks/useCounterStore/index.tsx +28 -0
- package/templates/base/frontend/src/$hooks/useCounterStore/types.tsx +7 -0
- package/templates/base/frontend/src/$hooks/usePageTitle/index.tsx +21 -0
- package/templates/base/frontend/src/$types/vite-env.d.ts +10 -0
- package/templates/base/frontend/src/App.tsx +36 -0
- package/templates/base/frontend/src/main.tsx +10 -0
- package/templates/base/frontend/src/openapi/utils/openapi.yaml.hbs +129 -0
- package/templates/base/frontend/src/pages/constants.tsx +31 -0
- package/templates/base/frontend/src/pages/index.tsx +192 -0
- package/templates/base/frontend/src/pages/types.tsx +6 -0
- package/templates/base/frontend/src/pages/users/[id]/index.tsx +53 -0
- package/templates/base/frontend/src/pages/users/index.tsx +57 -0
- package/templates/base/frontend/src/pages/users/types.tsx +4 -0
- package/templates/base/frontend/src/styles.module.css +7 -0
- package/templates/base/frontend/src/utils/constants.tsx +11 -0
- package/templates/base/frontend/src/utils/formatters/index.tsx +49 -0
- package/templates/base/frontend/src/utils/functions.tsx +70 -0
- package/templates/base/frontend/src/utils/index.tsx +3 -0
- package/templates/base/frontend/tsconfig.json +24 -0
- package/templates/base/frontend/vite.config.ts +20 -0
- package/templates/base/package.json.hbs +11 -0
- package/templates/base/security/baseline.json +4 -0
- package/templates/celery/backend/apps/core/tasks.py +14 -0
- package/templates/celery/backend/apps/core/tests/test_tasks.py +6 -0
- package/templates/celery/backend/config/celery.py.hbs +26 -0
- package/templates/celerybeat/backend/apps/core/tasks_scheduled.py +18 -0
- package/templates/celerybeat/backend/apps/core/tests/test_tasks_scheduled.py +6 -0
- package/templates/postgres/.dude/commands/reset.ts +83 -0
- package/templates/s3/backend/apps/files/__init__.py +0 -0
- package/templates/s3/backend/apps/files/admin.py +9 -0
- package/templates/s3/backend/apps/files/apps.py +6 -0
- package/templates/s3/backend/apps/files/migrations/0001_initial.py +29 -0
- package/templates/s3/backend/apps/files/migrations/__init__.py +0 -0
- package/templates/s3/backend/apps/files/models.py +21 -0
- package/templates/s3/backend/apps/files/serializers.py +27 -0
- package/templates/s3/backend/apps/files/services.py +19 -0
- package/templates/s3/backend/apps/files/tests/__init__.py +0 -0
- package/templates/s3/backend/apps/files/tests/test_models.py +10 -0
- package/templates/s3/backend/apps/files/tests/test_views.py +32 -0
- package/templates/s3/backend/apps/files/urls.py +10 -0
- package/templates/s3/backend/apps/files/views.py +29 -0
- package/templates/s3/frontend/src/openapi/utils/openapi.yaml.hbs +253 -0
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"""Example Celery task — replace with real background work."""
|
|
2
|
+
|
|
3
|
+
import logging
|
|
4
|
+
|
|
5
|
+
from celery import shared_task
|
|
6
|
+
|
|
7
|
+
logger = logging.getLogger(__name__)
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
@shared_task
|
|
11
|
+
def ping() -> str:
|
|
12
|
+
"""Trivial round-trip task, useful to verify the worker is alive."""
|
|
13
|
+
logger.info("ping task executed")
|
|
14
|
+
return "pong"
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"""Celery application for {{projectName}}.
|
|
2
|
+
|
|
3
|
+
Configuration is read from Django settings under the ``CELERY_`` namespace
|
|
4
|
+
(see ``config/settings/base.py``); tasks are auto-discovered from every
|
|
5
|
+
installed app's ``tasks*.py`` modules.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
import os
|
|
9
|
+
|
|
10
|
+
from celery import Celery
|
|
11
|
+
|
|
12
|
+
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings.local")
|
|
13
|
+
|
|
14
|
+
app = Celery("config")
|
|
15
|
+
app.config_from_object("django.conf:settings", namespace="CELERY")
|
|
16
|
+
app.autodiscover_tasks()
|
|
17
|
+
{{#if withCeleryBeat}}
|
|
18
|
+
|
|
19
|
+
# Periodic tasks — executed by the `celery_beat` compose service.
|
|
20
|
+
app.conf.beat_schedule = {
|
|
21
|
+
"heartbeat-every-minute": {
|
|
22
|
+
"task": "apps.core.tasks_scheduled.heartbeat",
|
|
23
|
+
"schedule": 60.0,
|
|
24
|
+
},
|
|
25
|
+
}
|
|
26
|
+
{{/if}}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"""Periodic tasks driven by Celery Beat.
|
|
2
|
+
|
|
3
|
+
The schedule lives in ``config/celery.py`` (``app.conf.beat_schedule``); the
|
|
4
|
+
`celery_beat` compose service dispatches these to the worker.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
import logging
|
|
8
|
+
|
|
9
|
+
from celery import shared_task
|
|
10
|
+
|
|
11
|
+
logger = logging.getLogger(__name__)
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
@shared_task
|
|
15
|
+
def heartbeat() -> str:
|
|
16
|
+
"""Log a liveness heartbeat — replace with real scheduled work."""
|
|
17
|
+
logger.info("beat heartbeat")
|
|
18
|
+
return "alive"
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { defineCommand } from '@cubocicloide/dude'
|
|
2
|
+
import { spawnSync } from 'node:child_process'
|
|
3
|
+
|
|
4
|
+
function exec(cmd: string, args: string[], cwd: string): void {
|
|
5
|
+
const result = spawnSync(cmd, args, { cwd, stdio: 'inherit' })
|
|
6
|
+
if (result.status !== 0) process.exit(result.status ?? 1)
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
async function waitForBackend(url: string, retries = 30, intervalMs = 2000): Promise<void> {
|
|
10
|
+
for (let i = 0; i < retries; i++) {
|
|
11
|
+
try {
|
|
12
|
+
const res = await fetch(url)
|
|
13
|
+
if (res.ok) return
|
|
14
|
+
} catch {
|
|
15
|
+
// not ready yet
|
|
16
|
+
}
|
|
17
|
+
await new Promise((resolve) => setTimeout(resolve, intervalMs))
|
|
18
|
+
}
|
|
19
|
+
process.stderr.write(
|
|
20
|
+
`error: backend did not become healthy after ${(retries * intervalMs) / 1000}s\n`,
|
|
21
|
+
)
|
|
22
|
+
process.exit(1)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const SEED_SCRIPT = `
|
|
26
|
+
from django.contrib.auth import get_user_model
|
|
27
|
+
|
|
28
|
+
User = get_user_model()
|
|
29
|
+
|
|
30
|
+
users = [
|
|
31
|
+
{"username": "admin", "email": "admin@example.com"},
|
|
32
|
+
{"username": "alice", "email": "alice@example.com"},
|
|
33
|
+
{"username": "bob", "email": "bob@example.com"},
|
|
34
|
+
]
|
|
35
|
+
|
|
36
|
+
added = 0
|
|
37
|
+
for u in users:
|
|
38
|
+
_, created = User.objects.get_or_create(username=u["username"], defaults={"email": u["email"]})
|
|
39
|
+
added += int(created)
|
|
40
|
+
print(f"Seeded {added} user(s).")
|
|
41
|
+
`
|
|
42
|
+
|
|
43
|
+
export default defineCommand({
|
|
44
|
+
description: 'Drop the database, re-apply all migrations, and seed demo data.',
|
|
45
|
+
async run({ projectRoot }) {
|
|
46
|
+
process.stdout.write('Dropping all containers and volumes...\n')
|
|
47
|
+
exec('docker', ['compose', 'down', '--volumes'], projectRoot)
|
|
48
|
+
|
|
49
|
+
process.stdout.write('Starting services...\n')
|
|
50
|
+
exec('docker', ['compose', 'up', '--detach'], projectRoot)
|
|
51
|
+
|
|
52
|
+
process.stdout.write('Waiting for backend to be ready...\n')
|
|
53
|
+
await waitForBackend('http://localhost:8000/api/health/')
|
|
54
|
+
|
|
55
|
+
// start.sh already migrates on boot; run it again explicitly so the
|
|
56
|
+
// command fails loudly if a migration is broken.
|
|
57
|
+
process.stdout.write('Running migrations...\n')
|
|
58
|
+
exec(
|
|
59
|
+
'docker',
|
|
60
|
+
[
|
|
61
|
+
'compose',
|
|
62
|
+
'exec',
|
|
63
|
+
'backend',
|
|
64
|
+
'uv',
|
|
65
|
+
'run',
|
|
66
|
+
'python',
|
|
67
|
+
'manage.py',
|
|
68
|
+
'migrate',
|
|
69
|
+
'--noinput',
|
|
70
|
+
],
|
|
71
|
+
projectRoot,
|
|
72
|
+
)
|
|
73
|
+
|
|
74
|
+
process.stdout.write('Seeding demo data...\n')
|
|
75
|
+
exec(
|
|
76
|
+
'docker',
|
|
77
|
+
['compose', 'exec', 'backend', 'uv', 'run', 'python', 'manage.py', 'shell', '-c', SEED_SCRIPT],
|
|
78
|
+
projectRoot,
|
|
79
|
+
)
|
|
80
|
+
|
|
81
|
+
process.stdout.write('Reset complete.\n')
|
|
82
|
+
},
|
|
83
|
+
})
|
|
File without changes
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
from django.contrib import admin
|
|
2
|
+
|
|
3
|
+
from apps.files.models import FileUpload
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
@admin.register(FileUpload)
|
|
7
|
+
class FileUploadAdmin(admin.ModelAdmin):
|
|
8
|
+
list_display = ("id", "original_name", "content_type", "size", "created_at")
|
|
9
|
+
readonly_fields = ("created_at",)
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
from django.db import migrations, models
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class Migration(migrations.Migration):
|
|
5
|
+
initial = True
|
|
6
|
+
|
|
7
|
+
dependencies = []
|
|
8
|
+
|
|
9
|
+
operations = [
|
|
10
|
+
migrations.CreateModel(
|
|
11
|
+
name="FileUpload",
|
|
12
|
+
fields=[
|
|
13
|
+
(
|
|
14
|
+
"id",
|
|
15
|
+
models.BigAutoField(
|
|
16
|
+
auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
|
|
17
|
+
),
|
|
18
|
+
),
|
|
19
|
+
("file", models.FileField(upload_to="uploads/%Y/%m/")),
|
|
20
|
+
("original_name", models.CharField(blank=True, default="", max_length=255)),
|
|
21
|
+
("content_type", models.CharField(blank=True, default="", max_length=127)),
|
|
22
|
+
("size", models.PositiveBigIntegerField(default=0)),
|
|
23
|
+
("created_at", models.DateTimeField(auto_now_add=True)),
|
|
24
|
+
],
|
|
25
|
+
options={
|
|
26
|
+
"ordering": ("-created_at",),
|
|
27
|
+
},
|
|
28
|
+
),
|
|
29
|
+
]
|
|
File without changes
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
from django.db import models
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class FileUpload(models.Model):
|
|
5
|
+
"""A file stored on the object-storage backend (S3 / MinIO locally).
|
|
6
|
+
|
|
7
|
+
The binary lives in the bucket; this row keeps the metadata and the
|
|
8
|
+
storage key. Downloads go through presigned URLs (``file.url``).
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
file = models.FileField(upload_to="uploads/%Y/%m/")
|
|
12
|
+
original_name = models.CharField(max_length=255, blank=True, default="")
|
|
13
|
+
content_type = models.CharField(max_length=127, blank=True, default="")
|
|
14
|
+
size = models.PositiveBigIntegerField(default=0)
|
|
15
|
+
created_at = models.DateTimeField(auto_now_add=True)
|
|
16
|
+
|
|
17
|
+
class Meta:
|
|
18
|
+
ordering = ("-created_at",)
|
|
19
|
+
|
|
20
|
+
def __str__(self) -> str:
|
|
21
|
+
return self.original_name or self.file.name
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
from rest_framework import serializers
|
|
2
|
+
|
|
3
|
+
from apps.files.models import FileUpload
|
|
4
|
+
from apps.files.services import create_file_upload
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class FileUploadSerializer(serializers.ModelSerializer):
|
|
8
|
+
"""Representation of a stored file.
|
|
9
|
+
|
|
10
|
+
``file`` is write-only (the upload); clients read the presigned ``url``
|
|
11
|
+
instead. Fields are always listed explicitly (lint rule BE002).
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
file = serializers.FileField(write_only=True)
|
|
15
|
+
url = serializers.SerializerMethodField()
|
|
16
|
+
|
|
17
|
+
class Meta:
|
|
18
|
+
model = FileUpload
|
|
19
|
+
fields = ("id", "file", "url", "original_name", "content_type", "size", "created_at")
|
|
20
|
+
read_only_fields = ("id", "original_name", "content_type", "size", "created_at")
|
|
21
|
+
|
|
22
|
+
def get_url(self, obj: FileUpload) -> str:
|
|
23
|
+
# Presigned URL when the S3 backend is active (AWS_QUERYSTRING_AUTH).
|
|
24
|
+
return obj.file.url
|
|
25
|
+
|
|
26
|
+
def create(self, validated_data: dict) -> FileUpload:
|
|
27
|
+
return create_file_upload(uploaded=validated_data["file"])
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"""Write-side operations for the files app.
|
|
2
|
+
|
|
3
|
+
Views never touch the ORM for writes (lint rule BE005) — creation goes
|
|
4
|
+
through this module so upload bookkeeping lives in exactly one place.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from django.core.files.uploadedfile import UploadedFile
|
|
8
|
+
|
|
9
|
+
from apps.files.models import FileUpload
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def create_file_upload(uploaded: UploadedFile) -> FileUpload:
|
|
13
|
+
"""Persist an uploaded file, capturing its original metadata."""
|
|
14
|
+
return FileUpload.objects.create(
|
|
15
|
+
file=uploaded,
|
|
16
|
+
original_name=uploaded.name or "",
|
|
17
|
+
content_type=getattr(uploaded, "content_type", "") or "",
|
|
18
|
+
size=uploaded.size or 0,
|
|
19
|
+
)
|
|
File without changes
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
from apps.files.models import FileUpload
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
def test_str_uses_original_name():
|
|
5
|
+
upload = FileUpload(original_name="report.pdf")
|
|
6
|
+
assert str(upload) == "report.pdf"
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def test_ordering_is_newest_first():
|
|
10
|
+
assert FileUpload._meta.ordering == ("-created_at",)
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import pytest
|
|
2
|
+
from django.core.files.uploadedfile import SimpleUploadedFile
|
|
3
|
+
from rest_framework.test import APIClient
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
@pytest.fixture(autouse=True)
|
|
7
|
+
def in_memory_storage(settings):
|
|
8
|
+
# Tests never talk to MinIO/S3 — swap the default backend for an
|
|
9
|
+
# in-memory one so uploads stay inside the test process.
|
|
10
|
+
settings.STORAGES = {
|
|
11
|
+
**settings.STORAGES,
|
|
12
|
+
"default": {"BACKEND": "django.core.files.storage.InMemoryStorage"},
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@pytest.mark.django_db
|
|
17
|
+
def test_upload_list_retrieve():
|
|
18
|
+
client = APIClient()
|
|
19
|
+
payload = SimpleUploadedFile("hello.txt", b"hi there", content_type="text/plain")
|
|
20
|
+
|
|
21
|
+
created = client.post("/api/files/", {"file": payload}, format="multipart")
|
|
22
|
+
assert created.status_code == 201
|
|
23
|
+
assert created.data["original_name"] == "hello.txt"
|
|
24
|
+
assert created.data["size"] == 8
|
|
25
|
+
|
|
26
|
+
listed = client.get("/api/files/")
|
|
27
|
+
assert listed.status_code == 200
|
|
28
|
+
assert listed.data["count"] == 1
|
|
29
|
+
|
|
30
|
+
detail = client.get(f"/api/files/{created.data['id']}/")
|
|
31
|
+
assert detail.status_code == 200
|
|
32
|
+
assert detail.data["url"]
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
from drf_spectacular.utils import extend_schema
|
|
2
|
+
from rest_framework.mixins import CreateModelMixin, ListModelMixin, RetrieveModelMixin
|
|
3
|
+
from rest_framework.parsers import MultiPartParser
|
|
4
|
+
from rest_framework.permissions import AllowAny
|
|
5
|
+
from rest_framework.viewsets import GenericViewSet
|
|
6
|
+
|
|
7
|
+
from apps.files.models import FileUpload
|
|
8
|
+
from apps.files.serializers import FileUploadSerializer
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
@extend_schema(tags=["files"])
|
|
12
|
+
class FileUploadViewSet(CreateModelMixin, ListModelMixin, RetrieveModelMixin, GenericViewSet):
|
|
13
|
+
"""Upload (multipart), list and retrieve stored files.
|
|
14
|
+
|
|
15
|
+
Writes go through ``apps.files.services`` via the serializer (lint rule
|
|
16
|
+
BE005); downloads use presigned URLs generated by the storage backend.
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
queryset = FileUpload.objects.all()
|
|
20
|
+
serializer_class = FileUploadSerializer
|
|
21
|
+
parser_classes = [MultiPartParser]
|
|
22
|
+
# Demo endpoint: AllowAny so the scaffold works out of the box. Tighten to
|
|
23
|
+
# IsAuthenticated before exposing real data — but keep the declaration
|
|
24
|
+
# explicit: every view must declare permission_classes (lint rule BE003).
|
|
25
|
+
permission_classes = [AllowAny]
|
|
26
|
+
|
|
27
|
+
@extend_schema(operation_id="files_create", description="Upload a file (multipart/form-data).")
|
|
28
|
+
def create(self, request, *args, **kwargs):
|
|
29
|
+
return super().create(request, *args, **kwargs)
|
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
openapi: 3.0.3
|
|
2
|
+
info:
|
|
3
|
+
title: {{projectName}} API
|
|
4
|
+
version: 1.0.0
|
|
5
|
+
paths:
|
|
6
|
+
/api/health/:
|
|
7
|
+
get:
|
|
8
|
+
operationId: health_retrieve
|
|
9
|
+
description: Health-check endpoint.
|
|
10
|
+
tags:
|
|
11
|
+
- health
|
|
12
|
+
security:
|
|
13
|
+
- {}
|
|
14
|
+
responses:
|
|
15
|
+
"200":
|
|
16
|
+
content:
|
|
17
|
+
application/json:
|
|
18
|
+
schema:
|
|
19
|
+
$ref: "#/components/schemas/Health"
|
|
20
|
+
description: ""
|
|
21
|
+
/api/users/:
|
|
22
|
+
get:
|
|
23
|
+
operationId: users_list
|
|
24
|
+
description: List (paginated) and retrieve users.
|
|
25
|
+
parameters:
|
|
26
|
+
- name: page
|
|
27
|
+
required: false
|
|
28
|
+
in: query
|
|
29
|
+
description: A page number within the paginated result set.
|
|
30
|
+
schema:
|
|
31
|
+
type: integer
|
|
32
|
+
tags:
|
|
33
|
+
- users
|
|
34
|
+
security:
|
|
35
|
+
- {}
|
|
36
|
+
responses:
|
|
37
|
+
"200":
|
|
38
|
+
content:
|
|
39
|
+
application/json:
|
|
40
|
+
schema:
|
|
41
|
+
$ref: "#/components/schemas/PaginatedUserList"
|
|
42
|
+
description: ""
|
|
43
|
+
/api/users/{id}/:
|
|
44
|
+
get:
|
|
45
|
+
operationId: users_retrieve
|
|
46
|
+
description: List (paginated) and retrieve users.
|
|
47
|
+
parameters:
|
|
48
|
+
- name: id
|
|
49
|
+
in: path
|
|
50
|
+
required: true
|
|
51
|
+
description: A unique integer value identifying this user.
|
|
52
|
+
schema:
|
|
53
|
+
type: integer
|
|
54
|
+
tags:
|
|
55
|
+
- users
|
|
56
|
+
security:
|
|
57
|
+
- {}
|
|
58
|
+
responses:
|
|
59
|
+
"200":
|
|
60
|
+
content:
|
|
61
|
+
application/json:
|
|
62
|
+
schema:
|
|
63
|
+
$ref: "#/components/schemas/User"
|
|
64
|
+
description: ""
|
|
65
|
+
/api/files/:
|
|
66
|
+
get:
|
|
67
|
+
operationId: files_list
|
|
68
|
+
description: Upload (multipart), list and retrieve stored files.
|
|
69
|
+
parameters:
|
|
70
|
+
- name: page
|
|
71
|
+
required: false
|
|
72
|
+
in: query
|
|
73
|
+
description: A page number within the paginated result set.
|
|
74
|
+
schema:
|
|
75
|
+
type: integer
|
|
76
|
+
tags:
|
|
77
|
+
- files
|
|
78
|
+
security:
|
|
79
|
+
- {}
|
|
80
|
+
responses:
|
|
81
|
+
"200":
|
|
82
|
+
content:
|
|
83
|
+
application/json:
|
|
84
|
+
schema:
|
|
85
|
+
$ref: "#/components/schemas/PaginatedFileUploadList"
|
|
86
|
+
description: ""
|
|
87
|
+
post:
|
|
88
|
+
operationId: files_create
|
|
89
|
+
description: Upload a file (multipart/form-data).
|
|
90
|
+
tags:
|
|
91
|
+
- files
|
|
92
|
+
requestBody:
|
|
93
|
+
content:
|
|
94
|
+
multipart/form-data:
|
|
95
|
+
schema:
|
|
96
|
+
$ref: "#/components/schemas/FileUploadRequest"
|
|
97
|
+
required: true
|
|
98
|
+
security:
|
|
99
|
+
- {}
|
|
100
|
+
responses:
|
|
101
|
+
"201":
|
|
102
|
+
content:
|
|
103
|
+
application/json:
|
|
104
|
+
schema:
|
|
105
|
+
$ref: "#/components/schemas/FileUpload"
|
|
106
|
+
description: ""
|
|
107
|
+
/api/files/{id}/:
|
|
108
|
+
get:
|
|
109
|
+
operationId: files_retrieve
|
|
110
|
+
description: Upload (multipart), list and retrieve stored files.
|
|
111
|
+
parameters:
|
|
112
|
+
- name: id
|
|
113
|
+
in: path
|
|
114
|
+
required: true
|
|
115
|
+
description: A unique integer value identifying this file upload.
|
|
116
|
+
schema:
|
|
117
|
+
type: integer
|
|
118
|
+
tags:
|
|
119
|
+
- files
|
|
120
|
+
security:
|
|
121
|
+
- {}
|
|
122
|
+
responses:
|
|
123
|
+
"200":
|
|
124
|
+
content:
|
|
125
|
+
application/json:
|
|
126
|
+
schema:
|
|
127
|
+
$ref: "#/components/schemas/FileUpload"
|
|
128
|
+
description: ""
|
|
129
|
+
components:
|
|
130
|
+
schemas:
|
|
131
|
+
Health:
|
|
132
|
+
type: object
|
|
133
|
+
description: Response payload of the health-check endpoint.
|
|
134
|
+
properties:
|
|
135
|
+
status:
|
|
136
|
+
type: string
|
|
137
|
+
required:
|
|
138
|
+
- status
|
|
139
|
+
PaginatedUserList:
|
|
140
|
+
type: object
|
|
141
|
+
properties:
|
|
142
|
+
count:
|
|
143
|
+
type: integer
|
|
144
|
+
example: 123
|
|
145
|
+
next:
|
|
146
|
+
type: string
|
|
147
|
+
nullable: true
|
|
148
|
+
format: uri
|
|
149
|
+
example: http://api.example.org/accounts/?page=4
|
|
150
|
+
previous:
|
|
151
|
+
type: string
|
|
152
|
+
nullable: true
|
|
153
|
+
format: uri
|
|
154
|
+
example: http://api.example.org/accounts/?page=2
|
|
155
|
+
results:
|
|
156
|
+
type: array
|
|
157
|
+
items:
|
|
158
|
+
$ref: "#/components/schemas/User"
|
|
159
|
+
required:
|
|
160
|
+
- count
|
|
161
|
+
- results
|
|
162
|
+
User:
|
|
163
|
+
type: object
|
|
164
|
+
description: Public representation of a user.
|
|
165
|
+
properties:
|
|
166
|
+
id:
|
|
167
|
+
type: integer
|
|
168
|
+
readOnly: true
|
|
169
|
+
username:
|
|
170
|
+
type: string
|
|
171
|
+
description: Required. 150 characters or fewer. Letters, digits and @/./+/-/_
|
|
172
|
+
only.
|
|
173
|
+
pattern: ^[\w.@+-]+$
|
|
174
|
+
maxLength: 150
|
|
175
|
+
email:
|
|
176
|
+
type: string
|
|
177
|
+
format: email
|
|
178
|
+
title: Email address
|
|
179
|
+
maxLength: 254
|
|
180
|
+
first_name:
|
|
181
|
+
type: string
|
|
182
|
+
maxLength: 150
|
|
183
|
+
last_name:
|
|
184
|
+
type: string
|
|
185
|
+
maxLength: 150
|
|
186
|
+
date_joined:
|
|
187
|
+
type: string
|
|
188
|
+
format: date-time
|
|
189
|
+
readOnly: true
|
|
190
|
+
required:
|
|
191
|
+
- date_joined
|
|
192
|
+
- id
|
|
193
|
+
- username
|
|
194
|
+
PaginatedFileUploadList:
|
|
195
|
+
type: object
|
|
196
|
+
properties:
|
|
197
|
+
count:
|
|
198
|
+
type: integer
|
|
199
|
+
example: 123
|
|
200
|
+
next:
|
|
201
|
+
type: string
|
|
202
|
+
nullable: true
|
|
203
|
+
format: uri
|
|
204
|
+
example: http://api.example.org/accounts/?page=4
|
|
205
|
+
previous:
|
|
206
|
+
type: string
|
|
207
|
+
nullable: true
|
|
208
|
+
format: uri
|
|
209
|
+
example: http://api.example.org/accounts/?page=2
|
|
210
|
+
results:
|
|
211
|
+
type: array
|
|
212
|
+
items:
|
|
213
|
+
$ref: "#/components/schemas/FileUpload"
|
|
214
|
+
required:
|
|
215
|
+
- count
|
|
216
|
+
- results
|
|
217
|
+
FileUpload:
|
|
218
|
+
type: object
|
|
219
|
+
description: Representation of a stored file.
|
|
220
|
+
properties:
|
|
221
|
+
id:
|
|
222
|
+
type: integer
|
|
223
|
+
readOnly: true
|
|
224
|
+
url:
|
|
225
|
+
type: string
|
|
226
|
+
readOnly: true
|
|
227
|
+
description: Presigned download URL generated by the storage backend.
|
|
228
|
+
original_name:
|
|
229
|
+
type: string
|
|
230
|
+
readOnly: true
|
|
231
|
+
content_type:
|
|
232
|
+
type: string
|
|
233
|
+
readOnly: true
|
|
234
|
+
size:
|
|
235
|
+
type: integer
|
|
236
|
+
readOnly: true
|
|
237
|
+
created_at:
|
|
238
|
+
type: string
|
|
239
|
+
format: date-time
|
|
240
|
+
readOnly: true
|
|
241
|
+
required:
|
|
242
|
+
- created_at
|
|
243
|
+
- id
|
|
244
|
+
- url
|
|
245
|
+
FileUploadRequest:
|
|
246
|
+
type: object
|
|
247
|
+
description: Multipart upload payload.
|
|
248
|
+
properties:
|
|
249
|
+
file:
|
|
250
|
+
type: string
|
|
251
|
+
format: binary
|
|
252
|
+
required:
|
|
253
|
+
- file
|