Merge branch 'mvp' into deliverynote

This commit is contained in:
jordi.nadeu 2019-12-12 11:23:58 +01:00
commit 778db58272
6 changed files with 38 additions and 5 deletions

View file

@ -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):
@ -375,9 +378,15 @@ 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)
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)

View file

@ -141,13 +141,16 @@ class DisplayMixin:
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

View file

@ -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):
@ -121,7 +122,12 @@ 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__)
# 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__

View file

@ -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
@ -73,6 +73,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:

View file

@ -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

View file

@ -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')