2018-09-11 19:50:40 +00:00
|
|
|
import uuid
|
2018-08-27 14:32:45 +00:00
|
|
|
from datetime import datetime
|
2018-09-11 20:51:13 +00:00
|
|
|
from typing import Iterable, Set, Union
|
2018-08-27 14:32:45 +00:00
|
|
|
from uuid import UUID
|
|
|
|
|
|
|
|
from sqlalchemy import Column
|
2018-09-11 20:51:13 +00:00
|
|
|
from sqlalchemy.orm import Query, relationship
|
2018-08-27 14:32:45 +00:00
|
|
|
from sqlalchemy_utils import Ltree
|
|
|
|
|
|
|
|
from ereuse_devicehub.resources.device.models import Device
|
|
|
|
from ereuse_devicehub.resources.models import Thing
|
|
|
|
|
2018-09-11 20:51:13 +00:00
|
|
|
LotQuery = Union[Query, Iterable['Lot']]
|
|
|
|
|
2018-08-27 14:32:45 +00:00
|
|
|
|
|
|
|
class Lot(Thing):
|
|
|
|
id = ... # type: Column
|
|
|
|
name = ... # type: Column
|
|
|
|
closed = ... # type: Column
|
|
|
|
devices = ... # type: relationship
|
2018-09-07 10:38:02 +00:00
|
|
|
paths = ... # type: relationship
|
2018-08-27 14:32:45 +00:00
|
|
|
|
|
|
|
def __init__(self, name: str, closed: bool = closed.default.arg) -> None:
|
|
|
|
super().__init__()
|
|
|
|
self.id = ... # type: UUID
|
|
|
|
self.name = ... # type: str
|
|
|
|
self.closed = ... # type: bool
|
|
|
|
self.devices = ... # type: Set[Device]
|
|
|
|
self.paths = ... # type: Set[Path]
|
|
|
|
|
2018-09-11 20:51:13 +00:00
|
|
|
def add_child(self, child: Union[Lot, uuid.UUID]):
|
2018-08-27 14:32:45 +00:00
|
|
|
pass
|
|
|
|
|
2018-09-11 20:51:13 +00:00
|
|
|
def remove_child(self, child: Lot):
|
2018-08-27 14:32:45 +00:00
|
|
|
pass
|
|
|
|
|
|
|
|
@classmethod
|
2018-09-11 20:51:13 +00:00
|
|
|
def roots(cls) -> LotQuery:
|
2018-08-27 14:32:45 +00:00
|
|
|
pass
|
|
|
|
|
2018-09-11 19:50:40 +00:00
|
|
|
@property
|
2018-09-11 20:51:13 +00:00
|
|
|
def children(self) -> LotQuery:
|
2018-09-11 19:50:40 +00:00
|
|
|
pass
|
|
|
|
|
2018-08-27 14:32:45 +00:00
|
|
|
|
|
|
|
class Path:
|
|
|
|
id = ... # type: Column
|
|
|
|
lot_id = ... # type: Column
|
|
|
|
lot = ... # type: relationship
|
|
|
|
path = ... # type: Column
|
|
|
|
created = ... # type: Column
|
|
|
|
|
|
|
|
def __init__(self, lot: Lot) -> None:
|
|
|
|
super().__init__()
|
|
|
|
self.id = ... # type: UUID
|
|
|
|
self.lot = ... # type: Lot
|
|
|
|
self.path = ... # type: Ltree
|
|
|
|
self.created = ... # type: datetime
|