2018-09-11 19:50:40 +00:00
|
|
|
import uuid
|
2018-08-27 14:32:45 +00:00
|
|
|
from datetime import datetime
|
2018-11-11 20:52:55 +00:00
|
|
|
from typing import Iterable, Optional, Set, Union
|
2018-08-27 14:32:45 +00:00
|
|
|
from uuid import UUID
|
|
|
|
|
2018-10-05 15:13:23 +00:00
|
|
|
from boltons import urlutils
|
2018-08-27 14:32:45 +00:00
|
|
|
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
|
|
|
|
|
2018-11-11 20:52:55 +00:00
|
|
|
from ereuse_devicehub.db import db
|
2018-08-27 14:32:45 +00:00
|
|
|
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-11-06 17:08:57 +00:00
|
|
|
description = ... # type: Column
|
2018-11-13 14:52:27 +00:00
|
|
|
all_devices = ... # type: relationship
|
|
|
|
parents = ... # type: relationship
|
2021-02-05 12:21:20 +00:00
|
|
|
amount = ... # type: Column
|
2020-08-17 14:45:18 +00:00
|
|
|
owner_address = ... # type: Column
|
|
|
|
owner = ... # type: relationship
|
|
|
|
transfer_state = ... # type: Column
|
|
|
|
receiver_address = ... # type: Column
|
|
|
|
receiver = ... # 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-11-13 14:52:27 +00:00
|
|
|
self.description = ... # type: str
|
|
|
|
self.all_devices = ... # type: Set[Device]
|
|
|
|
self.parents = ... # type: Set[Lot]
|
|
|
|
self.children = ... # type: Set[Lot]
|
2020-08-17 14:45:18 +00:00
|
|
|
self.owner_address = ... # type: UUID
|
2019-12-12 00:25:11 +00:00
|
|
|
self.transfer_state = ...
|
2020-08-17 14:45:18 +00:00
|
|
|
self.receiver_address = ... # type: str
|
2018-08-27 14:32:45 +00:00
|
|
|
|
2018-11-13 14:52:27 +00:00
|
|
|
def add_children(self, *children: Union[Lot, uuid.UUID]):
|
2018-08-27 14:32:45 +00:00
|
|
|
pass
|
|
|
|
|
2018-11-13 14:52:27 +00:00
|
|
|
def remove_children(self, *children: Union[Lot, uuid.UUID]):
|
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-10-06 10:45:56 +00:00
|
|
|
@property
|
|
|
|
def descendants(self) -> LotQuery:
|
|
|
|
pass
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def descendantsq(cls, id) -> LotQuery:
|
|
|
|
pass
|
|
|
|
|
2018-10-05 15:13:23 +00:00
|
|
|
@property
|
|
|
|
def url(self) -> urlutils.URL:
|
|
|
|
pass
|
2018-08-27 14:32:45 +00:00
|
|
|
|
2018-11-11 20:52:55 +00:00
|
|
|
def delete(self):
|
|
|
|
pass
|
|
|
|
|
2018-10-06 10:45:56 +00:00
|
|
|
|
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
|
2018-11-11 20:52:55 +00:00
|
|
|
|
2019-12-09 16:24:24 +00:00
|
|
|
@classmethod
|
|
|
|
def has_lot(cls, id, id1):
|
|
|
|
pass
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def delete(cls, id, id1):
|
|
|
|
pass
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def add(cls, id, id1):
|
|
|
|
pass
|
|
|
|
|
2018-11-11 20:52:55 +00:00
|
|
|
|
|
|
|
class LotDeviceDescendants(db.Model):
|
|
|
|
device_id = ... # type: Column
|
|
|
|
ancestor_lot_id = ... # type: Column
|
|
|
|
parent_lot_id = ... # type: Column
|
|
|
|
device_parent_id = ... # type: Column
|
|
|
|
|
|
|
|
def __init__(self) -> None:
|
|
|
|
super().__init__()
|
|
|
|
self.device_id = ... # type: int
|
|
|
|
self.ancestor_lot_id = ... # type: UUID
|
|
|
|
self.parent_lot_id = ... # type: UUID
|
|
|
|
self.device_parent_id = ... # type: Optional[int]
|