flaskforge-cli 0.1.0__tar.gz → 0.1.1__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.
- flaskforge_cli-0.1.1/PKG-INFO +143 -0
- flaskforge_cli-0.1.1/README.md +128 -0
- {flaskforge_cli-0.1.0 → flaskforge_cli-0.1.1}/pyproject.toml +1 -1
- {flaskforge_cli-0.1.0 → flaskforge_cli-0.1.1}/src/flaskforge/__init__.py +1 -1
- {flaskforge_cli-0.1.0 → flaskforge_cli-0.1.1}/src/flaskforge/generators.py +2 -0
- {flaskforge_cli-0.1.0 → flaskforge_cli-0.1.1}/src/flaskforge/registry.py +20 -5
- flaskforge_cli-0.1.1/src/flaskforge/templates/app/admin.py.tpl +16 -0
- flaskforge_cli-0.1.1/src/flaskforge/templates/ext/admin/accounts_admin.py.tpl +14 -0
- flaskforge_cli-0.1.1/src/flaskforge/templates/ext/admin/admin_views.py.tpl +31 -0
- flaskforge_cli-0.1.1/src/flaskforge/templates/ext/admin/test_admin.py.tpl +30 -0
- flaskforge_cli-0.1.1/src/flaskforge/templates/project/README.md.tpl +54 -0
- {flaskforge_cli-0.1.0 → flaskforge_cli-0.1.1}/src/flaskforge/templates/project/core/__init__.py.tpl +2 -1
- flaskforge_cli-0.1.1/src/flaskforge/templates/project/requirements-dev.txt.tpl +3 -0
- flaskforge_cli-0.1.1/src/flaskforge_cli.egg-info/PKG-INFO +143 -0
- {flaskforge_cli-0.1.0 → flaskforge_cli-0.1.1}/src/flaskforge_cli.egg-info/SOURCES.txt +4 -0
- {flaskforge_cli-0.1.0 → flaskforge_cli-0.1.1}/tests/test_flaskforge.py +27 -0
- flaskforge_cli-0.1.0/PKG-INFO +0 -77
- flaskforge_cli-0.1.0/README.md +0 -62
- flaskforge_cli-0.1.0/src/flaskforge/templates/project/README.md.tpl +0 -40
- flaskforge_cli-0.1.0/src/flaskforge/templates/project/requirements-dev.txt.tpl +0 -3
- flaskforge_cli-0.1.0/src/flaskforge_cli.egg-info/PKG-INFO +0 -77
- {flaskforge_cli-0.1.0 → flaskforge_cli-0.1.1}/LICENSE +0 -0
- {flaskforge_cli-0.1.0 → flaskforge_cli-0.1.1}/setup.cfg +0 -0
- {flaskforge_cli-0.1.0 → flaskforge_cli-0.1.1}/src/flaskforge/__main__.py +0 -0
- {flaskforge_cli-0.1.0 → flaskforge_cli-0.1.1}/src/flaskforge/cli.py +0 -0
- {flaskforge_cli-0.1.0 → flaskforge_cli-0.1.1}/src/flaskforge/commands.py +0 -0
- {flaskforge_cli-0.1.0 → flaskforge_cli-0.1.1}/src/flaskforge/management.py +0 -0
- {flaskforge_cli-0.1.0 → flaskforge_cli-0.1.1}/src/flaskforge/scaffold.py +0 -0
- {flaskforge_cli-0.1.0 → flaskforge_cli-0.1.1}/src/flaskforge/templates/app/__init__.py.tpl +0 -0
- {flaskforge_cli-0.1.0 → flaskforge_cli-0.1.1}/src/flaskforge/templates/app/forms.py.tpl +0 -0
- {flaskforge_cli-0.1.0 → flaskforge_cli-0.1.1}/src/flaskforge/templates/app/index.html.tpl +0 -0
- {flaskforge_cli-0.1.0 → flaskforge_cli-0.1.1}/src/flaskforge/templates/app/models.py.tpl +0 -0
- {flaskforge_cli-0.1.0 → flaskforge_cli-0.1.1}/src/flaskforge/templates/app/schemas.py.tpl +0 -0
- {flaskforge_cli-0.1.0 → flaskforge_cli-0.1.1}/src/flaskforge/templates/app/test_app.py.tpl +0 -0
- {flaskforge_cli-0.1.0 → flaskforge_cli-0.1.1}/src/flaskforge/templates/app/views.py.tpl +0 -0
- {flaskforge_cli-0.1.0 → flaskforge_cli-0.1.1}/src/flaskforge/templates/ext/login/__init__.py.tpl +0 -0
- {flaskforge_cli-0.1.0 → flaskforge_cli-0.1.1}/src/flaskforge/templates/ext/login/_csrf.html.tpl +0 -0
- {flaskforge_cli-0.1.0 → flaskforge_cli-0.1.1}/src/flaskforge/templates/ext/login/commands.py.tpl +0 -0
- {flaskforge_cli-0.1.0 → flaskforge_cli-0.1.1}/src/flaskforge/templates/ext/login/login.html.tpl +0 -0
- {flaskforge_cli-0.1.0 → flaskforge_cli-0.1.1}/src/flaskforge/templates/ext/login/models.py.tpl +0 -0
- {flaskforge_cli-0.1.0 → flaskforge_cli-0.1.1}/src/flaskforge/templates/ext/login/profile.html.tpl +0 -0
- {flaskforge_cli-0.1.0 → flaskforge_cli-0.1.1}/src/flaskforge/templates/ext/login/register.html.tpl +0 -0
- {flaskforge_cli-0.1.0 → flaskforge_cli-0.1.1}/src/flaskforge/templates/ext/login/test_accounts.py.tpl +0 -0
- {flaskforge_cli-0.1.0 → flaskforge_cli-0.1.1}/src/flaskforge/templates/ext/login/views.py.tpl +0 -0
- {flaskforge_cli-0.1.0 → flaskforge_cli-0.1.1}/src/flaskforge/templates/ext/sqlalchemy/mixins.py.tpl +0 -0
- {flaskforge_cli-0.1.0 → flaskforge_cli-0.1.1}/src/flaskforge/templates/project/Dockerfile.tpl +0 -0
- {flaskforge_cli-0.1.0 → flaskforge_cli-0.1.1}/src/flaskforge/templates/project/apps/__init__.py.tpl +0 -0
- {flaskforge_cli-0.1.0 → flaskforge_cli-0.1.1}/src/flaskforge/templates/project/apps/main/__init__.py.tpl +0 -0
- {flaskforge_cli-0.1.0 → flaskforge_cli-0.1.1}/src/flaskforge/templates/project/apps/main/templates/main/index.html.tpl +0 -0
- {flaskforge_cli-0.1.0 → flaskforge_cli-0.1.1}/src/flaskforge/templates/project/apps/main/views.py.tpl +0 -0
- {flaskforge_cli-0.1.0 → flaskforge_cli-0.1.1}/src/flaskforge/templates/project/config/__init__.py.tpl +0 -0
- {flaskforge_cli-0.1.0 → flaskforge_cli-0.1.1}/src/flaskforge/templates/project/config/settings.py.tpl +0 -0
- {flaskforge_cli-0.1.0 → flaskforge_cli-0.1.1}/src/flaskforge/templates/project/core/errors.py.tpl +0 -0
- {flaskforge_cli-0.1.0 → flaskforge_cli-0.1.1}/src/flaskforge/templates/project/core/extensions.py.tpl +0 -0
- {flaskforge_cli-0.1.0 → flaskforge_cli-0.1.1}/src/flaskforge/templates/project/dot_env.example.tpl +0 -0
- {flaskforge_cli-0.1.0 → flaskforge_cli-0.1.1}/src/flaskforge/templates/project/dot_env.tpl +0 -0
- {flaskforge_cli-0.1.0 → flaskforge_cli-0.1.1}/src/flaskforge/templates/project/dot_gitignore.tpl +0 -0
- {flaskforge_cli-0.1.0 → flaskforge_cli-0.1.1}/src/flaskforge/templates/project/manage.py.tpl +0 -0
- {flaskforge_cli-0.1.0 → flaskforge_cli-0.1.1}/src/flaskforge/templates/project/pytest.ini.tpl +0 -0
- {flaskforge_cli-0.1.0 → flaskforge_cli-0.1.1}/src/flaskforge/templates/project/requirements.txt.tpl +0 -0
- {flaskforge_cli-0.1.0 → flaskforge_cli-0.1.1}/src/flaskforge/templates/project/static/css/style.css.tpl +0 -0
- {flaskforge_cli-0.1.0 → flaskforge_cli-0.1.1}/src/flaskforge/templates/project/templates/base.html.tpl +0 -0
- {flaskforge_cli-0.1.0 → flaskforge_cli-0.1.1}/src/flaskforge/templates/project/templates/errors/error.html.tpl +0 -0
- {flaskforge_cli-0.1.0 → flaskforge_cli-0.1.1}/src/flaskforge/templates/project/tests/__init__.py.tpl +0 -0
- {flaskforge_cli-0.1.0 → flaskforge_cli-0.1.1}/src/flaskforge/templates/project/tests/conftest.py.tpl +0 -0
- {flaskforge_cli-0.1.0 → flaskforge_cli-0.1.1}/src/flaskforge/templates/project/tests/test_main.py.tpl +0 -0
- {flaskforge_cli-0.1.0 → flaskforge_cli-0.1.1}/src/flaskforge/templates/project/wsgi.py.tpl +0 -0
- {flaskforge_cli-0.1.0 → flaskforge_cli-0.1.1}/src/flaskforge_cli.egg-info/dependency_links.txt +0 -0
- {flaskforge_cli-0.1.0 → flaskforge_cli-0.1.1}/src/flaskforge_cli.egg-info/entry_points.txt +0 -0
- {flaskforge_cli-0.1.0 → flaskforge_cli-0.1.1}/src/flaskforge_cli.egg-info/requires.txt +0 -0
- {flaskforge_cli-0.1.0 → flaskforge_cli-0.1.1}/src/flaskforge_cli.egg-info/top_level.txt +0 -0
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: flaskforge-cli
|
|
3
|
+
Version: 0.1.1
|
|
4
|
+
Summary: Django-like CLI that scaffolds and extends large Flask projects
|
|
5
|
+
Requires-Python: >=3.9
|
|
6
|
+
Description-Content-Type: text/markdown
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
Requires-Dist: click>=8.1
|
|
9
|
+
Requires-Dist: Jinja2>=3.1
|
|
10
|
+
Requires-Dist: Flask>=3.0
|
|
11
|
+
Requires-Dist: python-dotenv>=1.0
|
|
12
|
+
Provides-Extra: dev
|
|
13
|
+
Requires-Dist: pytest; extra == "dev"
|
|
14
|
+
Dynamic: license-file
|
|
15
|
+
|
|
16
|
+
# flaskforge
|
|
17
|
+
|
|
18
|
+
A Django-like CLI for Flask. It scaffolds a large, well-structured Flask project
|
|
19
|
+
(app factory, settings per environment, Django-style `INSTALLED_APPS`, tests, Docker)
|
|
20
|
+
and wires up Flask extensions with a single command.
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
pipx install flaskforge-cli # or: pip install flaskforge-cli
|
|
24
|
+
flaskforge startproject shop --preset web
|
|
25
|
+
cd shop
|
|
26
|
+
python -m venv .venv && source .venv/bin/activate
|
|
27
|
+
pip install -r requirements-dev.txt
|
|
28
|
+
python manage.py makemigrations -m "initial" && python manage.py migrate
|
|
29
|
+
python manage.py createsuperuser
|
|
30
|
+
python manage.py runserver # http://127.0.0.1:8000
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
The PyPI package is called **`flaskforge-cli`**; the command and the Python package are `flaskforge`.
|
|
34
|
+
Requires Python 3.9+.
|
|
35
|
+
|
|
36
|
+
## Commands
|
|
37
|
+
|
|
38
|
+
Global (`flaskforge ...`):
|
|
39
|
+
|
|
40
|
+
| Command | What it does |
|
|
41
|
+
| --- | --- |
|
|
42
|
+
| `startproject NAME [DIR] [--preset P] [-e EXT,...] [--install]` | Create a project. Presets: `minimal`, `web`, `api`, `full` |
|
|
43
|
+
| `startapp NAME [--api]` | Create an app under `apps/` and register it in `INSTALLED_APPS` |
|
|
44
|
+
| `add EXT... [--no-install] [--force]` | `pip install` extensions and wire them into the project |
|
|
45
|
+
| `extensions` | List supported extensions and which are installed |
|
|
46
|
+
|
|
47
|
+
`startapp`, `add` and `extensions` work from any subdirectory of a project.
|
|
48
|
+
|
|
49
|
+
Project-level (`python manage.py ...`) - the commands above plus:
|
|
50
|
+
|
|
51
|
+
| Command | What it does |
|
|
52
|
+
| --- | --- |
|
|
53
|
+
| `runserver [-h HOST] [-p PORT]` | Dev server (port 8000, autoreload and debugger in development) |
|
|
54
|
+
| `makemigrations [-m MSG]` | Create migrations (runs `init` the first time) |
|
|
55
|
+
| `migrate` / `rollback` | Apply / revert migrations |
|
|
56
|
+
| `createsuperuser` | Create an admin user (when `login` is installed) |
|
|
57
|
+
| `check` | Load the app and report blueprints and routes |
|
|
58
|
+
| `shell`, `routes`, `run` | Built-in Flask commands |
|
|
59
|
+
|
|
60
|
+
## Generated layout
|
|
61
|
+
|
|
62
|
+
```
|
|
63
|
+
config/settings.py Base / Development / Testing / Production configs, INSTALLED_APPS
|
|
64
|
+
core/__init__.py create_app() factory; loads every app in INSTALLED_APPS
|
|
65
|
+
core/extensions.py extension instances (db, login_manager, ...), filled in by `add`
|
|
66
|
+
apps/<name>/ views.py (bp), models.py, templates/<name>/, tests in tests/
|
|
67
|
+
templates/ static/ shared templates (base.html) and assets
|
|
68
|
+
tests/ pytest, with app/client fixtures
|
|
69
|
+
wsgi.py Dockerfile .env
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
Each app in `INSTALLED_APPS` is auto-loaded:
|
|
73
|
+
|
|
74
|
+
| File | Purpose |
|
|
75
|
+
| --- | --- |
|
|
76
|
+
| `models.py` | Imported so the ORM and migrations see your models |
|
|
77
|
+
| `events.py` | Imported (e.g. Flask-SocketIO handlers) |
|
|
78
|
+
| `admin.py` | Imported (Flask-Admin model views, like Django's `admin.py`) |
|
|
79
|
+
| `views.py` | Must define `bp` (or a `blueprints` list) |
|
|
80
|
+
| `commands.py` | `commands = [...]` are added to the CLI |
|
|
81
|
+
|
|
82
|
+
Blueprints mounted under `/api` are exempt from CSRF (token-authenticated JSON APIs).
|
|
83
|
+
|
|
84
|
+
## Supported extensions
|
|
85
|
+
|
|
86
|
+
| Key | Package | Notes |
|
|
87
|
+
| --- | --- | --- |
|
|
88
|
+
| `sqlalchemy` | Flask-SQLAlchemy | `db`, `TimestampMixin` in `core/mixins.py` |
|
|
89
|
+
| `migrate` | Flask-Migrate | Requires `sqlalchemy` |
|
|
90
|
+
| `login` | Flask-Login | Scaffolds `apps/accounts` (User, register, login, logout, `createsuperuser`) |
|
|
91
|
+
| `admin` | Flask-Admin | Panel at `/admin`, **restricted to `is_admin` users**; requires `login` |
|
|
92
|
+
| `wtf` | Flask-WTF | Forms and global CSRF protection |
|
|
93
|
+
| `mail` | Flask-Mail | |
|
|
94
|
+
| `cors` | Flask-CORS | Applied to `/api/*` |
|
|
95
|
+
| `jwt` | Flask-JWT-Extended | |
|
|
96
|
+
| `cache` | Flask-Caching | |
|
|
97
|
+
| `limiter` | Flask-Limiter | |
|
|
98
|
+
| `babel` | Flask-Babel | |
|
|
99
|
+
| `marshmallow` | Flask-Marshmallow | Requires `sqlalchemy` |
|
|
100
|
+
| `socketio` | Flask-SocketIO | `runserver` uses `socketio.run()` automatically |
|
|
101
|
+
| `debugtoolbar` | Flask-DebugToolbar | Dev dependency, active only when `DEBUG=True` |
|
|
102
|
+
| `talisman` | Flask-Talisman | HTTPS forced in production |
|
|
103
|
+
| `compress` | Flask-Compress | |
|
|
104
|
+
|
|
105
|
+
Dependencies are resolved automatically (`add admin` also adds `login` and `sqlalchemy`).
|
|
106
|
+
Add a new extension by appending one `Extension(...)` entry to `src/flaskforge/registry.py`.
|
|
107
|
+
|
|
108
|
+
### Admin panel
|
|
109
|
+
|
|
110
|
+
```bash
|
|
111
|
+
python manage.py add admin
|
|
112
|
+
python manage.py createsuperuser
|
|
113
|
+
python manage.py runserver
|
|
114
|
+
# sign in at /accounts/login, then open /admin/
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
Register models of your own apps in `apps/<name>/admin.py` (generated automatically by
|
|
118
|
+
`startapp` when `admin` is installed). Always use `SecureModelView` from `core/admin_views.py`:
|
|
119
|
+
a bare Flask-Admin view has no access control. Anonymous visitors are redirected to the login
|
|
120
|
+
page and signed-in non-admins get `403`.
|
|
121
|
+
|
|
122
|
+
If Flask-Babel is installed in your environment, also run `add babel`: Flask-Admin uses it
|
|
123
|
+
automatically and it must be initialised.
|
|
124
|
+
|
|
125
|
+
## How it works
|
|
126
|
+
|
|
127
|
+
`add` inserts code above the `# forge:...` marker comments in `core/extensions.py` and
|
|
128
|
+
`config/settings.py` - please keep those comments. Operations are idempotent (running the same
|
|
129
|
+
command twice changes nothing) and existing files are never overwritten without `--force`.
|
|
130
|
+
Project metadata lives in `.flaskforge.json`.
|
|
131
|
+
|
|
132
|
+
## Development
|
|
133
|
+
|
|
134
|
+
```bash
|
|
135
|
+
git clone https://github.com/dvrone/flaskforge.git && cd flaskforge
|
|
136
|
+
pip install -e ".[dev]"
|
|
137
|
+
pytest
|
|
138
|
+
python -m build && twine upload dist/* # release (bump the version first)
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
## License
|
|
142
|
+
|
|
143
|
+
See [LICENSE](LICENSE).
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
# flaskforge
|
|
2
|
+
|
|
3
|
+
A Django-like CLI for Flask. It scaffolds a large, well-structured Flask project
|
|
4
|
+
(app factory, settings per environment, Django-style `INSTALLED_APPS`, tests, Docker)
|
|
5
|
+
and wires up Flask extensions with a single command.
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pipx install flaskforge-cli # or: pip install flaskforge-cli
|
|
9
|
+
flaskforge startproject shop --preset web
|
|
10
|
+
cd shop
|
|
11
|
+
python -m venv .venv && source .venv/bin/activate
|
|
12
|
+
pip install -r requirements-dev.txt
|
|
13
|
+
python manage.py makemigrations -m "initial" && python manage.py migrate
|
|
14
|
+
python manage.py createsuperuser
|
|
15
|
+
python manage.py runserver # http://127.0.0.1:8000
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
The PyPI package is called **`flaskforge-cli`**; the command and the Python package are `flaskforge`.
|
|
19
|
+
Requires Python 3.9+.
|
|
20
|
+
|
|
21
|
+
## Commands
|
|
22
|
+
|
|
23
|
+
Global (`flaskforge ...`):
|
|
24
|
+
|
|
25
|
+
| Command | What it does |
|
|
26
|
+
| --- | --- |
|
|
27
|
+
| `startproject NAME [DIR] [--preset P] [-e EXT,...] [--install]` | Create a project. Presets: `minimal`, `web`, `api`, `full` |
|
|
28
|
+
| `startapp NAME [--api]` | Create an app under `apps/` and register it in `INSTALLED_APPS` |
|
|
29
|
+
| `add EXT... [--no-install] [--force]` | `pip install` extensions and wire them into the project |
|
|
30
|
+
| `extensions` | List supported extensions and which are installed |
|
|
31
|
+
|
|
32
|
+
`startapp`, `add` and `extensions` work from any subdirectory of a project.
|
|
33
|
+
|
|
34
|
+
Project-level (`python manage.py ...`) - the commands above plus:
|
|
35
|
+
|
|
36
|
+
| Command | What it does |
|
|
37
|
+
| --- | --- |
|
|
38
|
+
| `runserver [-h HOST] [-p PORT]` | Dev server (port 8000, autoreload and debugger in development) |
|
|
39
|
+
| `makemigrations [-m MSG]` | Create migrations (runs `init` the first time) |
|
|
40
|
+
| `migrate` / `rollback` | Apply / revert migrations |
|
|
41
|
+
| `createsuperuser` | Create an admin user (when `login` is installed) |
|
|
42
|
+
| `check` | Load the app and report blueprints and routes |
|
|
43
|
+
| `shell`, `routes`, `run` | Built-in Flask commands |
|
|
44
|
+
|
|
45
|
+
## Generated layout
|
|
46
|
+
|
|
47
|
+
```
|
|
48
|
+
config/settings.py Base / Development / Testing / Production configs, INSTALLED_APPS
|
|
49
|
+
core/__init__.py create_app() factory; loads every app in INSTALLED_APPS
|
|
50
|
+
core/extensions.py extension instances (db, login_manager, ...), filled in by `add`
|
|
51
|
+
apps/<name>/ views.py (bp), models.py, templates/<name>/, tests in tests/
|
|
52
|
+
templates/ static/ shared templates (base.html) and assets
|
|
53
|
+
tests/ pytest, with app/client fixtures
|
|
54
|
+
wsgi.py Dockerfile .env
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Each app in `INSTALLED_APPS` is auto-loaded:
|
|
58
|
+
|
|
59
|
+
| File | Purpose |
|
|
60
|
+
| --- | --- |
|
|
61
|
+
| `models.py` | Imported so the ORM and migrations see your models |
|
|
62
|
+
| `events.py` | Imported (e.g. Flask-SocketIO handlers) |
|
|
63
|
+
| `admin.py` | Imported (Flask-Admin model views, like Django's `admin.py`) |
|
|
64
|
+
| `views.py` | Must define `bp` (or a `blueprints` list) |
|
|
65
|
+
| `commands.py` | `commands = [...]` are added to the CLI |
|
|
66
|
+
|
|
67
|
+
Blueprints mounted under `/api` are exempt from CSRF (token-authenticated JSON APIs).
|
|
68
|
+
|
|
69
|
+
## Supported extensions
|
|
70
|
+
|
|
71
|
+
| Key | Package | Notes |
|
|
72
|
+
| --- | --- | --- |
|
|
73
|
+
| `sqlalchemy` | Flask-SQLAlchemy | `db`, `TimestampMixin` in `core/mixins.py` |
|
|
74
|
+
| `migrate` | Flask-Migrate | Requires `sqlalchemy` |
|
|
75
|
+
| `login` | Flask-Login | Scaffolds `apps/accounts` (User, register, login, logout, `createsuperuser`) |
|
|
76
|
+
| `admin` | Flask-Admin | Panel at `/admin`, **restricted to `is_admin` users**; requires `login` |
|
|
77
|
+
| `wtf` | Flask-WTF | Forms and global CSRF protection |
|
|
78
|
+
| `mail` | Flask-Mail | |
|
|
79
|
+
| `cors` | Flask-CORS | Applied to `/api/*` |
|
|
80
|
+
| `jwt` | Flask-JWT-Extended | |
|
|
81
|
+
| `cache` | Flask-Caching | |
|
|
82
|
+
| `limiter` | Flask-Limiter | |
|
|
83
|
+
| `babel` | Flask-Babel | |
|
|
84
|
+
| `marshmallow` | Flask-Marshmallow | Requires `sqlalchemy` |
|
|
85
|
+
| `socketio` | Flask-SocketIO | `runserver` uses `socketio.run()` automatically |
|
|
86
|
+
| `debugtoolbar` | Flask-DebugToolbar | Dev dependency, active only when `DEBUG=True` |
|
|
87
|
+
| `talisman` | Flask-Talisman | HTTPS forced in production |
|
|
88
|
+
| `compress` | Flask-Compress | |
|
|
89
|
+
|
|
90
|
+
Dependencies are resolved automatically (`add admin` also adds `login` and `sqlalchemy`).
|
|
91
|
+
Add a new extension by appending one `Extension(...)` entry to `src/flaskforge/registry.py`.
|
|
92
|
+
|
|
93
|
+
### Admin panel
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
python manage.py add admin
|
|
97
|
+
python manage.py createsuperuser
|
|
98
|
+
python manage.py runserver
|
|
99
|
+
# sign in at /accounts/login, then open /admin/
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
Register models of your own apps in `apps/<name>/admin.py` (generated automatically by
|
|
103
|
+
`startapp` when `admin` is installed). Always use `SecureModelView` from `core/admin_views.py`:
|
|
104
|
+
a bare Flask-Admin view has no access control. Anonymous visitors are redirected to the login
|
|
105
|
+
page and signed-in non-admins get `403`.
|
|
106
|
+
|
|
107
|
+
If Flask-Babel is installed in your environment, also run `add babel`: Flask-Admin uses it
|
|
108
|
+
automatically and it must be initialised.
|
|
109
|
+
|
|
110
|
+
## How it works
|
|
111
|
+
|
|
112
|
+
`add` inserts code above the `# forge:...` marker comments in `core/extensions.py` and
|
|
113
|
+
`config/settings.py` - please keep those comments. Operations are idempotent (running the same
|
|
114
|
+
command twice changes nothing) and existing files are never overwritten without `--force`.
|
|
115
|
+
Project metadata lives in `.flaskforge.json`.
|
|
116
|
+
|
|
117
|
+
## Development
|
|
118
|
+
|
|
119
|
+
```bash
|
|
120
|
+
git clone https://github.com/dvrone/flaskforge.git && cd flaskforge
|
|
121
|
+
pip install -e ".[dev]"
|
|
122
|
+
pytest
|
|
123
|
+
python -m build && twine upload dist/* # release (bump the version first)
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
## License
|
|
127
|
+
|
|
128
|
+
See [LICENSE](LICENSE).
|
|
@@ -157,6 +157,8 @@ def create_app(project: Project, name: str, api: bool = False, force: bool = Fal
|
|
|
157
157
|
files.append(("app/forms.py.tpl", f"apps/{name}/forms.py"))
|
|
158
158
|
elif "marshmallow" in exts:
|
|
159
159
|
files.append(("app/schemas.py.tpl", f"apps/{name}/schemas.py"))
|
|
160
|
+
if "admin" in exts and "sqlalchemy" in exts:
|
|
161
|
+
files.append(("app/admin.py.tpl", f"apps/{name}/admin.py"))
|
|
160
162
|
_render_files(project, files, ctx, force)
|
|
161
163
|
register_app(project, f"apps.{name}")
|
|
162
164
|
project.save()
|
|
@@ -222,12 +222,27 @@ _ALL = [
|
|
|
222
222
|
Extension(
|
|
223
223
|
key="admin",
|
|
224
224
|
title="Flask-Admin",
|
|
225
|
-
description="
|
|
226
|
-
packages=("Flask-Admin",),
|
|
227
|
-
imports=(
|
|
228
|
-
|
|
225
|
+
description="Admin panel at /admin, restricted to is_admin users (needs login)",
|
|
226
|
+
packages=("Flask-Admin>=2.0",),
|
|
227
|
+
imports=(
|
|
228
|
+
"from flask_admin import Admin",
|
|
229
|
+
"",
|
|
230
|
+
"from .admin_views import SecureAdminIndexView",
|
|
231
|
+
),
|
|
232
|
+
instances=('admin = Admin(name="Admin", index_view=SecureAdminIndexView())',),
|
|
229
233
|
init=("admin.init_app(app)",),
|
|
230
|
-
|
|
234
|
+
requires=("sqlalchemy", "login"),
|
|
235
|
+
files=(
|
|
236
|
+
("ext/admin/admin_views.py.tpl", "core/admin_views.py"),
|
|
237
|
+
("ext/admin/accounts_admin.py.tpl", "apps/accounts/admin.py"),
|
|
238
|
+
("ext/admin/test_admin.py.tpl", "tests/test_admin.py"),
|
|
239
|
+
),
|
|
240
|
+
notes=(
|
|
241
|
+
"Create an admin user with `manage.py createsuperuser`, sign in at /accounts/login, "
|
|
242
|
+
"open /admin/. Register models in apps/<name>/admin.py with SecureModelView. "
|
|
243
|
+
"If Flask-Babel is installed in this environment, also run `add babel` "
|
|
244
|
+
"(Flask-Admin uses it automatically and it must be initialised)."
|
|
245
|
+
),
|
|
231
246
|
),
|
|
232
247
|
Extension(
|
|
233
248
|
key="debugtoolbar",
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
from core.admin_views import SecureModelView
|
|
2
|
+
from core.extensions import admin, db
|
|
3
|
+
|
|
4
|
+
from .models import [[ class_name ]]
|
|
5
|
+
|
|
6
|
+
# The `admin_` endpoint prefix keeps Flask-Admin's blueprint name from clashing
|
|
7
|
+
# with this app's own blueprint ("[[ app_name ]]").
|
|
8
|
+
admin.add_view(
|
|
9
|
+
SecureModelView(
|
|
10
|
+
[[ class_name ]],
|
|
11
|
+
db,
|
|
12
|
+
name="[[ class_name ]]",
|
|
13
|
+
endpoint="admin_[[ app_name ]]",
|
|
14
|
+
url="[[ app_name ]]",
|
|
15
|
+
)
|
|
16
|
+
)
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
from core.admin_views import SecureModelView
|
|
2
|
+
from core.extensions import admin, db
|
|
3
|
+
|
|
4
|
+
from .models import User
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class UserAdmin(SecureModelView):
|
|
8
|
+
column_list = ["id", "email", "is_admin", "created_at"]
|
|
9
|
+
column_searchable_list = ["email"]
|
|
10
|
+
form_columns = ["email", "is_admin"]
|
|
11
|
+
can_create = False # passwords are set via /accounts/register or `manage.py createsuperuser`
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
admin.add_view(UserAdmin(User, db, name="Users", endpoint="admin_users", url="users"))
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"""Access-controlled Flask-Admin views.
|
|
2
|
+
|
|
3
|
+
Only authenticated users with `is_admin = True` may open the admin panel:
|
|
4
|
+
* anonymous visitors are redirected to the login page,
|
|
5
|
+
* signed-in non-admins get 403.
|
|
6
|
+
|
|
7
|
+
Always use these classes instead of the bare Flask-Admin ones:
|
|
8
|
+
admin.add_view(SecureModelView(Model, db))
|
|
9
|
+
"""
|
|
10
|
+
from flask import abort, redirect, request, url_for
|
|
11
|
+
from flask_admin import AdminIndexView
|
|
12
|
+
from flask_admin.contrib.sqla import ModelView
|
|
13
|
+
from flask_login import current_user
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class AdminAccessMixin:
|
|
17
|
+
def is_accessible(self):
|
|
18
|
+
return current_user.is_authenticated and bool(getattr(current_user, "is_admin", False))
|
|
19
|
+
|
|
20
|
+
def inaccessible_callback(self, name, **kwargs):
|
|
21
|
+
if current_user.is_authenticated:
|
|
22
|
+
abort(403)
|
|
23
|
+
return redirect(url_for("accounts.login", next=request.path))
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class SecureAdminIndexView(AdminAccessMixin, AdminIndexView):
|
|
27
|
+
pass
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
class SecureModelView(AdminAccessMixin, ModelView):
|
|
31
|
+
pass
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
from apps.accounts.models import User
|
|
2
|
+
from core.extensions import db
|
|
3
|
+
|
|
4
|
+
PASSWORD = "s3cret-pass"
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def _login_as(client, email, is_admin):
|
|
8
|
+
user = User(email=email, is_admin=is_admin)
|
|
9
|
+
user.set_password(PASSWORD)
|
|
10
|
+
db.session.add(user)
|
|
11
|
+
db.session.commit()
|
|
12
|
+
client.post("/accounts/login", data={"email": email, "password": PASSWORD})
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def test_admin_redirects_anonymous_to_login(client):
|
|
16
|
+
response = client.get("/admin/")
|
|
17
|
+
assert response.status_code == 302
|
|
18
|
+
assert "/accounts/login" in response.headers["Location"]
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def test_admin_forbidden_for_regular_user(client):
|
|
22
|
+
_login_as(client, "user@example.com", is_admin=False)
|
|
23
|
+
assert client.get("/admin/").status_code == 403
|
|
24
|
+
assert client.get("/admin/users/").status_code == 403
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def test_admin_open_for_admin_user(client):
|
|
28
|
+
_login_as(client, "boss@example.com", is_admin=True)
|
|
29
|
+
assert client.get("/admin/").status_code == 200
|
|
30
|
+
assert client.get("/admin/users/").status_code == 200
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# [[ project ]]
|
|
2
|
+
|
|
3
|
+
A Flask project generated with [flaskforge](https://pypi.org/project/flaskforge-cli/).
|
|
4
|
+
|
|
5
|
+
## Getting started
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
python -m venv .venv && source .venv/bin/activate
|
|
9
|
+
pip install -r requirements-dev.txt
|
|
10
|
+
# .env was generated with a random SECRET_KEY (never commit it)
|
|
11
|
+
python manage.py runserver # http://127.0.0.1:8000
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
If the project uses a database, create the tables first:
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
python manage.py makemigrations -m "initial"
|
|
18
|
+
python manage.py migrate
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Layout
|
|
22
|
+
|
|
23
|
+
```
|
|
24
|
+
config/settings.py settings (Base / Development / Testing / Production), INSTALLED_APPS
|
|
25
|
+
core/__init__.py create_app() - the application factory
|
|
26
|
+
core/extensions.py Flask extension instances (db, login_manager, ...)
|
|
27
|
+
apps/<name>/ one package per app: views.py (bp), models.py, templates/<name>/
|
|
28
|
+
templates/ shared templates (base.html)
|
|
29
|
+
tests/ pytest
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Commands
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
python manage.py startapp blog # new app in apps/blog
|
|
36
|
+
python manage.py startapp posts --api # JSON API app at /api/posts
|
|
37
|
+
python manage.py add sqlalchemy migrate # install and wire up extensions
|
|
38
|
+
python manage.py extensions # list available extensions
|
|
39
|
+
python manage.py makemigrations -m "msg" # create a migration
|
|
40
|
+
python manage.py migrate # apply migrations
|
|
41
|
+
python manage.py routes # list URL rules
|
|
42
|
+
python manage.py shell
|
|
43
|
+
pytest
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Do not remove the `# forge:...` comments in `config/settings.py` and `core/extensions.py`:
|
|
47
|
+
flaskforge uses them to know where to insert code.
|
|
48
|
+
|
|
49
|
+
## Deployment
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
APP_ENV=production SECRET_KEY=... gunicorn wsgi:app
|
|
53
|
+
# or: docker build -t [[ project_slug ]] . && docker run -e SECRET_KEY=... -p 8000:8000 [[ project_slug ]]
|
|
54
|
+
```
|
{flaskforge_cli-0.1.0 → flaskforge_cli-0.1.1}/src/flaskforge/templates/project/core/__init__.py.tpl
RENAMED
|
@@ -31,12 +31,13 @@ def register_apps(app):
|
|
|
31
31
|
Per app (all optional except that something must expose a blueprint):
|
|
32
32
|
models.py imported so the ORM / migrations see the models
|
|
33
33
|
events.py imported (e.g. Flask-SocketIO handlers)
|
|
34
|
+
admin.py imported (Flask-Admin model views, like Django's admin.py)
|
|
34
35
|
views.py must define `bp` (or a `blueprints` list)
|
|
35
36
|
commands.py `commands = [click commands]` added to the CLI
|
|
36
37
|
"""
|
|
37
38
|
csrf = getattr(extensions, "csrf", None)
|
|
38
39
|
for dotted in app.config["INSTALLED_APPS"]:
|
|
39
|
-
for sub in ("models", "events"):
|
|
40
|
+
for sub in ("models", "events", "admin"):
|
|
40
41
|
if _has(f"{dotted}.{sub}"):
|
|
41
42
|
importlib.import_module(f"{dotted}.{sub}")
|
|
42
43
|
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: flaskforge-cli
|
|
3
|
+
Version: 0.1.1
|
|
4
|
+
Summary: Django-like CLI that scaffolds and extends large Flask projects
|
|
5
|
+
Requires-Python: >=3.9
|
|
6
|
+
Description-Content-Type: text/markdown
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
Requires-Dist: click>=8.1
|
|
9
|
+
Requires-Dist: Jinja2>=3.1
|
|
10
|
+
Requires-Dist: Flask>=3.0
|
|
11
|
+
Requires-Dist: python-dotenv>=1.0
|
|
12
|
+
Provides-Extra: dev
|
|
13
|
+
Requires-Dist: pytest; extra == "dev"
|
|
14
|
+
Dynamic: license-file
|
|
15
|
+
|
|
16
|
+
# flaskforge
|
|
17
|
+
|
|
18
|
+
A Django-like CLI for Flask. It scaffolds a large, well-structured Flask project
|
|
19
|
+
(app factory, settings per environment, Django-style `INSTALLED_APPS`, tests, Docker)
|
|
20
|
+
and wires up Flask extensions with a single command.
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
pipx install flaskforge-cli # or: pip install flaskforge-cli
|
|
24
|
+
flaskforge startproject shop --preset web
|
|
25
|
+
cd shop
|
|
26
|
+
python -m venv .venv && source .venv/bin/activate
|
|
27
|
+
pip install -r requirements-dev.txt
|
|
28
|
+
python manage.py makemigrations -m "initial" && python manage.py migrate
|
|
29
|
+
python manage.py createsuperuser
|
|
30
|
+
python manage.py runserver # http://127.0.0.1:8000
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
The PyPI package is called **`flaskforge-cli`**; the command and the Python package are `flaskforge`.
|
|
34
|
+
Requires Python 3.9+.
|
|
35
|
+
|
|
36
|
+
## Commands
|
|
37
|
+
|
|
38
|
+
Global (`flaskforge ...`):
|
|
39
|
+
|
|
40
|
+
| Command | What it does |
|
|
41
|
+
| --- | --- |
|
|
42
|
+
| `startproject NAME [DIR] [--preset P] [-e EXT,...] [--install]` | Create a project. Presets: `minimal`, `web`, `api`, `full` |
|
|
43
|
+
| `startapp NAME [--api]` | Create an app under `apps/` and register it in `INSTALLED_APPS` |
|
|
44
|
+
| `add EXT... [--no-install] [--force]` | `pip install` extensions and wire them into the project |
|
|
45
|
+
| `extensions` | List supported extensions and which are installed |
|
|
46
|
+
|
|
47
|
+
`startapp`, `add` and `extensions` work from any subdirectory of a project.
|
|
48
|
+
|
|
49
|
+
Project-level (`python manage.py ...`) - the commands above plus:
|
|
50
|
+
|
|
51
|
+
| Command | What it does |
|
|
52
|
+
| --- | --- |
|
|
53
|
+
| `runserver [-h HOST] [-p PORT]` | Dev server (port 8000, autoreload and debugger in development) |
|
|
54
|
+
| `makemigrations [-m MSG]` | Create migrations (runs `init` the first time) |
|
|
55
|
+
| `migrate` / `rollback` | Apply / revert migrations |
|
|
56
|
+
| `createsuperuser` | Create an admin user (when `login` is installed) |
|
|
57
|
+
| `check` | Load the app and report blueprints and routes |
|
|
58
|
+
| `shell`, `routes`, `run` | Built-in Flask commands |
|
|
59
|
+
|
|
60
|
+
## Generated layout
|
|
61
|
+
|
|
62
|
+
```
|
|
63
|
+
config/settings.py Base / Development / Testing / Production configs, INSTALLED_APPS
|
|
64
|
+
core/__init__.py create_app() factory; loads every app in INSTALLED_APPS
|
|
65
|
+
core/extensions.py extension instances (db, login_manager, ...), filled in by `add`
|
|
66
|
+
apps/<name>/ views.py (bp), models.py, templates/<name>/, tests in tests/
|
|
67
|
+
templates/ static/ shared templates (base.html) and assets
|
|
68
|
+
tests/ pytest, with app/client fixtures
|
|
69
|
+
wsgi.py Dockerfile .env
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
Each app in `INSTALLED_APPS` is auto-loaded:
|
|
73
|
+
|
|
74
|
+
| File | Purpose |
|
|
75
|
+
| --- | --- |
|
|
76
|
+
| `models.py` | Imported so the ORM and migrations see your models |
|
|
77
|
+
| `events.py` | Imported (e.g. Flask-SocketIO handlers) |
|
|
78
|
+
| `admin.py` | Imported (Flask-Admin model views, like Django's `admin.py`) |
|
|
79
|
+
| `views.py` | Must define `bp` (or a `blueprints` list) |
|
|
80
|
+
| `commands.py` | `commands = [...]` are added to the CLI |
|
|
81
|
+
|
|
82
|
+
Blueprints mounted under `/api` are exempt from CSRF (token-authenticated JSON APIs).
|
|
83
|
+
|
|
84
|
+
## Supported extensions
|
|
85
|
+
|
|
86
|
+
| Key | Package | Notes |
|
|
87
|
+
| --- | --- | --- |
|
|
88
|
+
| `sqlalchemy` | Flask-SQLAlchemy | `db`, `TimestampMixin` in `core/mixins.py` |
|
|
89
|
+
| `migrate` | Flask-Migrate | Requires `sqlalchemy` |
|
|
90
|
+
| `login` | Flask-Login | Scaffolds `apps/accounts` (User, register, login, logout, `createsuperuser`) |
|
|
91
|
+
| `admin` | Flask-Admin | Panel at `/admin`, **restricted to `is_admin` users**; requires `login` |
|
|
92
|
+
| `wtf` | Flask-WTF | Forms and global CSRF protection |
|
|
93
|
+
| `mail` | Flask-Mail | |
|
|
94
|
+
| `cors` | Flask-CORS | Applied to `/api/*` |
|
|
95
|
+
| `jwt` | Flask-JWT-Extended | |
|
|
96
|
+
| `cache` | Flask-Caching | |
|
|
97
|
+
| `limiter` | Flask-Limiter | |
|
|
98
|
+
| `babel` | Flask-Babel | |
|
|
99
|
+
| `marshmallow` | Flask-Marshmallow | Requires `sqlalchemy` |
|
|
100
|
+
| `socketio` | Flask-SocketIO | `runserver` uses `socketio.run()` automatically |
|
|
101
|
+
| `debugtoolbar` | Flask-DebugToolbar | Dev dependency, active only when `DEBUG=True` |
|
|
102
|
+
| `talisman` | Flask-Talisman | HTTPS forced in production |
|
|
103
|
+
| `compress` | Flask-Compress | |
|
|
104
|
+
|
|
105
|
+
Dependencies are resolved automatically (`add admin` also adds `login` and `sqlalchemy`).
|
|
106
|
+
Add a new extension by appending one `Extension(...)` entry to `src/flaskforge/registry.py`.
|
|
107
|
+
|
|
108
|
+
### Admin panel
|
|
109
|
+
|
|
110
|
+
```bash
|
|
111
|
+
python manage.py add admin
|
|
112
|
+
python manage.py createsuperuser
|
|
113
|
+
python manage.py runserver
|
|
114
|
+
# sign in at /accounts/login, then open /admin/
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
Register models of your own apps in `apps/<name>/admin.py` (generated automatically by
|
|
118
|
+
`startapp` when `admin` is installed). Always use `SecureModelView` from `core/admin_views.py`:
|
|
119
|
+
a bare Flask-Admin view has no access control. Anonymous visitors are redirected to the login
|
|
120
|
+
page and signed-in non-admins get `403`.
|
|
121
|
+
|
|
122
|
+
If Flask-Babel is installed in your environment, also run `add babel`: Flask-Admin uses it
|
|
123
|
+
automatically and it must be initialised.
|
|
124
|
+
|
|
125
|
+
## How it works
|
|
126
|
+
|
|
127
|
+
`add` inserts code above the `# forge:...` marker comments in `core/extensions.py` and
|
|
128
|
+
`config/settings.py` - please keep those comments. Operations are idempotent (running the same
|
|
129
|
+
command twice changes nothing) and existing files are never overwritten without `--force`.
|
|
130
|
+
Project metadata lives in `.flaskforge.json`.
|
|
131
|
+
|
|
132
|
+
## Development
|
|
133
|
+
|
|
134
|
+
```bash
|
|
135
|
+
git clone https://github.com/dvrone/flaskforge.git && cd flaskforge
|
|
136
|
+
pip install -e ".[dev]"
|
|
137
|
+
pytest
|
|
138
|
+
python -m build && twine upload dist/* # release (bump the version first)
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
## License
|
|
142
|
+
|
|
143
|
+
See [LICENSE](LICENSE).
|
|
@@ -10,12 +10,16 @@ src/flaskforge/management.py
|
|
|
10
10
|
src/flaskforge/registry.py
|
|
11
11
|
src/flaskforge/scaffold.py
|
|
12
12
|
src/flaskforge/templates/app/__init__.py.tpl
|
|
13
|
+
src/flaskforge/templates/app/admin.py.tpl
|
|
13
14
|
src/flaskforge/templates/app/forms.py.tpl
|
|
14
15
|
src/flaskforge/templates/app/index.html.tpl
|
|
15
16
|
src/flaskforge/templates/app/models.py.tpl
|
|
16
17
|
src/flaskforge/templates/app/schemas.py.tpl
|
|
17
18
|
src/flaskforge/templates/app/test_app.py.tpl
|
|
18
19
|
src/flaskforge/templates/app/views.py.tpl
|
|
20
|
+
src/flaskforge/templates/ext/admin/accounts_admin.py.tpl
|
|
21
|
+
src/flaskforge/templates/ext/admin/admin_views.py.tpl
|
|
22
|
+
src/flaskforge/templates/ext/admin/test_admin.py.tpl
|
|
19
23
|
src/flaskforge/templates/ext/login/__init__.py.tpl
|
|
20
24
|
src/flaskforge/templates/ext/login/_csrf.html.tpl
|
|
21
25
|
src/flaskforge/templates/ext/login/commands.py.tpl
|
|
@@ -126,3 +126,30 @@ def test_missing_marker_gives_actionable_error(runner, tmp_path, monkeypatch):
|
|
|
126
126
|
path.write_text(path.read_text().replace("# forge:instances", ""))
|
|
127
127
|
result = runner.invoke(cli, ["add", "--no-install", "cache"])
|
|
128
128
|
assert result.exit_code != 0 and "forge:instances" in result.output
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
def test_add_admin_pulls_login_and_secures_views(runner, tmp_path, monkeypatch):
|
|
132
|
+
root = make_project(runner, tmp_path)
|
|
133
|
+
monkeypatch.chdir(root)
|
|
134
|
+
invoke(runner, "add", "--no-install", "admin")
|
|
135
|
+
manifest = json.loads((root / ".flaskforge.json").read_text())
|
|
136
|
+
assert manifest["extensions"] == ["sqlalchemy", "login", "admin"]
|
|
137
|
+
ext_py = (root / "core/extensions.py").read_text()
|
|
138
|
+
assert "SecureAdminIndexView()" in ext_py
|
|
139
|
+
views = (root / "core/admin_views.py").read_text()
|
|
140
|
+
assert "is_admin" in views and "inaccessible_callback" in views
|
|
141
|
+
assert (root / "apps/accounts/admin.py").exists()
|
|
142
|
+
assert "Flask-Admin>=2.0" in (root / "requirements.txt").read_text()
|
|
143
|
+
|
|
144
|
+
# new apps get an admin.py with a non-clashing endpoint
|
|
145
|
+
invoke(runner, "startapp", "notes")
|
|
146
|
+
admin_py = (root / "apps/notes/admin.py").read_text()
|
|
147
|
+
assert 'endpoint="admin_notes"' in admin_py
|
|
148
|
+
assert compileall.compile_dir(str(root), quiet=1)
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
def test_generated_readme_and_requirements(runner, tmp_path):
|
|
152
|
+
root = make_project(runner, tmp_path)
|
|
153
|
+
assert "flaskforge-cli" in (root / "requirements-dev.txt").read_text()
|
|
154
|
+
readme = (root / "README.md").read_text()
|
|
155
|
+
assert "Getting started" in readme and "cp .env.example" not in readme
|
flaskforge_cli-0.1.0/PKG-INFO
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: flaskforge-cli
|
|
3
|
-
Version: 0.1.0
|
|
4
|
-
Summary: Django-like CLI that scaffolds and extends large Flask projects
|
|
5
|
-
Requires-Python: >=3.9
|
|
6
|
-
Description-Content-Type: text/markdown
|
|
7
|
-
License-File: LICENSE
|
|
8
|
-
Requires-Dist: click>=8.1
|
|
9
|
-
Requires-Dist: Jinja2>=3.1
|
|
10
|
-
Requires-Dist: Flask>=3.0
|
|
11
|
-
Requires-Dist: python-dotenv>=1.0
|
|
12
|
-
Provides-Extra: dev
|
|
13
|
-
Requires-Dist: pytest; extra == "dev"
|
|
14
|
-
Dynamic: license-file
|
|
15
|
-
|
|
16
|
-
# flaskforge
|
|
17
|
-
|
|
18
|
-
Flask uchun Django'ga o'xshash CLI: katta loyiha strukturasini avtomatik yaratadi va
|
|
19
|
-
Flask extensionlarini bitta buyruq bilan ulaydi.
|
|
20
|
-
|
|
21
|
-
## O'rnatish
|
|
22
|
-
|
|
23
|
-
```bash
|
|
24
|
-
pip install -e .
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
## Ishlatish
|
|
28
|
-
|
|
29
|
-
```bash
|
|
30
|
-
flaskforge startproject shop --preset web # minimal | web | api | full
|
|
31
|
-
cd shop
|
|
32
|
-
python -m venv .venv && source .venv/bin/activate
|
|
33
|
-
pip install -r requirements-dev.txt && pip install -e /path/to/flaskforge
|
|
34
|
-
|
|
35
|
-
python manage.py startapp blog # apps/blog (HTML blueprint)
|
|
36
|
-
python manage.py startapp posts --api # apps/posts (JSON API, /api/posts)
|
|
37
|
-
python manage.py add mail cache limiter # extension qo'shish (pip install + kod ulash)
|
|
38
|
-
python manage.py makemigrations -m "initial" # Flask-Migrate (init avtomatik)
|
|
39
|
-
python manage.py migrate
|
|
40
|
-
python manage.py createsuperuser # `add login` dan keyin
|
|
41
|
-
python manage.py runserver # http://127.0.0.1:8000
|
|
42
|
-
python manage.py extensions # ro'yxat
|
|
43
|
-
```
|
|
44
|
-
|
|
45
|
-
`flaskforge startapp|add|extensions` loyihaning istalgan papkasidan ham ishlaydi.
|
|
46
|
-
|
|
47
|
-
## Yaratiladigan struktura
|
|
48
|
-
|
|
49
|
-
```
|
|
50
|
-
config/settings.py Base/Development/Testing/Production, INSTALLED_APPS
|
|
51
|
-
core/__init__.py create_app() - app factory, INSTALLED_APPS ni avtomatik yuklaydi
|
|
52
|
-
core/extensions.py db, login_manager, ... (marker'lar orqali avtomatik to'ldiriladi)
|
|
53
|
-
apps/<name>/ views.py (bp), models.py, [forms.py, schemas.py, events.py, commands.py]
|
|
54
|
-
templates/ static/ tests/ wsgi.py Dockerfile .env
|
|
55
|
-
```
|
|
56
|
-
|
|
57
|
-
Har bir app'dan avtomatik yuklanadi: `models.py`, `events.py`, `views.py` (`bp`),
|
|
58
|
-
`commands.py` (`commands = [...]` -> `manage.py` buyruqlari).
|
|
59
|
-
|
|
60
|
-
## Qo'llab-quvvatlanadigan extensionlar
|
|
61
|
-
|
|
62
|
-
sqlalchemy, migrate, login (apps/accounts bilan), wtf (CSRF), mail, cors, jwt, cache,
|
|
63
|
-
limiter, babel, marshmallow, socketio, admin, debugtoolbar, talisman, compress.
|
|
64
|
-
|
|
65
|
-
Yangisini qo'shish: `src/flaskforge/registry.py` ichiga bitta `Extension(...)` yozuvi.
|
|
66
|
-
|
|
67
|
-
## Qanday ishlaydi
|
|
68
|
-
|
|
69
|
-
`add` buyrug'i `core/extensions.py` va `config/settings.py` ichidagi `# forge:...`
|
|
70
|
-
izohlari (marker) tepasiga kod qo'shadi. Amal idempotent: ikki marta ishlatsangiz
|
|
71
|
-
hech narsa takrorlanmaydi. Mavjud fayllar `--force`siz ustidan yozilmaydi.
|
|
72
|
-
|
|
73
|
-
## Test
|
|
74
|
-
|
|
75
|
-
```bash
|
|
76
|
-
pip install -e ".[dev]" && pytest
|
|
77
|
-
```
|
flaskforge_cli-0.1.0/README.md
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
# flaskforge
|
|
2
|
-
|
|
3
|
-
Flask uchun Django'ga o'xshash CLI: katta loyiha strukturasini avtomatik yaratadi va
|
|
4
|
-
Flask extensionlarini bitta buyruq bilan ulaydi.
|
|
5
|
-
|
|
6
|
-
## O'rnatish
|
|
7
|
-
|
|
8
|
-
```bash
|
|
9
|
-
pip install -e .
|
|
10
|
-
```
|
|
11
|
-
|
|
12
|
-
## Ishlatish
|
|
13
|
-
|
|
14
|
-
```bash
|
|
15
|
-
flaskforge startproject shop --preset web # minimal | web | api | full
|
|
16
|
-
cd shop
|
|
17
|
-
python -m venv .venv && source .venv/bin/activate
|
|
18
|
-
pip install -r requirements-dev.txt && pip install -e /path/to/flaskforge
|
|
19
|
-
|
|
20
|
-
python manage.py startapp blog # apps/blog (HTML blueprint)
|
|
21
|
-
python manage.py startapp posts --api # apps/posts (JSON API, /api/posts)
|
|
22
|
-
python manage.py add mail cache limiter # extension qo'shish (pip install + kod ulash)
|
|
23
|
-
python manage.py makemigrations -m "initial" # Flask-Migrate (init avtomatik)
|
|
24
|
-
python manage.py migrate
|
|
25
|
-
python manage.py createsuperuser # `add login` dan keyin
|
|
26
|
-
python manage.py runserver # http://127.0.0.1:8000
|
|
27
|
-
python manage.py extensions # ro'yxat
|
|
28
|
-
```
|
|
29
|
-
|
|
30
|
-
`flaskforge startapp|add|extensions` loyihaning istalgan papkasidan ham ishlaydi.
|
|
31
|
-
|
|
32
|
-
## Yaratiladigan struktura
|
|
33
|
-
|
|
34
|
-
```
|
|
35
|
-
config/settings.py Base/Development/Testing/Production, INSTALLED_APPS
|
|
36
|
-
core/__init__.py create_app() - app factory, INSTALLED_APPS ni avtomatik yuklaydi
|
|
37
|
-
core/extensions.py db, login_manager, ... (marker'lar orqali avtomatik to'ldiriladi)
|
|
38
|
-
apps/<name>/ views.py (bp), models.py, [forms.py, schemas.py, events.py, commands.py]
|
|
39
|
-
templates/ static/ tests/ wsgi.py Dockerfile .env
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
Har bir app'dan avtomatik yuklanadi: `models.py`, `events.py`, `views.py` (`bp`),
|
|
43
|
-
`commands.py` (`commands = [...]` -> `manage.py` buyruqlari).
|
|
44
|
-
|
|
45
|
-
## Qo'llab-quvvatlanadigan extensionlar
|
|
46
|
-
|
|
47
|
-
sqlalchemy, migrate, login (apps/accounts bilan), wtf (CSRF), mail, cors, jwt, cache,
|
|
48
|
-
limiter, babel, marshmallow, socketio, admin, debugtoolbar, talisman, compress.
|
|
49
|
-
|
|
50
|
-
Yangisini qo'shish: `src/flaskforge/registry.py` ichiga bitta `Extension(...)` yozuvi.
|
|
51
|
-
|
|
52
|
-
## Qanday ishlaydi
|
|
53
|
-
|
|
54
|
-
`add` buyrug'i `core/extensions.py` va `config/settings.py` ichidagi `# forge:...`
|
|
55
|
-
izohlari (marker) tepasiga kod qo'shadi. Amal idempotent: ikki marta ishlatsangiz
|
|
56
|
-
hech narsa takrorlanmaydi. Mavjud fayllar `--force`siz ustidan yozilmaydi.
|
|
57
|
-
|
|
58
|
-
## Test
|
|
59
|
-
|
|
60
|
-
```bash
|
|
61
|
-
pip install -e ".[dev]" && pytest
|
|
62
|
-
```
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
# [[ project ]]
|
|
2
|
-
|
|
3
|
-
Flask loyihasi (`flaskforge` bilan yaratilgan).
|
|
4
|
-
|
|
5
|
-
## Ishga tushirish
|
|
6
|
-
|
|
7
|
-
```bash
|
|
8
|
-
python -m venv .venv && source .venv/bin/activate
|
|
9
|
-
pip install -r requirements-dev.txt
|
|
10
|
-
pip install flaskforge # manage.py uchun
|
|
11
|
-
python manage.py runserver
|
|
12
|
-
```
|
|
13
|
-
|
|
14
|
-
## Tuzilma
|
|
15
|
-
|
|
16
|
-
```
|
|
17
|
-
config/settings.py # sozlamalar (Base/Development/Testing/Production), INSTALLED_APPS
|
|
18
|
-
core/__init__.py # create_app() - application factory
|
|
19
|
-
core/extensions.py # barcha Flask extension obyektlari (db, login_manager, ...)
|
|
20
|
-
apps/<name>/ # har bir app: views.py (bp), models.py, templates/<name>/
|
|
21
|
-
templates/ # umumiy shablonlar (base.html)
|
|
22
|
-
tests/ # pytest
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
## Buyruqlar
|
|
26
|
-
|
|
27
|
-
```bash
|
|
28
|
-
python manage.py startapp blog # yangi app (apps/blog)
|
|
29
|
-
python manage.py startapp posts --api # JSON API app (/api/posts)
|
|
30
|
-
python manage.py add sqlalchemy migrate # extension qo'shish
|
|
31
|
-
python manage.py extensions # mavjud extensionlar
|
|
32
|
-
python manage.py makemigrations -m "msg" # migratsiya yaratish
|
|
33
|
-
python manage.py migrate # migratsiyani qo'llash
|
|
34
|
-
python manage.py routes # URL'lar ro'yxati
|
|
35
|
-
python manage.py shell
|
|
36
|
-
pytest
|
|
37
|
-
```
|
|
38
|
-
|
|
39
|
-
`config/settings.py` va `core/extensions.py` ichidagi `# forge:...` izohlarini o'chirmang:
|
|
40
|
-
flaskforge kodni aynan shu joylarga qo'shadi.
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: flaskforge-cli
|
|
3
|
-
Version: 0.1.0
|
|
4
|
-
Summary: Django-like CLI that scaffolds and extends large Flask projects
|
|
5
|
-
Requires-Python: >=3.9
|
|
6
|
-
Description-Content-Type: text/markdown
|
|
7
|
-
License-File: LICENSE
|
|
8
|
-
Requires-Dist: click>=8.1
|
|
9
|
-
Requires-Dist: Jinja2>=3.1
|
|
10
|
-
Requires-Dist: Flask>=3.0
|
|
11
|
-
Requires-Dist: python-dotenv>=1.0
|
|
12
|
-
Provides-Extra: dev
|
|
13
|
-
Requires-Dist: pytest; extra == "dev"
|
|
14
|
-
Dynamic: license-file
|
|
15
|
-
|
|
16
|
-
# flaskforge
|
|
17
|
-
|
|
18
|
-
Flask uchun Django'ga o'xshash CLI: katta loyiha strukturasini avtomatik yaratadi va
|
|
19
|
-
Flask extensionlarini bitta buyruq bilan ulaydi.
|
|
20
|
-
|
|
21
|
-
## O'rnatish
|
|
22
|
-
|
|
23
|
-
```bash
|
|
24
|
-
pip install -e .
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
## Ishlatish
|
|
28
|
-
|
|
29
|
-
```bash
|
|
30
|
-
flaskforge startproject shop --preset web # minimal | web | api | full
|
|
31
|
-
cd shop
|
|
32
|
-
python -m venv .venv && source .venv/bin/activate
|
|
33
|
-
pip install -r requirements-dev.txt && pip install -e /path/to/flaskforge
|
|
34
|
-
|
|
35
|
-
python manage.py startapp blog # apps/blog (HTML blueprint)
|
|
36
|
-
python manage.py startapp posts --api # apps/posts (JSON API, /api/posts)
|
|
37
|
-
python manage.py add mail cache limiter # extension qo'shish (pip install + kod ulash)
|
|
38
|
-
python manage.py makemigrations -m "initial" # Flask-Migrate (init avtomatik)
|
|
39
|
-
python manage.py migrate
|
|
40
|
-
python manage.py createsuperuser # `add login` dan keyin
|
|
41
|
-
python manage.py runserver # http://127.0.0.1:8000
|
|
42
|
-
python manage.py extensions # ro'yxat
|
|
43
|
-
```
|
|
44
|
-
|
|
45
|
-
`flaskforge startapp|add|extensions` loyihaning istalgan papkasidan ham ishlaydi.
|
|
46
|
-
|
|
47
|
-
## Yaratiladigan struktura
|
|
48
|
-
|
|
49
|
-
```
|
|
50
|
-
config/settings.py Base/Development/Testing/Production, INSTALLED_APPS
|
|
51
|
-
core/__init__.py create_app() - app factory, INSTALLED_APPS ni avtomatik yuklaydi
|
|
52
|
-
core/extensions.py db, login_manager, ... (marker'lar orqali avtomatik to'ldiriladi)
|
|
53
|
-
apps/<name>/ views.py (bp), models.py, [forms.py, schemas.py, events.py, commands.py]
|
|
54
|
-
templates/ static/ tests/ wsgi.py Dockerfile .env
|
|
55
|
-
```
|
|
56
|
-
|
|
57
|
-
Har bir app'dan avtomatik yuklanadi: `models.py`, `events.py`, `views.py` (`bp`),
|
|
58
|
-
`commands.py` (`commands = [...]` -> `manage.py` buyruqlari).
|
|
59
|
-
|
|
60
|
-
## Qo'llab-quvvatlanadigan extensionlar
|
|
61
|
-
|
|
62
|
-
sqlalchemy, migrate, login (apps/accounts bilan), wtf (CSRF), mail, cors, jwt, cache,
|
|
63
|
-
limiter, babel, marshmallow, socketio, admin, debugtoolbar, talisman, compress.
|
|
64
|
-
|
|
65
|
-
Yangisini qo'shish: `src/flaskforge/registry.py` ichiga bitta `Extension(...)` yozuvi.
|
|
66
|
-
|
|
67
|
-
## Qanday ishlaydi
|
|
68
|
-
|
|
69
|
-
`add` buyrug'i `core/extensions.py` va `config/settings.py` ichidagi `# forge:...`
|
|
70
|
-
izohlari (marker) tepasiga kod qo'shadi. Amal idempotent: ikki marta ishlatsangiz
|
|
71
|
-
hech narsa takrorlanmaydi. Mavjud fayllar `--force`siz ustidan yozilmaydi.
|
|
72
|
-
|
|
73
|
-
## Test
|
|
74
|
-
|
|
75
|
-
```bash
|
|
76
|
-
pip install -e ".[dev]" && pytest
|
|
77
|
-
```
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{flaskforge_cli-0.1.0 → flaskforge_cli-0.1.1}/src/flaskforge/templates/ext/login/__init__.py.tpl
RENAMED
|
File without changes
|
{flaskforge_cli-0.1.0 → flaskforge_cli-0.1.1}/src/flaskforge/templates/ext/login/_csrf.html.tpl
RENAMED
|
File without changes
|
{flaskforge_cli-0.1.0 → flaskforge_cli-0.1.1}/src/flaskforge/templates/ext/login/commands.py.tpl
RENAMED
|
File without changes
|
{flaskforge_cli-0.1.0 → flaskforge_cli-0.1.1}/src/flaskforge/templates/ext/login/login.html.tpl
RENAMED
|
File without changes
|
{flaskforge_cli-0.1.0 → flaskforge_cli-0.1.1}/src/flaskforge/templates/ext/login/models.py.tpl
RENAMED
|
File without changes
|
{flaskforge_cli-0.1.0 → flaskforge_cli-0.1.1}/src/flaskforge/templates/ext/login/profile.html.tpl
RENAMED
|
File without changes
|
{flaskforge_cli-0.1.0 → flaskforge_cli-0.1.1}/src/flaskforge/templates/ext/login/register.html.tpl
RENAMED
|
File without changes
|
|
File without changes
|
{flaskforge_cli-0.1.0 → flaskforge_cli-0.1.1}/src/flaskforge/templates/ext/login/views.py.tpl
RENAMED
|
File without changes
|
{flaskforge_cli-0.1.0 → flaskforge_cli-0.1.1}/src/flaskforge/templates/ext/sqlalchemy/mixins.py.tpl
RENAMED
|
File without changes
|
{flaskforge_cli-0.1.0 → flaskforge_cli-0.1.1}/src/flaskforge/templates/project/Dockerfile.tpl
RENAMED
|
File without changes
|
{flaskforge_cli-0.1.0 → flaskforge_cli-0.1.1}/src/flaskforge/templates/project/apps/__init__.py.tpl
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{flaskforge_cli-0.1.0 → flaskforge_cli-0.1.1}/src/flaskforge/templates/project/core/errors.py.tpl
RENAMED
|
File without changes
|
|
File without changes
|
{flaskforge_cli-0.1.0 → flaskforge_cli-0.1.1}/src/flaskforge/templates/project/dot_env.example.tpl
RENAMED
|
File without changes
|
|
File without changes
|
{flaskforge_cli-0.1.0 → flaskforge_cli-0.1.1}/src/flaskforge/templates/project/dot_gitignore.tpl
RENAMED
|
File without changes
|
{flaskforge_cli-0.1.0 → flaskforge_cli-0.1.1}/src/flaskforge/templates/project/manage.py.tpl
RENAMED
|
File without changes
|
{flaskforge_cli-0.1.0 → flaskforge_cli-0.1.1}/src/flaskforge/templates/project/pytest.ini.tpl
RENAMED
|
File without changes
|
{flaskforge_cli-0.1.0 → flaskforge_cli-0.1.1}/src/flaskforge/templates/project/requirements.txt.tpl
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{flaskforge_cli-0.1.0 → flaskforge_cli-0.1.1}/src/flaskforge/templates/project/tests/__init__.py.tpl
RENAMED
|
File without changes
|
{flaskforge_cli-0.1.0 → flaskforge_cli-0.1.1}/src/flaskforge/templates/project/tests/conftest.py.tpl
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{flaskforge_cli-0.1.0 → flaskforge_cli-0.1.1}/src/flaskforge_cli.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|