Skip to content

Commit

Permalink
update Starlite asgi template (#772)
Browse files Browse the repository at this point in the history
  • Loading branch information
sinisaos authored Feb 24, 2023
1 parent 7e6012b commit a89e476
Showing 1 changed file with 8 additions and 23 deletions.
31 changes: 8 additions & 23 deletions piccolo/apps/asgi/commands/templates/app/_starlite_app.py.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,19 @@ import typing as t

from piccolo.engine import engine_finder
from piccolo_admin.endpoints import create_admin
from starlite import (
MediaType,
Response,
Starlite,
StaticFilesConfig,
TemplateConfig,
asgi,
delete,
get,
patch,
post,
)
from starlite.plugins.piccolo_orm import PiccoloORMPlugin
from starlite import Starlite, asgi, delete, get, patch, post
from starlite.config.static_files import StaticFilesConfig
from starlite.config.template import TemplateConfig
from starlite.contrib.jinja import JinjaTemplateEngine
from starlite.exceptions import NotFoundException
from starlite.plugins.piccolo_orm import PiccoloORMPlugin
from starlite.types import Receive, Scope, Send

from home.endpoints import home
from home.piccolo_app import APP_CONFIG
from home.tables import Task


# mounting Piccolo Admin
@asgi("/admin/", is_mount=True)
async def admin(scope: "Scope", receive: "Receive", send: "Send") -> None:
Expand All @@ -45,11 +38,7 @@ async def create_task(data: Task) -> Task:
async def update_task(task_id: int, data: Task) -> Task:
task = await Task.objects().get(Task.id == task_id)
if not task:
return Response(
content={},
media_type=MediaType.JSON,
status_code=404,
)
raise NotFoundException("Task does not exist")
for key, value in data.to_dict().items():
task.id = task_id
setattr(task, key, value)
Expand All @@ -62,11 +51,7 @@ async def update_task(task_id: int, data: Task) -> Task:
async def delete_task(task_id: int) -> None:
task = await Task.objects().get(Task.id == task_id)
if not task:
return Response(
content={},
media_type=MediaType.JSON,
status_code=404,
)
raise NotFoundException("Task does not exist")
await task.remove()


Expand Down

0 comments on commit a89e476

Please sign in to comment.