2019-12-31 21:32:47 +00:00
|
|
|
import enum
|
|
|
|
|
|
|
|
from marshmallow_enum import EnumField
|
2020-01-03 16:44:24 +00:00
|
|
|
from marshmallow_sqlalchemy import ModelSchema
|
2019-12-31 21:32:47 +00:00
|
|
|
from sqlalchemy import func
|
2020-03-04 18:40:25 +00:00
|
|
|
from sqlalchemy.dialects.postgresql import UUID
|
2019-12-31 21:32:47 +00:00
|
|
|
|
|
|
|
from crc import db
|
|
|
|
|
|
|
|
|
|
|
|
class FileType(enum.Enum):
|
|
|
|
bpmn = "bpmm"
|
2020-02-05 22:23:37 +00:00
|
|
|
csv = 'csv'
|
2019-12-31 21:32:47 +00:00
|
|
|
dmn = "dmn"
|
2020-02-05 22:23:37 +00:00
|
|
|
doc = "doc"
|
2020-02-04 19:26:53 +00:00
|
|
|
docx = "docx"
|
|
|
|
gif = 'gif'
|
|
|
|
jpg = 'jpg'
|
2020-02-05 22:23:37 +00:00
|
|
|
md = 'md'
|
2020-02-04 19:26:53 +00:00
|
|
|
pdf = 'pdf'
|
|
|
|
png = 'png'
|
2020-02-05 22:23:37 +00:00
|
|
|
ppt = 'ppt'
|
|
|
|
pptx = 'pptx'
|
|
|
|
rtf = 'rtf'
|
2020-02-04 19:26:53 +00:00
|
|
|
svg = "svg"
|
2020-02-05 22:23:37 +00:00
|
|
|
svg_xml = "svg+xml"
|
|
|
|
txt = 'txt'
|
|
|
|
xls = 'xls'
|
2020-02-04 19:26:53 +00:00
|
|
|
xlsx = 'xlsx'
|
2020-02-05 22:23:37 +00:00
|
|
|
xml = 'xml'
|
2020-02-04 19:26:53 +00:00
|
|
|
zip = 'zip'
|
2019-12-31 21:32:47 +00:00
|
|
|
|
2020-02-18 15:14:03 +00:00
|
|
|
|
2020-03-04 18:40:25 +00:00
|
|
|
CONTENT_TYPES = {
|
|
|
|
"bpmn": "text/xml",
|
|
|
|
"csv": "text/csv",
|
|
|
|
"dmn": "text/xml",
|
|
|
|
"doc": "application/msword",
|
|
|
|
"docx": "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
|
|
|
"gif": "image/gif",
|
|
|
|
"jpg": "image/jpeg",
|
|
|
|
"md" : "text/plain",
|
|
|
|
"pdf": "application/pdf",
|
|
|
|
"png": "image/png",
|
|
|
|
"ppt": "application/vnd.ms-powerpoint",
|
|
|
|
"pptx": "application/vnd.openxmlformats-officedocument.presentationml.presentation",
|
|
|
|
"rtf": "application/rtf",
|
|
|
|
"svg": "image/svg+xml",
|
|
|
|
"svg_xml": "image/svg+xml",
|
|
|
|
"txt": "text/plain",
|
|
|
|
"xls": "application/vnd.ms-excel",
|
|
|
|
"xlsx": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
|
|
|
"xml": "application/xml",
|
|
|
|
"zip": "application/zip"
|
|
|
|
}
|
|
|
|
|
2019-12-31 21:32:47 +00:00
|
|
|
class FileDataModel(db.Model):
|
|
|
|
__tablename__ = 'file_data'
|
|
|
|
id = db.Column(db.Integer, primary_key=True)
|
2020-03-04 18:40:25 +00:00
|
|
|
md5_hash = db.Column(UUID(as_uuid=True), unique=False, nullable=False)
|
2019-12-31 21:32:47 +00:00
|
|
|
data = db.Column(db.LargeBinary)
|
2020-03-04 18:40:25 +00:00
|
|
|
version = db.Column(db.Integer, default=0)
|
|
|
|
last_updated = db.Column(db.DateTime(timezone=True), default=func.now())
|
2019-12-31 21:32:47 +00:00
|
|
|
file_model_id = db.Column(db.Integer, db.ForeignKey('file.id'))
|
|
|
|
file_model = db.relationship("FileModel")
|
|
|
|
|
2020-01-03 16:44:24 +00:00
|
|
|
|
2019-12-31 21:32:47 +00:00
|
|
|
class FileModel(db.Model):
|
|
|
|
__tablename__ = 'file'
|
|
|
|
id = db.Column(db.Integer, primary_key=True)
|
|
|
|
name = db.Column(db.String)
|
|
|
|
type = db.Column(db.Enum(FileType))
|
|
|
|
primary = db.Column(db.Boolean)
|
|
|
|
content_type = db.Column(db.String)
|
2020-02-04 14:57:02 +00:00
|
|
|
workflow_spec_id = db.Column(db.String, db.ForeignKey('workflow_spec.id'), nullable=True)
|
|
|
|
workflow_id = db.Column(db.Integer, db.ForeignKey('workflow.id'), nullable=True)
|
|
|
|
study_id = db.Column(db.Integer, db.ForeignKey('study.id'), nullable=True)
|
|
|
|
task_id = db.Column(db.String, nullable=True)
|
2020-02-05 19:55:31 +00:00
|
|
|
form_field_key = db.Column(db.String, nullable=True)
|
2020-03-04 18:40:25 +00:00
|
|
|
latest_version = db.Column(db.Integer, default=0)
|
2019-12-31 21:32:47 +00:00
|
|
|
|
|
|
|
|
2020-01-03 16:44:24 +00:00
|
|
|
class FileModelSchema(ModelSchema):
|
2019-12-31 21:32:47 +00:00
|
|
|
class Meta:
|
|
|
|
model = FileModel
|
2020-01-13 22:52:37 +00:00
|
|
|
include_fk = True # Includes foreign keys
|
2019-12-31 21:32:47 +00:00
|
|
|
type = EnumField(FileType)
|