Adds author_id to Computer resource
This commit is contained in:
parent
bdd996a132
commit
31357276ae
|
@ -7,6 +7,7 @@ from typing import Dict, List, Set
|
||||||
|
|
||||||
from boltons import urlutils
|
from boltons import urlutils
|
||||||
from citext import CIText
|
from citext import CIText
|
||||||
|
from flask import g
|
||||||
from ereuse_utils.naming import HID_CONVERSION_DOC, Naming
|
from ereuse_utils.naming import HID_CONVERSION_DOC, Naming
|
||||||
from more_itertools import unique_everseen
|
from more_itertools import unique_everseen
|
||||||
from sqlalchemy import BigInteger, Boolean, Column, Enum as DBEnum, Float, ForeignKey, Integer, \
|
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.orm import ColumnProperty, backref, relationship, validates
|
||||||
from sqlalchemy.util import OrderedSet
|
from sqlalchemy.util import OrderedSet
|
||||||
from sqlalchemy_utils import ColorType
|
from sqlalchemy_utils import ColorType
|
||||||
|
from sqlalchemy.dialects.postgresql import UUID
|
||||||
from stdnum import imei, meid
|
from stdnum import imei, meid
|
||||||
from teal.db import CASCADE_DEL, POLYMORPHIC_ID, POLYMORPHIC_ON, ResourceNotFound, URL, \
|
from teal.db import CASCADE_DEL, POLYMORPHIC_ID, POLYMORPHIC_ON, ResourceNotFound, URL, \
|
||||||
check_lower, check_range
|
check_lower, check_range
|
||||||
|
@ -27,6 +29,7 @@ from ereuse_devicehub.db import db
|
||||||
from ereuse_devicehub.resources.enums import BatteryTechnology, CameraFacing, ComputerChassis, \
|
from ereuse_devicehub.resources.enums import BatteryTechnology, CameraFacing, ComputerChassis, \
|
||||||
DataStorageInterface, DisplayTech, PrinterTechnology, RamFormat, RamInterface, Severity
|
DataStorageInterface, DisplayTech, PrinterTechnology, RamFormat, RamInterface, Severity
|
||||||
from ereuse_devicehub.resources.models import STR_SM_SIZE, Thing
|
from ereuse_devicehub.resources.models import STR_SM_SIZE, Thing
|
||||||
|
from ereuse_devicehub.resources.user.models import User
|
||||||
|
|
||||||
|
|
||||||
class Device(Thing):
|
class Device(Thing):
|
||||||
|
@ -380,6 +383,11 @@ class Computer(Device):
|
||||||
It is a subset of the Linux definition of DMI / DMI decode.
|
It is a subset of the Linux definition of DMI / DMI decode.
|
||||||
"""
|
"""
|
||||||
deposit = Column(Integer, check_range('deposit',min=0,max=100), default=0)
|
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:
|
def __init__(self, chassis, **kwargs) -> None:
|
||||||
chassis = ComputerChassis(chassis)
|
chassis = ComputerChassis(chassis)
|
||||||
|
|
|
@ -142,12 +142,14 @@ class Computer(DisplayMixin, Device):
|
||||||
components = ... # type: Column
|
components = ... # type: Column
|
||||||
chassis = ... # type: Column
|
chassis = ... # type: Column
|
||||||
deposit = ... # type: Column
|
deposit = ... # type: Column
|
||||||
|
author_id = ... # type: Column
|
||||||
|
|
||||||
def __init__(self, **kwargs) -> None:
|
def __init__(self, **kwargs) -> None:
|
||||||
super().__init__(**kwargs)
|
super().__init__(**kwargs)
|
||||||
self.components = ... # type: Set[Component]
|
self.components = ... # type: Set[Component]
|
||||||
self.actions_parent = ... # type: Set[e.Action]
|
self.actions_parent = ... # type: Set[e.Action]
|
||||||
self.chassis = ... # type: ComputerChassis
|
self.chassis = ... # type: ComputerChassis
|
||||||
|
self.author_id = ...
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def actions(self) -> List:
|
def actions(self) -> List:
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
from marshmallow import post_load, pre_load
|
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 marshmallow.validate import Length, OneOf, Range
|
||||||
from sqlalchemy.util import OrderedSet
|
from sqlalchemy.util import OrderedSet
|
||||||
from stdnum import imei, meid
|
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.device import models as m, states
|
||||||
from ereuse_devicehub.resources.models import STR_BIG_SIZE, STR_SIZE
|
from ereuse_devicehub.resources.models import STR_BIG_SIZE, STR_SIZE
|
||||||
from ereuse_devicehub.resources.schemas import Thing, UnitCodes
|
from ereuse_devicehub.resources.schemas import Thing, UnitCodes
|
||||||
|
from ereuse_devicehub.resources.user import schemas as s_user
|
||||||
|
|
||||||
|
|
||||||
class Device(Thing):
|
class Device(Thing):
|
||||||
|
@ -124,6 +125,9 @@ class Computer(Device):
|
||||||
deposit = Integer(dump_only=True,
|
deposit = Integer(dump_only=True,
|
||||||
data_key='deposit',
|
data_key='deposit',
|
||||||
description=m.Computer.deposit.__doc__)
|
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):
|
class Desktop(Computer):
|
||||||
__doc__ = m.Desktop.__doc__
|
__doc__ = m.Desktop.__doc__
|
||||||
|
|
Reference in a new issue