File: app.py

package info (click to toggle)
python-hug 2.6.0-2.4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 4,072 kB
  • sloc: python: 8,938; sh: 99; makefile: 17
file content (33 lines) | stat: -rw-r--r-- 706 bytes parent folder | download
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()