forked from hugapi/hug
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
33 lines (22 loc) · 706 Bytes
/
app.py
File metadata and controls
33 lines (22 loc) · 706 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import hug
from demo import api
from demo.base import Base
from demo.context import SqlalchemyContext, engine
from demo.directives import SqlalchemySession
from demo.models import TestUser
@hug.context_factory()
def create_context(*args, **kwargs):
return SqlalchemyContext()
@hug.delete_context()
def delete_context(context: SqlalchemyContext, exception=None, errors=None, lacks_requirement=None):
context.cleanup(exception)
@hug.local(skip_directives=False)
def initialize(db: SqlalchemySession):
admin = TestUser(username='admin', password='admin')
db.add(admin)
db.flush()
@hug.extend_api()
def apis():
return [api]
Base.metadata.create_all(bind=engine)
initialize()