-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add support for Lilya * Fix event handlers * Fix linting and formating * Fix linting and formating with updated requirements * Update README.md
- Loading branch information
Showing
10 changed files
with
81 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
piccolo/apps/asgi/commands/templates/app/_lilya_app.py.jinja
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
from piccolo_admin.endpoints import create_admin | ||
from piccolo_api.crud.endpoints import PiccoloCRUD | ||
from piccolo.engine import engine_finder | ||
from lilya.routing import Path, Include | ||
from lilya.apps import Lilya | ||
from lilya.staticfiles import StaticFiles | ||
|
||
from home.endpoints import HomeController | ||
from home.piccolo_app import APP_CONFIG | ||
from home.tables import Task | ||
|
||
|
||
app = Lilya( | ||
routes=[ | ||
Path("/", HomeController), | ||
Include( | ||
"/admin/", | ||
create_admin( | ||
tables=APP_CONFIG.table_classes, | ||
# Required when running under HTTPS: | ||
# allowed_hosts=['my_site.com'] | ||
) | ||
), | ||
Include("/static/", StaticFiles(directory="static")), | ||
Include("/tasks/", PiccoloCRUD(table=Task)) | ||
], | ||
) | ||
|
||
|
||
@app.on_event("on_startup") | ||
async def open_database_connection_pool(): | ||
try: | ||
engine = engine_finder() | ||
await engine.start_connection_pool() | ||
except Exception: | ||
print("Unable to connect to the database") | ||
|
||
|
||
@app.on_event("on_shutdown") | ||
async def close_database_connection_pool(): | ||
try: | ||
engine = engine_finder() | ||
await engine.close_connection_pool() | ||
except Exception: | ||
print("Unable to connect to the database") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
piccolo/apps/asgi/commands/templates/app/home/_lilya_endpoints.py.jinja
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import os | ||
|
||
import jinja2 | ||
from lilya.controllers import Controller | ||
from lilya.responses import HTMLResponse | ||
|
||
|
||
ENVIRONMENT = jinja2.Environment( | ||
loader=jinja2.FileSystemLoader( | ||
searchpath=os.path.join(os.path.dirname(__file__), "templates") | ||
) | ||
) | ||
|
||
|
||
class HomeController(Controller): | ||
async def get(self, request): | ||
template = ENVIRONMENT.get_template("home.html.jinja") | ||
|
||
content = template.render(title="Piccolo + ASGI",) | ||
|
||
return HTMLResponse(content) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters