ohmyapi 0.1.10__tar.gz → 0.1.12__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.
Files changed (25) hide show
  1. {ohmyapi-0.1.10 → ohmyapi-0.1.12}/PKG-INFO +26 -6
  2. {ohmyapi-0.1.10 → ohmyapi-0.1.12}/README.md +25 -5
  3. {ohmyapi-0.1.10 → ohmyapi-0.1.12}/pyproject.toml +1 -1
  4. {ohmyapi-0.1.10 → ohmyapi-0.1.12}/src/ohmyapi/builtin/auth/permissions.py +1 -0
  5. {ohmyapi-0.1.10 → ohmyapi-0.1.12}/src/ohmyapi/builtin/auth/routes.py +7 -11
  6. {ohmyapi-0.1.10 → ohmyapi-0.1.12}/src/ohmyapi/cli.py +13 -4
  7. ohmyapi-0.1.12/src/ohmyapi/core/templates/app/routes.py.j2 +17 -0
  8. ohmyapi-0.1.10/src/ohmyapi/core/templates/app/routes.py.j2 +0 -13
  9. {ohmyapi-0.1.10 → ohmyapi-0.1.12}/src/ohmyapi/__init__.py +0 -0
  10. {ohmyapi-0.1.10 → ohmyapi-0.1.12}/src/ohmyapi/__main__.py +0 -0
  11. {ohmyapi-0.1.10 → ohmyapi-0.1.12}/src/ohmyapi/builtin/auth/__init__.py +0 -0
  12. {ohmyapi-0.1.10 → ohmyapi-0.1.12}/src/ohmyapi/builtin/auth/models.py +0 -0
  13. {ohmyapi-0.1.10 → ohmyapi-0.1.12}/src/ohmyapi/core/__init__.py +0 -0
  14. {ohmyapi-0.1.10 → ohmyapi-0.1.12}/src/ohmyapi/core/runtime.py +0 -0
  15. {ohmyapi-0.1.10 → ohmyapi-0.1.12}/src/ohmyapi/core/scaffolding.py +0 -0
  16. {ohmyapi-0.1.10 → ohmyapi-0.1.12}/src/ohmyapi/core/templates/app/__init__.py.j2 +0 -0
  17. {ohmyapi-0.1.10 → ohmyapi-0.1.12}/src/ohmyapi/core/templates/app/models.py.j2 +0 -0
  18. {ohmyapi-0.1.10 → ohmyapi-0.1.12}/src/ohmyapi/core/templates/project/README.md.j2 +0 -0
  19. {ohmyapi-0.1.10 → ohmyapi-0.1.12}/src/ohmyapi/core/templates/project/pyproject.toml.j2 +0 -0
  20. {ohmyapi-0.1.10 → ohmyapi-0.1.12}/src/ohmyapi/core/templates/project/settings.py.j2 +0 -0
  21. {ohmyapi-0.1.10 → ohmyapi-0.1.12}/src/ohmyapi/db/__init__.py +0 -0
  22. {ohmyapi-0.1.10 → ohmyapi-0.1.12}/src/ohmyapi/db/exceptions.py +0 -0
  23. {ohmyapi-0.1.10 → ohmyapi-0.1.12}/src/ohmyapi/db/model/__init__.py +0 -0
  24. {ohmyapi-0.1.10 → ohmyapi-0.1.12}/src/ohmyapi/db/model/model.py +0 -0
  25. {ohmyapi-0.1.10 → ohmyapi-0.1.12}/src/ohmyapi/router.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ohmyapi
3
- Version: 0.1.10
3
+ Version: 0.1.12
4
4
  Summary: A Django-like but async web-framework based on FastAPI and TortoiseORM.
5
5
  License-Expression: MIT
6
6
  Keywords: fastapi,tortoise,orm,async,web-framework
@@ -158,7 +158,10 @@ from ohmyapi.db.exceptions import DoesNotExist
158
158
 
159
159
  from .models import Tournament
160
160
 
161
- router = APIRouter(prefix="/tournament")
161
+ # Expose your app's routes via `router = fastapi.APIRouter`.
162
+ # Use prefixes wisely to avoid cross-app namespace-collisions.
163
+ # Tags improve the UX of the OpenAPI docs at /docs.
164
+ router = APIRouter(prefix="/tournament", tags=['Tournament'])
162
165
 
163
166
 
164
167
  @router.get("/")
@@ -264,8 +267,6 @@ In your `routes.py`:
264
267
 
265
268
  ```python
266
269
  from ohmyapi.router import APIRouter, Depends
267
-
268
- from ohmyapi_auth.models import User
269
270
  from ohmyapi_auth import (
270
271
  models as auth,
271
272
  permissions,
@@ -273,7 +274,7 @@ from ohmyapi_auth import (
273
274
 
274
275
  from .models import Tournament
275
276
 
276
- router = APIRouter(prefix="/tournament")
277
+ router = APIRouter(prefix="/tournament", tags=["Tournament"])
277
278
 
278
279
 
279
280
  @router.get("/")
@@ -291,10 +292,11 @@ Use Tortoise's `Manager` to implement model-level permissions.
291
292
 
292
293
  ```python
293
294
  from ohmyapi.db import Manager
295
+ from ohmyapi_auth.models import User
294
296
 
295
297
 
296
298
  class TeamManager(Manager):
297
- async def for_user(self, user: ohmyapi_auth.models.User):
299
+ async def for_user(self, user: User):
298
300
  return await self.filter(members=user).all()
299
301
 
300
302
 
@@ -305,6 +307,24 @@ class Team(Model):
305
307
  manager = TeamManager()
306
308
  ```
307
309
 
310
+ Use the custom manager in your FastAPI route handler:
311
+
312
+ ```python
313
+ from ohmyapi.router import APIRouter
314
+ from ohmyapi_auth import (
315
+ models as auth,
316
+ permissions,
317
+ )
318
+
319
+ router = APIRouter(prefix="/tournament", tags=["Tournament"])
320
+
321
+
322
+ @router.get("/teams")
323
+ async def teams(user: auth.User = Depends(permissions.require_authenticated)):
324
+ queryset = Team.for_user(user)
325
+ return await Tournament.Schema.many.from_queryset(queryset)
326
+ ```
327
+
308
328
  ## Shell
309
329
 
310
330
  Similar to Django, you can attach to an interactive shell with your project already loaded inside.
@@ -126,7 +126,10 @@ from ohmyapi.db.exceptions import DoesNotExist
126
126
 
127
127
  from .models import Tournament
128
128
 
129
- router = APIRouter(prefix="/tournament")
129
+ # Expose your app's routes via `router = fastapi.APIRouter`.
130
+ # Use prefixes wisely to avoid cross-app namespace-collisions.
131
+ # Tags improve the UX of the OpenAPI docs at /docs.
132
+ router = APIRouter(prefix="/tournament", tags=['Tournament'])
130
133
 
131
134
 
132
135
  @router.get("/")
@@ -232,8 +235,6 @@ In your `routes.py`:
232
235
 
233
236
  ```python
234
237
  from ohmyapi.router import APIRouter, Depends
235
-
236
- from ohmyapi_auth.models import User
237
238
  from ohmyapi_auth import (
238
239
  models as auth,
239
240
  permissions,
@@ -241,7 +242,7 @@ from ohmyapi_auth import (
241
242
 
242
243
  from .models import Tournament
243
244
 
244
- router = APIRouter(prefix="/tournament")
245
+ router = APIRouter(prefix="/tournament", tags=["Tournament"])
245
246
 
246
247
 
247
248
  @router.get("/")
@@ -259,10 +260,11 @@ Use Tortoise's `Manager` to implement model-level permissions.
259
260
 
260
261
  ```python
261
262
  from ohmyapi.db import Manager
263
+ from ohmyapi_auth.models import User
262
264
 
263
265
 
264
266
  class TeamManager(Manager):
265
- async def for_user(self, user: ohmyapi_auth.models.User):
267
+ async def for_user(self, user: User):
266
268
  return await self.filter(members=user).all()
267
269
 
268
270
 
@@ -273,6 +275,24 @@ class Team(Model):
273
275
  manager = TeamManager()
274
276
  ```
275
277
 
278
+ Use the custom manager in your FastAPI route handler:
279
+
280
+ ```python
281
+ from ohmyapi.router import APIRouter
282
+ from ohmyapi_auth import (
283
+ models as auth,
284
+ permissions,
285
+ )
286
+
287
+ router = APIRouter(prefix="/tournament", tags=["Tournament"])
288
+
289
+
290
+ @router.get("/teams")
291
+ async def teams(user: auth.User = Depends(permissions.require_authenticated)):
292
+ queryset = Team.for_user(user)
293
+ return await Tournament.Schema.many.from_queryset(queryset)
294
+ ```
295
+
276
296
  ## Shell
277
297
 
278
298
  Similar to Django, you can attach to an interactive shell with your project already loaded inside.
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "ohmyapi"
3
- version = "0.1.10"
3
+ version = "0.1.12"
4
4
  description = "A Django-like but async web-framework based on FastAPI and TortoiseORM."
5
5
  license = "MIT"
6
6
  keywords = ["fastapi", "tortoise", "orm", "async", "web-framework"]
@@ -4,4 +4,5 @@ from .routes import (
4
4
  require_authenticated,
5
5
  require_admin,
6
6
  require_staff,
7
+ require_group,
7
8
  )
@@ -95,7 +95,7 @@ async def require_admin(current_user: User = Depends(get_current_user)) -> User:
95
95
 
96
96
  async def require_staff(current_user: User = Depends(get_current_user)) -> User:
97
97
  """Ensure the current user is a staff member."""
98
- if not current_user.is_staff:
98
+ if not current_user.is_admin and not current_user.is_staff:
99
99
  raise HTTPException(403, "Staff privileges required")
100
100
  return current_user
101
101
 
@@ -152,17 +152,13 @@ async def refresh_token(refresh_token: str):
152
152
  return {"access_token": new_access, "token_type": "bearer"}
153
153
 
154
154
 
155
+ @router.get("/introspect")
156
+ async def introspect(token: Dict = Depends(get_token)):
157
+ return token
158
+
159
+
155
160
  @router.get("/me")
156
161
  async def me(user: User = Depends(get_current_user)):
157
162
  """Return the currently authenticated user."""
158
- return {
159
- "email": user.email,
160
- "username": user.username,
161
- "is_admin": user.is_admin,
162
- "is_staff": user.is_staff,
163
- }
164
-
163
+ return user
165
164
 
166
- @router.get("/introspect")
167
- async def introspect(token: Dict = Depends(get_token)):
168
- return token
@@ -16,13 +16,13 @@ Find your loaded project singleton via identifier: `p`
16
16
 
17
17
  @app.command()
18
18
  def startproject(name: str):
19
- """Create a new OhMyAPI project in the given directory"""
19
+ """Create a new OhMyAPI project in the given directory."""
20
20
  scaffolding.startproject(name)
21
21
 
22
22
 
23
23
  @app.command()
24
24
  def startapp(app_name: str, root: str = "."):
25
- """Create a new app with the given name in your OhMyAPI project"""
25
+ """Create a new app with the given name in your OhMyAPI project."""
26
26
  scaffolding.startapp(app_name, root)
27
27
 
28
28
 
@@ -93,6 +93,10 @@ def migrate(app: str = "*", root: str = "."):
93
93
 
94
94
  @app.command()
95
95
  def createsuperuser(root: str = "."):
96
+ """Create a superuser in the DB.
97
+
98
+ This requires the presence of `ohmyapi_auth` in your INSTALLED_APPS to work.
99
+ """
96
100
  project_path = Path(root).resolve()
97
101
  project = runtime.Project(project_path)
98
102
  if not project.is_app_installed("ohmyapi_auth"):
@@ -103,9 +107,14 @@ def createsuperuser(root: str = "."):
103
107
  import ohmyapi_auth
104
108
  email = input("E-Mail: ")
105
109
  username = input("Username: ")
106
- password = getpass("Password: ")
110
+ password1, password2 = "foo", "bar"
111
+ while password1 != password2:
112
+ password1 = getpass("Password: ")
113
+ password2 = getpass("Repeat Password: ")
114
+ if password1 != password2:
115
+ print("Passwords didn't match!")
107
116
  user = ohmyapi_auth.models.User(email=email, username=username, is_staff=True, is_admin=True)
108
- user.set_password(password)
117
+ user.set_password(password1)
109
118
  asyncio.run(project.init_orm())
110
119
  asyncio.run(user.save())
111
120
  asyncio.run(project.close_orm())
@@ -0,0 +1,17 @@
1
+ from ohmyapi.router import APIRouter
2
+
3
+ from . import models
4
+
5
+ # Expose your app's routes via `router = fastapi.APIRouter`.
6
+ # Use prefixes wisely to avoid cross-app namespace-collisions.
7
+ # Tags improve the UX of the OpenAPI docs at /docs.
8
+ router = APIRouter(prefix="/{{ app_name }}", tags=[{{ app_name }}])
9
+
10
+
11
+ @router.get("/")
12
+ def hello_world():
13
+ return {
14
+ "project": "{{ project_name }}",
15
+ "app": "{{ app_name }}",
16
+ }
17
+
@@ -1,13 +0,0 @@
1
- from ohmyapi.router import APIRouter
2
- from . import models
3
-
4
- router = APIRouter(prefix="/{{ app_name }}")
5
-
6
-
7
- @router.get("/")
8
- def ping():
9
- return {
10
- "project": "{{ project_name }}",
11
- "app": "{{ app_name }}",
12
- }
13
-
File without changes