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/crud.py
1
from sqlalchemy.orm import Session
1
from datetime import datetime, date
2 2

  
3
from sqlalchemy.orm import Session
4
from sqlalchemy import and_
3 5
from . import models, schemas
4 6

  
5 7

  
......
12 14

  
13 15

  
14 16
def find_device(db: Session, device: schemas.DeviceBase):
15
    return db.query(models.Device).filter(models.Device.product_id == device.product_id and
16
                                          models.Device.vendor_id == device.vendor_id and
17
                                          models.Device.serial_number == device.serial_number).first()
17
    return db.query(models.Device).filter(and_(models.Device.product_id == device.product_id,
18
                                          models.Device.vendor_id == device.vendor_id,
19
                                          models.Device.serial_number == device.serial_number)).first()
18 20

  
19 21

  
20 22
def create_device(db: Session, device: schemas.DeviceBase):
21 23
    db_device = models.Device(vendor_id=device.vendor_id, product_id=device.product_id,
22
                              serial_number=device.serial_number)
24
                              serial_number=device.serial_number, assigned=False)
23 25
    db.add(db_device)
24 26
    db.commit()
25 27
    db.refresh(db_device)
......
34 36
    return db.query(models.License).offset(skip).limit(limit).all()
35 37

  
36 38

  
37
def create_license(db: Session, license: schemas.LicenseBase):
38
    db_license = models.License(name=license.name, expiration_date=license.expiration_date)
39
def create_license(db: Session, name: str, expdate: date):
40
    db_license = models.License(name=name, expiration_date=expdate)
39 41
    db.add(db_license)
40 42
    db.commit()
41 43
    db.refresh(db_license)
......
60 62

  
61 63

  
62 64
def find_pc(db: Session, username: str, hostname: str):
63
    return db.query(models.PC).filter(models.PC.username == username and
64
                                      models.PC.hostname == hostname).first()
65
    return db.query(models.PC).filter(and_(models.PC.username == username,
66
                                      models.PC.hostname == hostname)).first()
67

  
68

  
69
def find_pcs(db: Session, pcs: []):
70
    return db.query(models.PC).filter(models.PC.id.in_(pcs)).all()
65 71

  
66 72

  
67 73
def create_pc(db: Session, user: str, host: str):
68
    db_pc = models.PC(username=user, hostname=host)
74
    db_pc = models.PC(username=user, hostname=host, assigned=False)
69 75
    db.add(db_pc)
70 76
    db.commit()
71 77
    db.refresh(db_pc)
72 78
    return db_pc
73 79

  
74 80

  
81
def get_team(db: Session, team_id: int):
82
    return db.query(models.Team).filter(models.Team.id == team_id).first()
83

  
84

  
85
def get_teams(db: Session, skip: int = 0, limit: int = 100):
86
    return db.query(models.Team).offset(skip).limit(limit).all()
87

  
88

  
89
def create_team(db: Session, name: str):
90
    db_team = models.PC(name=name)
91
    db.add(db_team)
92
    db.commit()
93
    db.refresh(db_team)
94
    return db_team
95

  
96

  
75 97
def get_logs(db: Session, skip: int = 0, limit: int = 100):
76 98
    return db.query(models.USBLog).offset(skip).limit(limit).all()
77 99

  
......
80 102
    return db.query(models.USBLog).filter(models.USBLog.device_id == device_id).offset(skip).limit(limit).all()
81 103

  
82 104

  
83
def create_device_logs(db: Session, item: schemas.USBTempBase, dev_id: int, pc_id: int):
84
    db_log = models.USBLog(pc_id=pc_id, timestamp=item.timestamp, status=item.status, device_id=dev_id)
105
def create_device_logs(db: Session, item: schemas.USBTempBase, dev_id: int, pc_id: int, date: datetime):
106
    db_log = models.USBLog(pc_id=pc_id, timestamp=date, status=item.status, device_id=dev_id)
85 107
    db.add(db_log)
86 108
    db.commit()
87 109
    db.refresh(db_log)
88 110
    return db_log
111

  

Také k dispozici: Unified diff