models: big refactor
This commit is contained in:
parent
86c3683ad6
commit
2674e115f3
22 changed files with 284 additions and 266 deletions
46
app/models/base.py
Normal file
46
app/models/base.py
Normal file
|
@ -0,0 +1,46 @@
|
|||
from datetime import datetime
|
||||
|
||||
from app import db
|
||||
from app.models import AbstractConfiguration
|
||||
|
||||
|
||||
class Group(AbstractConfiguration):
|
||||
group_name = db.Column(db.String(80), unique=True, nullable=False)
|
||||
eotk = db.Column(db.Boolean())
|
||||
|
||||
origins = db.relationship("Origin", back_populates="group")
|
||||
bridgeconfs = db.relationship("BridgeConf", back_populates="group")
|
||||
alarms = db.relationship("Alarm", back_populates="group")
|
||||
|
||||
@classmethod
|
||||
def csv_header(self):
|
||||
return super().csv_header() + [
|
||||
"group_name", "eotk"
|
||||
]
|
||||
|
||||
|
||||
class MirrorList(AbstractConfiguration):
|
||||
provider = db.Column(db.String(255), nullable=False)
|
||||
format = db.Column(db.String(20), nullable=False)
|
||||
container = db.Column(db.String(255), nullable=False)
|
||||
branch = db.Column(db.String(255), nullable=False)
|
||||
filename = db.Column(db.String(255), nullable=False)
|
||||
|
||||
def destroy(self):
|
||||
self.destroyed = datetime.utcnow()
|
||||
self.updated = datetime.utcnow()
|
||||
db.session.commit()
|
||||
|
||||
def url(self):
|
||||
if self.provider == "gitlab":
|
||||
return f"https://gitlab.com/{self.container}/-/raw/{self.branch}/{self.filename}"
|
||||
if self.provider == "github":
|
||||
return f"https://raw.githubusercontent.com/{self.container}/{self.branch}/{self.filename}"
|
||||
if self.provider == "s3":
|
||||
return f"s3://{self.container}/{self.filename}"
|
||||
|
||||
@classmethod
|
||||
def csv_header(self):
|
||||
return super().csv_header() + [
|
||||
"provider", "format", "container", "branch", "filename"
|
||||
]
|
Loading…
Add table
Add a link
Reference in a new issue