From bdd996a1323b51f533cba182085a368c109d7041 Mon Sep 17 00:00:00 2001 From: emmdim Date: Wed, 11 Dec 2019 00:35:17 +0100 Subject: [PATCH 1/3] Adds deposit field in Computer --- ereuse_devicehub/resources/device/models.py | 3 ++- ereuse_devicehub/resources/device/models.pyi | 1 + ereuse_devicehub/resources/device/schemas.py | 4 +++- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/ereuse_devicehub/resources/device/models.py b/ereuse_devicehub/resources/device/models.py index ce5ac219..40512a2c 100644 --- a/ereuse_devicehub/resources/device/models.py +++ b/ereuse_devicehub/resources/device/models.py @@ -376,9 +376,10 @@ class Computer(Device): id = Column(BigInteger, ForeignKey(Device.id), primary_key=True) chassis = Column(DBEnum(ComputerChassis), nullable=False) chassis.comment = """The physical form of the computer. - + It is a subset of the Linux definition of DMI / DMI decode. """ + deposit = Column(Integer, check_range('deposit',min=0,max=100), default=0) 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 51a8ea53..2de7bb93 100644 --- a/ereuse_devicehub/resources/device/models.pyi +++ b/ereuse_devicehub/resources/device/models.pyi @@ -141,6 +141,7 @@ class DisplayMixin: class Computer(DisplayMixin, Device): components = ... # type: Column chassis = ... # type: Column + deposit = ... # type: Column def __init__(self, **kwargs) -> None: super().__init__(**kwargs) diff --git a/ereuse_devicehub/resources/device/schemas.py b/ereuse_devicehub/resources/device/schemas.py index e5ce1c77..97c229b7 100644 --- a/ereuse_devicehub/resources/device/schemas.py +++ b/ereuse_devicehub/resources/device/schemas.py @@ -121,7 +121,9 @@ class Computer(Device): dump_only=True, collection_class=set, description=m.Computer.privacy.__doc__) - + deposit = Integer(dump_only=True, + data_key='deposit', + description=m.Computer.deposit.__doc__) class Desktop(Computer): __doc__ = m.Desktop.__doc__ From 31357276ae50b32ff2912dbb3fc76630b9f87c93 Mon Sep 17 00:00:00 2001 From: emmdim Date: Wed, 11 Dec 2019 02:19:13 +0100 Subject: [PATCH 2/3] Adds author_id to Computer resource --- ereuse_devicehub/resources/device/models.py | 8 ++++++++ ereuse_devicehub/resources/device/models.pyi | 4 +++- ereuse_devicehub/resources/device/schemas.py | 6 +++++- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/ereuse_devicehub/resources/device/models.py b/ereuse_devicehub/resources/device/models.py index 40512a2c..b36c00dc 100644 --- a/ereuse_devicehub/resources/device/models.py +++ b/ereuse_devicehub/resources/device/models.py @@ -7,6 +7,7 @@ from typing import Dict, List, Set from boltons import urlutils from citext import CIText +from flask import g from ereuse_utils.naming import HID_CONVERSION_DOC, Naming from more_itertools import unique_everseen from sqlalchemy import BigInteger, Boolean, Column, Enum as DBEnum, Float, ForeignKey, Integer, \ @@ -16,6 +17,7 @@ from sqlalchemy.ext.hybrid import hybrid_property from sqlalchemy.orm import ColumnProperty, backref, relationship, validates from sqlalchemy.util import OrderedSet from sqlalchemy_utils import ColorType +from sqlalchemy.dialects.postgresql import UUID from stdnum import imei, meid from teal.db import CASCADE_DEL, POLYMORPHIC_ID, POLYMORPHIC_ON, ResourceNotFound, URL, \ check_lower, check_range @@ -27,6 +29,7 @@ from ereuse_devicehub.db import db from ereuse_devicehub.resources.enums import BatteryTechnology, CameraFacing, ComputerChassis, \ DataStorageInterface, DisplayTech, PrinterTechnology, RamFormat, RamInterface, Severity from ereuse_devicehub.resources.models import STR_SM_SIZE, Thing +from ereuse_devicehub.resources.user.models import User class Device(Thing): @@ -380,6 +383,11 @@ 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), + nullable=False, + default=lambda: g.user.id) + author = db.relationship(User, primaryjoin=author_id == User.id) 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 2de7bb93..453f93d0 100644 --- a/ereuse_devicehub/resources/device/models.pyi +++ b/ereuse_devicehub/resources/device/models.pyi @@ -142,13 +142,15 @@ class Computer(DisplayMixin, Device): components = ... # type: Column chassis = ... # type: Column deposit = ... # type: Column + author_id = ... # 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 = ... + @property def actions(self) -> List: pass diff --git a/ereuse_devicehub/resources/device/schemas.py b/ereuse_devicehub/resources/device/schemas.py index 97c229b7..ec9aa72c 100644 --- a/ereuse_devicehub/resources/device/schemas.py +++ b/ereuse_devicehub/resources/device/schemas.py @@ -1,7 +1,7 @@ import datetime from marshmallow import post_load, pre_load -from marshmallow.fields import Boolean, Date, DateTime, Float, Integer, List, Str, String +from marshmallow.fields import Boolean, Date, DateTime, Float, Integer, List, Str, String, UUID from marshmallow.validate import Length, OneOf, Range from sqlalchemy.util import OrderedSet from stdnum import imei, meid @@ -14,6 +14,7 @@ from ereuse_devicehub.resources import enums from ereuse_devicehub.resources.device import models as m, states from ereuse_devicehub.resources.models import STR_BIG_SIZE, STR_SIZE from ereuse_devicehub.resources.schemas import Thing, UnitCodes +from ereuse_devicehub.resources.user import schemas as s_user class Device(Thing): @@ -124,6 +125,9 @@ class Computer(Device): deposit = Integer(dump_only=True, 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') class Desktop(Computer): __doc__ = m.Desktop.__doc__ From 856745ef91b899b49d1b8aa3275f837a169b3a51 Mon Sep 17 00:00:00 2001 From: emmdim Date: Wed, 11 Dec 2019 02:49:47 +0100 Subject: [PATCH 3/3] Adds deposit and author is lot resources --- ereuse_devicehub/resources/lot/models.py | 8 +++++++- ereuse_devicehub/resources/lot/models.pyi | 3 +++ ereuse_devicehub/resources/lot/schemas.py | 6 ++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/ereuse_devicehub/resources/lot/models.py b/ereuse_devicehub/resources/lot/models.py index 5d08ab88..7e86b949 100644 --- a/ereuse_devicehub/resources/lot/models.py +++ b/ereuse_devicehub/resources/lot/models.py @@ -9,7 +9,7 @@ from sqlalchemy import TEXT from sqlalchemy.dialects.postgresql import UUID from sqlalchemy_utils import LtreeType from sqlalchemy_utils.types.ltree import LQUERY -from teal.db import CASCADE_OWN, UUIDLtree +from teal.db import CASCADE_OWN, UUIDLtree, check_range from teal.resource import url_for_resource from ereuse_devicehub.db import create_view, db, exp, f @@ -61,6 +61,12 @@ class Lot(Thing): """All devices, including components, inside this lot and its 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), + nullable=False, + default=lambda: g.user.id) + author = db.relationship(User, primaryjoin=author_id == User.id) 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 2c820b0c..6101e9e9 100644 --- a/ereuse_devicehub/resources/lot/models.pyi +++ b/ereuse_devicehub/resources/lot/models.pyi @@ -24,6 +24,8 @@ class Lot(Thing): description = ... # type: Column all_devices = ... # type: relationship parents = ... # type: relationship + deposit = ... # type: Column + author_id = ... # type: Column def __init__(self, name: str, closed: bool = closed.default.arg) -> None: super().__init__() @@ -36,6 +38,7 @@ class Lot(Thing): self.all_devices = ... # type: Set[Device] self.parents = ... # type: Set[Lot] self.children = ... # type: Set[Lot] + self.author_id = ... 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 c6550e86..6fd4f889 100644 --- a/ereuse_devicehub/resources/lot/schemas.py +++ b/ereuse_devicehub/resources/lot/schemas.py @@ -17,3 +17,9 @@ class Lot(Thing): children = NestedOn('Lot', many=True, dump_only=True) parents = NestedOn('Lot', many=True, dump_only=True) url = URL(dump_only=True, description=m.Lot.url.__doc__) + deposit = f.Integer(dump_only=True, + 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, + data_key='author_id')