asok 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.
- asok-0.1.0/LICENSE +21 -0
- asok-0.1.0/MANIFEST.in +5 -0
- asok-0.1.0/PKG-INFO +209 -0
- asok-0.1.0/README.md +183 -0
- asok-0.1.0/asok/__init__.py +38 -0
- asok-0.1.0/asok/admin/__init__.py +2955 -0
- asok-0.1.0/asok/admin/static/admin.css +1015 -0
- asok-0.1.0/asok/admin/static/admin.js +673 -0
- asok-0.1.0/asok/admin/static/logo.svg +14 -0
- asok-0.1.0/asok/admin/static/quill.js +11489 -0
- asok-0.1.0/asok/admin/static/quill.snow.css +945 -0
- asok-0.1.0/asok/admin/templates/2fa.html +70 -0
- asok-0.1.0/asok/admin/templates/2fa_setup.html +71 -0
- asok-0.1.0/asok/admin/templates/base.html +221 -0
- asok-0.1.0/asok/admin/templates/dashboard.html +115 -0
- asok-0.1.0/asok/admin/templates/edit.html +217 -0
- asok-0.1.0/asok/admin/templates/history.html +66 -0
- asok-0.1.0/asok/admin/templates/import.html +174 -0
- asok-0.1.0/asok/admin/templates/list.html +248 -0
- asok-0.1.0/asok/admin/templates/login.html +88 -0
- asok-0.1.0/asok/admin/templates/macros.html +179 -0
- asok-0.1.0/asok/admin/templates/me.html +147 -0
- asok-0.1.0/asok/admin/templates/media.html +99 -0
- asok-0.1.0/asok/admin/templates/search.html +79 -0
- asok-0.1.0/asok/admin/translations.py +514 -0
- asok-0.1.0/asok/api/__init__.py +128 -0
- asok-0.1.0/asok/api/openapi.py +169 -0
- asok-0.1.0/asok/api/static/docs.css +654 -0
- asok-0.1.0/asok/api/static/logo.svg +14 -0
- asok-0.1.0/asok/api/templates/docs.html +450 -0
- asok-0.1.0/asok/assets/logo.svg +14 -0
- asok-0.1.0/asok/auth.py +234 -0
- asok-0.1.0/asok/background.py +43 -0
- asok-0.1.0/asok/cache.py +144 -0
- asok-0.1.0/asok/cli.py +1885 -0
- asok-0.1.0/asok/component.py +150 -0
- asok-0.1.0/asok/core.py +1711 -0
- asok-0.1.0/asok/exceptions.py +14 -0
- asok-0.1.0/asok/forms.py +677 -0
- asok-0.1.0/asok/logger.py +126 -0
- asok-0.1.0/asok/mail.py +126 -0
- asok-0.1.0/asok/orm.py +1749 -0
- asok-0.1.0/asok/ratelimit.py +90 -0
- asok-0.1.0/asok/request.py +1215 -0
- asok-0.1.0/asok/scheduler.py +45 -0
- asok-0.1.0/asok/session.py +248 -0
- asok-0.1.0/asok/templates.py +995 -0
- asok-0.1.0/asok/testing.py +120 -0
- asok-0.1.0/asok/utils/__init__.py +0 -0
- asok-0.1.0/asok/utils/css.py +75 -0
- asok-0.1.0/asok/utils/geo.py +94 -0
- asok-0.1.0/asok/utils/humanize.py +114 -0
- asok-0.1.0/asok/utils/image.py +67 -0
- asok-0.1.0/asok/utils/js.py +19 -0
- asok-0.1.0/asok/utils/minify.py +60 -0
- asok-0.1.0/asok/utils/security.py +80 -0
- asok-0.1.0/asok/validation.py +362 -0
- asok-0.1.0/asok/ws.py +801 -0
- asok-0.1.0/asok.egg-info/PKG-INFO +209 -0
- asok-0.1.0/asok.egg-info/SOURCES.txt +83 -0
- asok-0.1.0/asok.egg-info/dependency_links.txt +1 -0
- asok-0.1.0/asok.egg-info/entry_points.txt +2 -0
- asok-0.1.0/asok.egg-info/top_level.txt +1 -0
- asok-0.1.0/pyproject.toml +69 -0
- asok-0.1.0/setup.cfg +4 -0
- asok-0.1.0/tests/test_auth.py +181 -0
- asok-0.1.0/tests/test_background.py +82 -0
- asok-0.1.0/tests/test_cache.py +71 -0
- asok-0.1.0/tests/test_component.py +98 -0
- asok-0.1.0/tests/test_csrf.py +76 -0
- asok-0.1.0/tests/test_exceptions.py +27 -0
- asok-0.1.0/tests/test_forms.py +235 -0
- asok-0.1.0/tests/test_logger.py +116 -0
- asok-0.1.0/tests/test_mail.py +146 -0
- asok-0.1.0/tests/test_orm.py +235 -0
- asok-0.1.0/tests/test_ratelimit.py +45 -0
- asok-0.1.0/tests/test_request.py +196 -0
- asok-0.1.0/tests/test_routing.py +194 -0
- asok-0.1.0/tests/test_scheduler.py +77 -0
- asok-0.1.0/tests/test_security.py +123 -0
- asok-0.1.0/tests/test_session.py +171 -0
- asok-0.1.0/tests/test_templates.py +226 -0
- asok-0.1.0/tests/test_utils.py +99 -0
- asok-0.1.0/tests/test_validation.py +174 -0
- asok-0.1.0/tests/test_websocket.py +134 -0
asok-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Asok Framework 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.
|
asok-0.1.0/MANIFEST.in
ADDED
asok-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: asok
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A minimalist, zero-dependency Python web framework.
|
|
5
|
+
Author-email: Asok Maintainers <asok-framework@outlook.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/asok-framework/asok
|
|
8
|
+
Project-URL: Repository, https://github.com/asok-framework/asok
|
|
9
|
+
Project-URL: Issues, https://github.com/asok-framework/asok/issues
|
|
10
|
+
Keywords: web,framework,zero-dependency,minimalist,orm,wsgi
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.7
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Operating System :: OS Independent
|
|
21
|
+
Classifier: Topic :: Internet :: WWW/HTTP :: WSGI :: Application
|
|
22
|
+
Requires-Python: >=3.7
|
|
23
|
+
Description-Content-Type: text/markdown
|
|
24
|
+
License-File: LICENSE
|
|
25
|
+
Dynamic: license-file
|
|
26
|
+
|
|
27
|
+
# <img src="icons/favicon.svg" alt="Asok Framework Logo" width="50" align="center" /> Asok Framework
|
|
28
|
+
|
|
29
|
+
**Asok** is a powerful and elegant "zero-dependency" Python micro-framework. Version 0.1.0 introduces a professional modular architecture, file-based routing through the `src/pages/` directory, and a comprehensive CLI tool.
|
|
30
|
+
|
|
31
|
+
📖 **[→ Full Documentation](docs/README.md)** — 44 chapters, from installation to production deployment.
|
|
32
|
+
|
|
33
|
+
---
|
|
34
|
+
|
|
35
|
+
## ✨ Key Features
|
|
36
|
+
- **Zero Dependencies**: Relies exclusively on the Python standard library.
|
|
37
|
+
- **Professional Typing**: Full support for PEP 484 type hints for a robust developer experience.
|
|
38
|
+
- **Modular Package**: Install via `pip` or by simply dropping the `asok/` folder into your project.
|
|
39
|
+
- **CLI Tool**: Scaffolding (`asok make`), Dev Server (`asok dev`), and assets management.
|
|
40
|
+
- **Local Geolocation**: Built-in IP detection and localization without third-party APIs.
|
|
41
|
+
- **File-based Routing**: Your `src/pages/` directories define your URLs.
|
|
42
|
+
- **Dynamic Routing**: Native support for parameters via `[param]`.
|
|
43
|
+
- **Built-in Authentication**: Secure sessions via signed cookies (HMAC).
|
|
44
|
+
- **AsokDB**: A mini SQLite ORM with relationships and automatic hashing.
|
|
45
|
+
- **Template Engine**: Jinja-like syntax with inheritance (`extends`) and blocks.
|
|
46
|
+
|
|
47
|
+
---
|
|
48
|
+
|
|
49
|
+
## ⚖️ Asok vs Django vs Flask
|
|
50
|
+
|
|
51
|
+
Asok was designed to bring the best of both worlds (the lightweight nature of Flask and the batteries-included approach of Django), while adding modern file-based routing (inspired by Next.js/SvelteKit).
|
|
52
|
+
|
|
53
|
+
| Feature | Asok | Flask | Django |
|
|
54
|
+
|---|---|---|---|
|
|
55
|
+
| **External Dependencies** | **0 (Zero)** | ~6 (Werkzeug, Jinja...) | ~3 (asgiref, sqlparse...) |
|
|
56
|
+
| **Philosophy** | Batteries Included + Modern | Micro-framework | Megalo-framework |
|
|
57
|
+
| **Routing System** | **File-based** (`src/pages/`) | Decorators (`@app.route`) | Centralized (`urls.py`) |
|
|
58
|
+
| **Built-in ORM** | Yes (AsokDB - optimized SQLite) | No (SQLAlchemy required) | Yes (Full-featured, multi-DB) |
|
|
59
|
+
| **Generated Admin** | Yes, 100% automatic and reactive | No (Flask-Admin required) | Yes, historical and heavy |
|
|
60
|
+
| **Real-time (WebSockets)** | **Native** (Alive Engine) | No (Flask-SocketIO required) | Complex (Django Channels) |
|
|
61
|
+
| **Reactive Components** | **Native** (Live Components) | No | No |
|
|
62
|
+
| **Ideal for** | Fast projects, Modern SaaS, Zero devops | Simple APIs, Microservices | Large legacy architectures |
|
|
63
|
+
|
|
64
|
+
---
|
|
65
|
+
|
|
66
|
+
## 🛠️ Installation & Setup
|
|
67
|
+
|
|
68
|
+
### 1. Installation
|
|
69
|
+
You can install Asok via pip (coming soon) or clone the repo and use the `asok/` folder.
|
|
70
|
+
|
|
71
|
+
### 2. Create a project
|
|
72
|
+
```bash
|
|
73
|
+
asok create my-project
|
|
74
|
+
cd my-project
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### 3. Start the server
|
|
78
|
+
```bash
|
|
79
|
+
asok dev
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
---
|
|
83
|
+
|
|
84
|
+
## 🏗️ Project Structure
|
|
85
|
+
```text
|
|
86
|
+
.
|
|
87
|
+
├── wsgi.py # Application entry point
|
|
88
|
+
├── src
|
|
89
|
+
│ ├── locales/ # JSON translations (en.json, fr.json)
|
|
90
|
+
│ ├── middlewares/ # Request interceptors
|
|
91
|
+
│ ├── models/ # ORM models (Post.py, User.py)
|
|
92
|
+
│ ├── pages/ # YOUR ROUTES (page.py or page.html)
|
|
93
|
+
│ │ ├── page.html # Route /
|
|
94
|
+
│ │ └── about/
|
|
95
|
+
│ │ └── page.html # Route /about
|
|
96
|
+
│ └── partials/ # Shared resources
|
|
97
|
+
│ ├── css/, js/, images/
|
|
98
|
+
│ └── html/ # Layouts and components
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
---
|
|
102
|
+
|
|
103
|
+
## 🛣️ Routing
|
|
104
|
+
Routing is dictated by the structure of the `src/pages/` folder. Each folder represents a URL segment, and contains a `page.py` or `page.html` file.
|
|
105
|
+
|
|
106
|
+
- `src/pages/page.html` → `/`
|
|
107
|
+
- `src/pages/about/page.html` → `/about`
|
|
108
|
+
- `src/pages/user/[id]/page.py` → `/user/123` (`id` parameter)
|
|
109
|
+
|
|
110
|
+
### Dynamic Page Example (`src/pages/shop/[cat]/page.py`)
|
|
111
|
+
```python
|
|
112
|
+
def render(request):
|
|
113
|
+
category = request.params.get('cat')
|
|
114
|
+
return f"Shop : {category}"
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
---
|
|
118
|
+
|
|
119
|
+
## 🎨 Templates & Inheritance
|
|
120
|
+
Templates in `src/pages/` can inherit from layouts in `src/partials/html/`.
|
|
121
|
+
|
|
122
|
+
**Layout (`src/partials/html/main.html`)** :
|
|
123
|
+
```html
|
|
124
|
+
<html>
|
|
125
|
+
<body>
|
|
126
|
+
{% include 'html/_nav.html' %}
|
|
127
|
+
<main>{% block content %}{CONTENT}{% endblock %}</main>
|
|
128
|
+
</body>
|
|
129
|
+
</html>
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
**Page (`src/pages/page.html`)** :
|
|
133
|
+
```html
|
|
134
|
+
{% extends 'html/main.html' %}
|
|
135
|
+
{% block content %}
|
|
136
|
+
<h1>Welcome to Asok V2</h1>
|
|
137
|
+
{% endblock %}
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
---
|
|
141
|
+
|
|
142
|
+
## 🗄️ AsokDB (The ORM)
|
|
143
|
+
Define your models in `src/models/`.
|
|
144
|
+
|
|
145
|
+
```python
|
|
146
|
+
from asok import Model, Field, Relation
|
|
147
|
+
|
|
148
|
+
class User(Model):
|
|
149
|
+
name = Field.String()
|
|
150
|
+
email = Field.String(unique=True)
|
|
151
|
+
password = Field.Password()
|
|
152
|
+
posts = Relation.HasMany('Post')
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
---
|
|
156
|
+
|
|
157
|
+
## 🌍 i18n & Validation
|
|
158
|
+
- **Translation**: `{{ __('welcome') }}` (looks in `src/locales/`).
|
|
159
|
+
- **Validation**: `Validator(data).rule('email', 'required|email')`.
|
|
160
|
+
- **CSRF**: `{{ request.csrf_input() }}` automatic in forms.
|
|
161
|
+
|
|
162
|
+
---
|
|
163
|
+
|
|
164
|
+
## 🎨 Admin Customization
|
|
165
|
+
|
|
166
|
+
The administration interface is highly customizable:
|
|
167
|
+
|
|
168
|
+
```python
|
|
169
|
+
admin = Admin(app, site_name="My Platform", favicon="images/logo.svg")
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
### Asset Resolution (Smart Resolution)
|
|
173
|
+
The admin automatically detects the source of resources:
|
|
174
|
+
- **Internal Assets**: Files like `admin.css` or the default `logo.svg` are served from the package.
|
|
175
|
+
- **Project Assets**: If you specify a path (e.g. `images/logo.svg` or `uploads/icon.png`), the admin will serve them from your resources folder (`src/partials/`).
|
|
176
|
+
|
|
177
|
+
---
|
|
178
|
+
|
|
179
|
+
## 🚀 Towards Production
|
|
180
|
+
Asok is WSGI compatible. You can use Gunicorn or any other WSGI server:
|
|
181
|
+
```bash
|
|
182
|
+
gunicorn wsgi:app
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
---
|
|
186
|
+
|
|
187
|
+
## 🤝 Contributing
|
|
188
|
+
Contributions are more than welcome! Asok is built to be simple and transparent, making it a great codebase to dive into.
|
|
189
|
+
- Found a bug? Open an **Issue**.
|
|
190
|
+
- Have a feature idea? Start a **Discussion**.
|
|
191
|
+
- Fixed something? Submit a **Pull Request**.
|
|
192
|
+
|
|
193
|
+
Make sure to run the tests and linter before submitting your PR:
|
|
194
|
+
```bash
|
|
195
|
+
make lint
|
|
196
|
+
make test
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
---
|
|
200
|
+
|
|
201
|
+
## 📜 License
|
|
202
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
203
|
+
|
|
204
|
+
<br><br>
|
|
205
|
+
<p align="left">
|
|
206
|
+
<img src="icons/logo.svg" alt="Asok Framework" width="200" />
|
|
207
|
+
</p>
|
|
208
|
+
|
|
209
|
+
|
asok-0.1.0/README.md
ADDED
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
# <img src="icons/favicon.svg" alt="Asok Framework Logo" width="50" align="center" /> Asok Framework
|
|
2
|
+
|
|
3
|
+
**Asok** is a powerful and elegant "zero-dependency" Python micro-framework. Version 0.1.0 introduces a professional modular architecture, file-based routing through the `src/pages/` directory, and a comprehensive CLI tool.
|
|
4
|
+
|
|
5
|
+
📖 **[→ Full Documentation](docs/README.md)** — 44 chapters, from installation to production deployment.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## ✨ Key Features
|
|
10
|
+
- **Zero Dependencies**: Relies exclusively on the Python standard library.
|
|
11
|
+
- **Professional Typing**: Full support for PEP 484 type hints for a robust developer experience.
|
|
12
|
+
- **Modular Package**: Install via `pip` or by simply dropping the `asok/` folder into your project.
|
|
13
|
+
- **CLI Tool**: Scaffolding (`asok make`), Dev Server (`asok dev`), and assets management.
|
|
14
|
+
- **Local Geolocation**: Built-in IP detection and localization without third-party APIs.
|
|
15
|
+
- **File-based Routing**: Your `src/pages/` directories define your URLs.
|
|
16
|
+
- **Dynamic Routing**: Native support for parameters via `[param]`.
|
|
17
|
+
- **Built-in Authentication**: Secure sessions via signed cookies (HMAC).
|
|
18
|
+
- **AsokDB**: A mini SQLite ORM with relationships and automatic hashing.
|
|
19
|
+
- **Template Engine**: Jinja-like syntax with inheritance (`extends`) and blocks.
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
## ⚖️ Asok vs Django vs Flask
|
|
24
|
+
|
|
25
|
+
Asok was designed to bring the best of both worlds (the lightweight nature of Flask and the batteries-included approach of Django), while adding modern file-based routing (inspired by Next.js/SvelteKit).
|
|
26
|
+
|
|
27
|
+
| Feature | Asok | Flask | Django |
|
|
28
|
+
|---|---|---|---|
|
|
29
|
+
| **External Dependencies** | **0 (Zero)** | ~6 (Werkzeug, Jinja...) | ~3 (asgiref, sqlparse...) |
|
|
30
|
+
| **Philosophy** | Batteries Included + Modern | Micro-framework | Megalo-framework |
|
|
31
|
+
| **Routing System** | **File-based** (`src/pages/`) | Decorators (`@app.route`) | Centralized (`urls.py`) |
|
|
32
|
+
| **Built-in ORM** | Yes (AsokDB - optimized SQLite) | No (SQLAlchemy required) | Yes (Full-featured, multi-DB) |
|
|
33
|
+
| **Generated Admin** | Yes, 100% automatic and reactive | No (Flask-Admin required) | Yes, historical and heavy |
|
|
34
|
+
| **Real-time (WebSockets)** | **Native** (Alive Engine) | No (Flask-SocketIO required) | Complex (Django Channels) |
|
|
35
|
+
| **Reactive Components** | **Native** (Live Components) | No | No |
|
|
36
|
+
| **Ideal for** | Fast projects, Modern SaaS, Zero devops | Simple APIs, Microservices | Large legacy architectures |
|
|
37
|
+
|
|
38
|
+
---
|
|
39
|
+
|
|
40
|
+
## 🛠️ Installation & Setup
|
|
41
|
+
|
|
42
|
+
### 1. Installation
|
|
43
|
+
You can install Asok via pip (coming soon) or clone the repo and use the `asok/` folder.
|
|
44
|
+
|
|
45
|
+
### 2. Create a project
|
|
46
|
+
```bash
|
|
47
|
+
asok create my-project
|
|
48
|
+
cd my-project
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### 3. Start the server
|
|
52
|
+
```bash
|
|
53
|
+
asok dev
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
---
|
|
57
|
+
|
|
58
|
+
## 🏗️ Project Structure
|
|
59
|
+
```text
|
|
60
|
+
.
|
|
61
|
+
├── wsgi.py # Application entry point
|
|
62
|
+
├── src
|
|
63
|
+
│ ├── locales/ # JSON translations (en.json, fr.json)
|
|
64
|
+
│ ├── middlewares/ # Request interceptors
|
|
65
|
+
│ ├── models/ # ORM models (Post.py, User.py)
|
|
66
|
+
│ ├── pages/ # YOUR ROUTES (page.py or page.html)
|
|
67
|
+
│ │ ├── page.html # Route /
|
|
68
|
+
│ │ └── about/
|
|
69
|
+
│ │ └── page.html # Route /about
|
|
70
|
+
│ └── partials/ # Shared resources
|
|
71
|
+
│ ├── css/, js/, images/
|
|
72
|
+
│ └── html/ # Layouts and components
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
---
|
|
76
|
+
|
|
77
|
+
## 🛣️ Routing
|
|
78
|
+
Routing is dictated by the structure of the `src/pages/` folder. Each folder represents a URL segment, and contains a `page.py` or `page.html` file.
|
|
79
|
+
|
|
80
|
+
- `src/pages/page.html` → `/`
|
|
81
|
+
- `src/pages/about/page.html` → `/about`
|
|
82
|
+
- `src/pages/user/[id]/page.py` → `/user/123` (`id` parameter)
|
|
83
|
+
|
|
84
|
+
### Dynamic Page Example (`src/pages/shop/[cat]/page.py`)
|
|
85
|
+
```python
|
|
86
|
+
def render(request):
|
|
87
|
+
category = request.params.get('cat')
|
|
88
|
+
return f"Shop : {category}"
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
---
|
|
92
|
+
|
|
93
|
+
## 🎨 Templates & Inheritance
|
|
94
|
+
Templates in `src/pages/` can inherit from layouts in `src/partials/html/`.
|
|
95
|
+
|
|
96
|
+
**Layout (`src/partials/html/main.html`)** :
|
|
97
|
+
```html
|
|
98
|
+
<html>
|
|
99
|
+
<body>
|
|
100
|
+
{% include 'html/_nav.html' %}
|
|
101
|
+
<main>{% block content %}{CONTENT}{% endblock %}</main>
|
|
102
|
+
</body>
|
|
103
|
+
</html>
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
**Page (`src/pages/page.html`)** :
|
|
107
|
+
```html
|
|
108
|
+
{% extends 'html/main.html' %}
|
|
109
|
+
{% block content %}
|
|
110
|
+
<h1>Welcome to Asok V2</h1>
|
|
111
|
+
{% endblock %}
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
---
|
|
115
|
+
|
|
116
|
+
## 🗄️ AsokDB (The ORM)
|
|
117
|
+
Define your models in `src/models/`.
|
|
118
|
+
|
|
119
|
+
```python
|
|
120
|
+
from asok import Model, Field, Relation
|
|
121
|
+
|
|
122
|
+
class User(Model):
|
|
123
|
+
name = Field.String()
|
|
124
|
+
email = Field.String(unique=True)
|
|
125
|
+
password = Field.Password()
|
|
126
|
+
posts = Relation.HasMany('Post')
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
---
|
|
130
|
+
|
|
131
|
+
## 🌍 i18n & Validation
|
|
132
|
+
- **Translation**: `{{ __('welcome') }}` (looks in `src/locales/`).
|
|
133
|
+
- **Validation**: `Validator(data).rule('email', 'required|email')`.
|
|
134
|
+
- **CSRF**: `{{ request.csrf_input() }}` automatic in forms.
|
|
135
|
+
|
|
136
|
+
---
|
|
137
|
+
|
|
138
|
+
## 🎨 Admin Customization
|
|
139
|
+
|
|
140
|
+
The administration interface is highly customizable:
|
|
141
|
+
|
|
142
|
+
```python
|
|
143
|
+
admin = Admin(app, site_name="My Platform", favicon="images/logo.svg")
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
### Asset Resolution (Smart Resolution)
|
|
147
|
+
The admin automatically detects the source of resources:
|
|
148
|
+
- **Internal Assets**: Files like `admin.css` or the default `logo.svg` are served from the package.
|
|
149
|
+
- **Project Assets**: If you specify a path (e.g. `images/logo.svg` or `uploads/icon.png`), the admin will serve them from your resources folder (`src/partials/`).
|
|
150
|
+
|
|
151
|
+
---
|
|
152
|
+
|
|
153
|
+
## 🚀 Towards Production
|
|
154
|
+
Asok is WSGI compatible. You can use Gunicorn or any other WSGI server:
|
|
155
|
+
```bash
|
|
156
|
+
gunicorn wsgi:app
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
---
|
|
160
|
+
|
|
161
|
+
## 🤝 Contributing
|
|
162
|
+
Contributions are more than welcome! Asok is built to be simple and transparent, making it a great codebase to dive into.
|
|
163
|
+
- Found a bug? Open an **Issue**.
|
|
164
|
+
- Have a feature idea? Start a **Discussion**.
|
|
165
|
+
- Fixed something? Submit a **Pull Request**.
|
|
166
|
+
|
|
167
|
+
Make sure to run the tests and linter before submitting your PR:
|
|
168
|
+
```bash
|
|
169
|
+
make lint
|
|
170
|
+
make test
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
---
|
|
174
|
+
|
|
175
|
+
## 📜 License
|
|
176
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
177
|
+
|
|
178
|
+
<br><br>
|
|
179
|
+
<p align="left">
|
|
180
|
+
<img src="icons/logo.svg" alt="Asok Framework" width="200" />
|
|
181
|
+
</p>
|
|
182
|
+
|
|
183
|
+
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import sys
|
|
3
|
+
|
|
4
|
+
__version__ = "0.1.0"
|
|
5
|
+
|
|
6
|
+
# Disable bytecode generation (__pycache__) by default to keep the file-system based routing clean.
|
|
7
|
+
# Can be overridden by setting ASOK_WRITE_BYTECODE=true in the environment.
|
|
8
|
+
if os.environ.get("ASOK_WRITE_BYTECODE", "").lower() != "true":
|
|
9
|
+
sys.dont_write_bytecode = True
|
|
10
|
+
|
|
11
|
+
from .admin import Admin as Admin
|
|
12
|
+
from .api import api as api
|
|
13
|
+
from .background import background as background
|
|
14
|
+
from .cache import Cache as Cache
|
|
15
|
+
from .component import Component as Component
|
|
16
|
+
from .core import Asok as Asok
|
|
17
|
+
from .exceptions import RedirectException as RedirectException
|
|
18
|
+
from .forms import Form as Form
|
|
19
|
+
from .logger import RequestLogger as RequestLogger
|
|
20
|
+
from .logger import get_logger as get_logger
|
|
21
|
+
from .mail import Mail as Mail
|
|
22
|
+
from .utils.security import internal_only as internal_only
|
|
23
|
+
from .orm import Field as Field
|
|
24
|
+
from .orm import Model as Model
|
|
25
|
+
from .orm import ModelError as ModelError
|
|
26
|
+
from .orm import Relation as Relation
|
|
27
|
+
from .orm import slugify as slugify
|
|
28
|
+
from .ratelimit import RateLimit as RateLimit
|
|
29
|
+
from .request import Request as Request
|
|
30
|
+
from .request import UploadedFile as UploadedFile
|
|
31
|
+
from .scheduler import schedule as schedule
|
|
32
|
+
from .session import Session as Session
|
|
33
|
+
from .session import SessionStore as SessionStore
|
|
34
|
+
from .templates import render_template_string as render_template_string
|
|
35
|
+
from .testing import TestClient as TestClient
|
|
36
|
+
from .validation import Schema as Schema
|
|
37
|
+
from .validation import Validator as Validator
|
|
38
|
+
from .ws import WebSocketServer as WebSocketServer
|