2019-01-23 15:55:04 +00:00
|
|
|
from boltons.typeutils import classproperty
|
|
|
|
from flask import current_app
|
|
|
|
|
2019-01-21 15:08:55 +00:00
|
|
|
from ereuse_devicehub.db import db
|
|
|
|
from ereuse_devicehub.resources.models import Thing
|
|
|
|
|
|
|
|
|
|
|
|
class Inventory(Thing):
|
|
|
|
id = db.Column(db.Unicode(), primary_key=True)
|
|
|
|
id.comment = """The name of the inventory as in the URL and schema."""
|
|
|
|
name = db.Column(db.CIText(), nullable=False, unique=True)
|
|
|
|
name.comment = """The human name of the inventory."""
|
2019-01-23 15:55:04 +00:00
|
|
|
tag_provider = db.Column(db.URL(), nullable=False)
|
|
|
|
tag_token = db.Column(db.UUID(as_uuid=True), unique=True, nullable=False)
|
2019-01-21 15:08:55 +00:00
|
|
|
tag_token.comment = """The token to access a Tag service."""
|
2019-01-23 15:55:04 +00:00
|
|
|
org_id = db.Column(db.UUID(as_uuid=True), db.ForeignKey('organization.id'), nullable=False)
|
|
|
|
|
2019-02-07 12:47:42 +00:00
|
|
|
__table_args__ = (
|
|
|
|
db.Index('id_hash', id, postgresql_using='hash'),
|
|
|
|
{'schema': 'common'}
|
|
|
|
)
|
|
|
|
|
2019-01-23 15:55:04 +00:00
|
|
|
@classproperty
|
|
|
|
def current(cls) -> 'Inventory':
|
|
|
|
"""The inventory of the current_app."""
|
|
|
|
return Inventory.query.filter_by(id=current_app.id).one()
|