From 8a0957f512471b1a10fe8b9e9260d671a3725c89 Mon Sep 17 00:00:00 2001 From: emmdim Date: Thu, 19 Dec 2019 01:38:03 +0100 Subject: [PATCH] Changes author_id (uid) to owner_address (ethereum) and receiver_id to receiver_address (just the name) + minor impvrovements --- ereuse_devicehub/resources/device/models.py | 14 +++++++------- ereuse_devicehub/resources/device/models.pyi | 11 ++++++----- ereuse_devicehub/resources/device/schemas.py | 6 +++--- ereuse_devicehub/resources/lot/models.py | 14 +++++++------- ereuse_devicehub/resources/lot/models.pyi | 12 +++++++----- ereuse_devicehub/resources/lot/schemas.py | 5 +++-- ereuse_devicehub/resources/lot/views.py | 4 ++-- 7 files changed, 35 insertions(+), 31 deletions(-) diff --git a/ereuse_devicehub/resources/device/models.py b/ereuse_devicehub/resources/device/models.py index 6d4547f3..1ecbe8f3 100644 --- a/ereuse_devicehub/resources/device/models.py +++ b/ereuse_devicehub/resources/device/models.py @@ -383,18 +383,18 @@ class Computer(Device): It is a subset of the Linux definition of DMI / DMI decode. """ deposit = Column(Integer, check_range('deposit',min=0,max=100), default=0) - author_id = db.Column(UUID(as_uuid=True), - db.ForeignKey(User.id), + owner_address = db.Column(CIText(), + db.ForeignKey(User.ethereum_address), nullable=False, - default=lambda: g.user.id) - author = db.relationship(User, primaryjoin=author_id == User.id) + default=lambda: g.user.ethereum_address) + author = db.relationship(User, primaryjoin=owner_address == User.ethereum_address) transfer_state = db.Column(IntEnum(TransferState), default=TransferState.Initial, nullable=False) transfer_state.comment = TransferState.__doc__ - receiver_id = db.Column(CIText(), + receiver_address = db.Column(CIText(), db.ForeignKey(User.ethereum_address), nullable=True) - receiver = db.relationship(User, primaryjoin=receiver_id == User.ethereum_address) - delivery_note_address = db.Column(CIText(), nullable=True) + receiver = db.relationship(User, primaryjoin=receiver_address == User.ethereum_address) + deliverynote_address = db.Column(CIText(), nullable=True) def __init__(self, chassis, **kwargs) -> None: chassis = ComputerChassis(chassis) diff --git a/ereuse_devicehub/resources/device/models.pyi b/ereuse_devicehub/resources/device/models.pyi index 36f89581..65605ce8 100644 --- a/ereuse_devicehub/resources/device/models.pyi +++ b/ereuse_devicehub/resources/device/models.pyi @@ -142,19 +142,20 @@ class Computer(DisplayMixin, Device): components = ... # type: Column chassis = ... # type: Column deposit = ... # type: Column - author_id = ... # type: Column + owner_address = ... # type: Column transfer_state = ... # type: Column - receiver_id = ... # type: Column - delivery_note_address = ... # type: Column + receiver_address = ... # type: Column + deliverynote_address = ... # type: Column def __init__(self, **kwargs) -> None: super().__init__(**kwargs) self.components = ... # type: Set[Component] self.actions_parent = ... # type: Set[e.Action] self.chassis = ... # type: ComputerChassis - self.author_id = ... # type: UUID + self.owner_address = ... # type: UUID self.transfer_state = ... - self.receiver_id = ... # type: str + self.receiver_address = ... # type: str + self.deliverynote_address = ... # type: str @property def actions(self) -> List: diff --git a/ereuse_devicehub/resources/device/schemas.py b/ereuse_devicehub/resources/device/schemas.py index 3bbacccc..eae6b0a8 100644 --- a/ereuse_devicehub/resources/device/schemas.py +++ b/ereuse_devicehub/resources/device/schemas.py @@ -126,10 +126,10 @@ class Computer(Device): data_key='deposit', description=m.Computer.deposit.__doc__) # author_id = NestedOn(s_user.User,only_query='author_id') - author_id = UUID(dump_only=True, - data_key='author_id') + owner_address = SanitizedStr(validate=f.validate.Length(max=42)) transfer_state = EnumField(enums.TransferState, description=m.Computer.transfer_state.comment) - receiver_id = SanitizedStr(validate=f.validate.Length(max=42)) + receiver_address = SanitizedStr(validate=f.validate.Length(max=42)) + deliverynote_address = SanitizedStr(validate=f.validate.Length(max=42)) class Desktop(Computer): diff --git a/ereuse_devicehub/resources/lot/models.py b/ereuse_devicehub/resources/lot/models.py index db22c433..a26bbd53 100644 --- a/ereuse_devicehub/resources/lot/models.py +++ b/ereuse_devicehub/resources/lot/models.py @@ -63,18 +63,18 @@ class Lot(Thing): descendants. """ deposit = db.Column(db.Integer, check_range('deposit', min=0, max=100), default=0) - author_id = db.Column(UUID(as_uuid=True), - db.ForeignKey(User.id), + owner_address = db.Column(CIText(), + db.ForeignKey(User.ethereum_address), nullable=False, - default=lambda: g.user.id) - author = db.relationship(User, primaryjoin=author_id == User.id) + default=lambda: g.user.ethereum_address) + owner = db.relationship(User, primaryjoin=owner_address == User.ethereum_address) transfer_state = db.Column(IntEnum(TransferState), default=TransferState.Initial, nullable=False) transfer_state.comment = TransferState.__doc__ - receiver_id = db.Column(CIText(), + receiver_address = db.Column(CIText(), db.ForeignKey(User.ethereum_address), nullable=True) - receiver = db.relationship(User, primaryjoin=receiver_id == User.ethereum_address) - delivery_note_address = db.Column(CIText(), nullable=True) + receiver = db.relationship(User, primaryjoin=receiver_address == User.ethereum_address) + deliverynote_address = db.Column(CIText(), nullable=True) def __init__(self, name: str, closed: bool = closed.default.arg, description: str = None) -> None: diff --git a/ereuse_devicehub/resources/lot/models.pyi b/ereuse_devicehub/resources/lot/models.pyi index 872278ef..e552bbf4 100644 --- a/ereuse_devicehub/resources/lot/models.pyi +++ b/ereuse_devicehub/resources/lot/models.pyi @@ -25,11 +25,12 @@ class Lot(Thing): all_devices = ... # type: relationship parents = ... # type: relationship deposit = ... # type: Column - author_id = ... # type: Column + owner_address = ... # type: Column + owner = ... # type: relationship transfer_state = ... # type: Column - receiver_id = ... # type: Column + receiver_address = ... # type: Column receiver = ... # type: relationship - delivery_note_address = ... # type: Column + deliverynote_address = ... # type: Column def __init__(self, name: str, closed: bool = closed.default.arg) -> None: super().__init__() @@ -42,9 +43,10 @@ class Lot(Thing): self.all_devices = ... # type: Set[Device] self.parents = ... # type: Set[Lot] self.children = ... # type: Set[Lot] - self.author_id = ... # type: UUID + self.owner_address = ... # type: UUID self.transfer_state = ... - self.receiver_id = ... # type: str + self.receiver_address = ... # type: str + self.deliverynote_address = ... # type: str def add_children(self, *children: Union[Lot, uuid.UUID]): pass diff --git a/ereuse_devicehub/resources/lot/schemas.py b/ereuse_devicehub/resources/lot/schemas.py index 95d4190d..861ef6a5 100644 --- a/ereuse_devicehub/resources/lot/schemas.py +++ b/ereuse_devicehub/resources/lot/schemas.py @@ -22,6 +22,7 @@ class Lot(Thing): data_key='deposit', description=m.Lot.deposit.__doc__) # author_id = NestedOn(s_user.User,only_query='author_id') - author_id = f.UUID(dump_only=True) + owner_address = SanitizedStr(validate=f.validate.Length(max=42)) transfer_state = EnumField(TransferState, description=m.Lot.transfer_state.comment) - receiver_id = SanitizedStr(validate=f.validate.Length(max=42)) + receiver_address = SanitizedStr(validate=f.validate.Length(max=42)) + deliverynote_address = SanitizedStr(validate=f.validate.Length(max=42)) \ No newline at end of file diff --git a/ereuse_devicehub/resources/lot/views.py b/ereuse_devicehub/resources/lot/views.py index 6cadc116..b7aee2de 100644 --- a/ereuse_devicehub/resources/lot/views.py +++ b/ereuse_devicehub/resources/lot/views.py @@ -41,10 +41,10 @@ class LotView(View): return ret def patch(self, id): - patch_schema = self.resource_def.SCHEMA(only=('name', 'description', 'transfer_state', 'receiver_id', 'deposit', 'delivery_note_address', 'devices', 'author_id'), partial=True) + patch_schema = self.resource_def.SCHEMA(only=('name', 'description', 'transfer_state', 'receiver_address', 'deposit', 'deliverynote_address', 'devices', 'owner_address'), partial=True) l = request.get_json(schema=patch_schema) lot = Lot.query.filter_by(id=id).one() - device_fields = ['transfer_state', 'receiver_id', 'deposit', 'delivery_note_address', 'author_id'] + device_fields = ['transfer_state', 'receiver_address', 'deposit', 'deliverynote_address', 'owner_address'] computers = [x for x in lot.all_devices if isinstance(x, Computer)] for key, value in l.items(): setattr(lot, key, value)