Projekt

Obecné

Profil

Stáhnout (3.03 KB) Statistiky
| Větev: | Tag: | Revize:
1
from sqlalchemy.orm import Session
2

    
3
from . import models, schemas
4

    
5

    
6
def get_device(db: Session, device_id: int):
7
    return db.query(models.Device).filter(models.Device.id == device_id).first()
8

    
9

    
10
def get_devices(db: Session, skip: int = 0, limit: int = 100):
11
    return db.query(models.Device).offset(skip).limit(limit).all()
12

    
13

    
14
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()
18

    
19

    
20
def create_device(db: Session, device: schemas.DeviceBase):
21
    db_device = models.Device(vendor_id=device.vendor_id, product_id=device.product_id,
22
                              serial_number=device.serial_number)
23
    db.add(db_device)
24
    db.commit()
25
    db.refresh(db_device)
26
    return db_device
27

    
28

    
29
def get_license(db: Session, license_id: int):
30
    return db.query(models.License).filter(models.License.id == license_id).first()
31

    
32

    
33
def get_licenses(db: Session, skip: int = 0, limit: int = 100):
34
    return db.query(models.License).offset(skip).limit(limit).all()
35

    
36

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

    
44

    
45
def create_device_license(db: Session, device_license: schemas.DeviceLicenseBase):
46
    db_device_license = models.DeviceLicense(device_id=device_license.device_id, license_id=device_license.license_id,
47
                                             assigned_datetime=device_license.assigned_datetime)
48
    db.add(db_device_license)
49
    db.commit()
50
    db.refresh(db_device_license)
51
    return db_device_license
52

    
53

    
54
def get_pc(db: Session, pc_id: int):
55
    return db.query(models.PC).filter(models.PC.id == pc_id).first()
56

    
57

    
58
def get_pcs(db: Session, skip: int = 0, limit: int = 100):
59
    return db.query(models.PC).offset(skip).limit(limit).all()
60

    
61

    
62
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

    
66

    
67
def create_pc(db: Session, user: str, host: str):
68
    db_pc = models.PC(username=user, hostname=host)
69
    db.add(db_pc)
70
    db.commit()
71
    db.refresh(db_pc)
72
    return db_pc
73

    
74

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

    
78

    
79
def get_log(db: Session, device_id: int, skip: int = 0, limit: int = 100):
80
    return db.query(models.USBLog).filter(models.USBLog.device_id == device_id).offset(skip).limit(limit).all()
81

    
82

    
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)
85
    db.add(db_log)
86
    db.commit()
87
    db.refresh(db_log)
88
    return db_log
(2-2/6)