adds new attributes on Computer model

This commit is contained in:
JNadeu 2019-12-17 23:57:55 +01:00 committed by nad
parent ede36eabd6
commit 8be56c93f9
4 changed files with 19 additions and 5 deletions

1
.gitignore vendored
View File

@ -109,4 +109,3 @@ ENV/
.vscode/
.DS_Store
/app.py

View File

@ -20,14 +20,14 @@ 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
check_lower, check_range, IntEnum
from teal.enums import Layouts
from teal.marshmallow import ValidationError
from teal.resource import url_for_resource
from ereuse_devicehub.db import db
from ereuse_devicehub.resources.enums import BatteryTechnology, CameraFacing, ComputerChassis, \
DataStorageInterface, DisplayTech, PrinterTechnology, RamFormat, RamInterface, Severity
DataStorageInterface, DisplayTech, PrinterTechnology, RamFormat, RamInterface, Severity, TransferState
from ereuse_devicehub.resources.models import STR_SM_SIZE, Thing
from ereuse_devicehub.resources.user.models import User
@ -387,6 +387,13 @@ class Computer(Device):
nullable=False,
default=lambda: g.user.id)
author = db.relationship(User, primaryjoin=author_id == User.id)
transfer_state = db.Column(IntEnum(TransferState), default=TransferState.Initial, nullable=False)
transfer_state.comment = TransferState.__doc__
receiver_id = 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)
def __init__(self, chassis, **kwargs) -> None:
chassis = ComputerChassis(chassis)

View File

@ -143,13 +143,18 @@ class Computer(DisplayMixin, Device):
chassis = ... # type: Column
deposit = ... # type: Column
author_id = ... # type: Column
transfer_state = ... # type: Column
receiver_id = ... # type: Column
delivery_note_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 = ...
self.author_id = ... # type: UUID
self.transfer_state = ...
self.receiver_id = ... # type: str
@property
def actions(self) -> List:

View File

@ -1,6 +1,6 @@
import datetime
from marshmallow import post_load, pre_load
from marshmallow import post_load, pre_load, fields as f
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
@ -128,6 +128,9 @@ class Computer(Device):
# author_id = NestedOn(s_user.User,only_query='author_id')
author_id = UUID(dump_only=True,
data_key='author_id')
transfer_state = EnumField(enums.TransferState, description=m.Computer.transfer_state.comment)
receiver_id = SanitizedStr(validate=f.validate.Length(max=42))
class Desktop(Computer):
__doc__ = m.Desktop.__doc__