Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 99c92c11

Přidáno uživatelem Matěj Zeman před asi 2 roky(ů)

re #9429 Added class and funcionality for Teams table. Modified date parsing and storing. Modified View at /usb-logs/. Replaced "_" with "-" in all endpoints.

Zobrazit rozdíly:

server/sql_app/api/usb_logs.py
1 1
from typing import List
2 2
from fastapi import Depends, FastAPI, HTTPException, APIRouter, Form
3
from datetime import datetime
3 4
from sqlalchemy.orm import Session
4 5
from ...sql_app import crud, models, schemas
5 6
from ..database import SessionLocal, engine
......
23 24
        db.close()
24 25

  
25 26

  
26
@usblogs.get("/logs_web/", response_class=HTMLResponse)
27
@usblogs.get("/logs-web/", response_class=HTMLResponse)
27 28
async def read_logs(request: Request, skip: int = 0, limit: int = 100, db: Session = Depends(get_db)):
28 29
    logs = crud.get_logs(db, skip=skip, limit=limit)
29
    pcs = []
30
    for log in logs:
31
        if log.pc_id not in pcs:
32
            pcs.append(log.pc_id)
33 30
    return templates.TemplateResponse("logs.html", {"request": request, "logs": logs})
34 31

  
35 32

  
36 33
@usblogs.post("/usb-logs/", response_model=schemas.USBLog)
37 34
def create_device_logs(log: schemas.USBTempBase, db: Session = Depends(get_db)):
38 35
    dev = crud.find_device(db, log.device)
36
    dat = datetime.strptime(log.timestamp, '%Y-%m-%d %H:%M:%S.%f')
39 37
    if dev is None:
40 38
        dev = crud.create_device(db=db, device=log.device)
41 39
    pc = crud.find_pc(db, log.username, log.hostname)
42 40
    if pc is None:
43 41
        pc = crud.create_pc(db=db, user=log.username, host=log.hostname)
44 42

  
45
    print(crud.create_device_logs(db=db, item=log, dev_id=dev.id, pc_id=pc.id))
43
    print(crud.create_device_logs(db=db, item=log, dev_id=dev.id, pc_id=pc.id, date=dat))
46 44

  
47 45

  
48 46
@usblogs.get("/logs/", response_model=List[schemas.USBLog])

Také k dispozici: Unified diff