This repository has been archived on 2024-05-31. You can view files and clone it, but cannot push or open issues or pull requests.
devicehub-teal/ereuse_devicehub/parser/models.py

43 lines
1.4 KiB
Python
Raw Normal View History

from citext import CIText
2022-04-12 08:24:32 +00:00
from flask import g
from sqlalchemy import BigInteger, Column, Sequence, SmallInteger
from sqlalchemy.dialects.postgresql import UUID
from ereuse_devicehub.db import db
from ereuse_devicehub.resources.action.models import Snapshot
from ereuse_devicehub.resources.enums import Severity
from ereuse_devicehub.resources.models import Thing
2022-04-12 08:24:32 +00:00
from ereuse_devicehub.resources.user.models import User
class SnapshotsLog(Thing):
2022-05-18 15:59:05 +00:00
"""A Snapshot log."""
id = Column(BigInteger, Sequence('snapshots_log_seq'), primary_key=True)
severity = Column(SmallInteger, default=Severity.Info, nullable=False)
2022-05-18 10:46:57 +00:00
version = Column(CIText(), default='', nullable=True)
description = Column(CIText(), default='', nullable=True)
sid = Column(CIText(), nullable=True)
2022-05-18 15:59:05 +00:00
snapshot_uuid = Column(UUID(as_uuid=True), nullable=True)
snapshot_id = Column(UUID(as_uuid=True), db.ForeignKey(Snapshot.id), nullable=True)
2022-04-12 08:24:32 +00:00
owner_id = db.Column(
UUID(as_uuid=True),
db.ForeignKey(User.id),
nullable=False,
default=lambda: g.user.id,
)
2022-05-18 15:59:05 +00:00
snapshot = db.relationship(Snapshot, primaryjoin=snapshot_id == Snapshot.id)
2022-04-12 08:24:32 +00:00
owner = db.relationship(User, primaryjoin=owner_id == User.id)
def save(self, commit=False):
db.session.add(self)
if commit:
db.session.commit()
2022-05-18 16:26:01 +00:00
def get_status(self):
if self.severity:
return Severity(self.severity)
return ''