Revize 9aae8d25
Přidáno uživatelem Matěj Zeman před asi 2 roky(ů)
server/sql_app/api/licenses.py | ||
---|---|---|
1 | 1 |
from typing import List |
2 | 2 |
|
3 |
from fastapi import Depends, FastAPI, HTTPException, APIRouter |
|
3 |
from fastapi import Depends, FastAPI, HTTPException, APIRouter, Form
|
|
4 | 4 |
from sqlalchemy.orm import Session |
5 | 5 |
from datetime import date |
6 | 6 |
from sql_app import crud, models, schemas |
... | ... | |
25 | 25 |
db.close() |
26 | 26 |
|
27 | 27 |
|
28 |
@licenses.get("/license-create", response_class=HTMLResponse) |
|
29 |
async def licenses_create_web(request: Request): |
|
30 |
return templates.TemplateResponse("license_create.html", {"request": request}) |
|
31 |
|
|
32 |
|
|
28 | 33 |
@licenses.get("/licenses-web", response_class=HTMLResponse) |
29 |
async def read_pcs(request: Request, skip: int = 0, limit: int = 100, db: Session = Depends(get_db)):
|
|
34 |
async def licenses_web(request: Request, skip: int = 0, limit: int = 100, db: Session = Depends(get_db)):
|
|
30 | 35 |
licenses = crud.get_licenses(db, skip=skip, limit=limit) |
31 | 36 |
return templates.TemplateResponse("licenses.html", {"request": request, "licenses": licenses}) |
32 | 37 |
|
33 | 38 |
|
34 |
@licenses.post("/license", response_model=schemas.License) |
|
35 |
def create_license(license: schemas.LicenseCreate, db: Session = Depends(get_db)): |
|
36 |
print(crud.create_license(db=db, name=license.name, expdate=license.expiration_date)) |
|
39 |
@licenses.post("/licenses-web", response_class=HTMLResponse) |
|
40 |
def create_license(request: Request, name: str = Form(...), expdate: date = Form(...), skip: int = 0, limit: int = 100, |
|
41 |
db: Session = Depends(get_db)): |
|
42 |
db_license = crud.create_license(db, name, expdate) |
|
43 |
if db_license is None: |
|
44 |
print("something went wrong") |
|
45 |
licenses = crud.get_licenses(db, skip=skip, limit=limit) |
|
46 |
return templates.TemplateResponse("licenses.html", {"request": request, "licenses": licenses}) |
|
37 | 47 |
|
38 | 48 |
|
39 | 49 |
@licenses.get("/licenses", response_model=List[schemas.License]) |
Také k dispozici: Unified diff
re #9575 Added filter over Usernames in /api/v1/logs-web and endpoint with Form for creating a license.