2019-12-18 19:02:17 +00:00
|
|
|
import datetime
|
2019-12-27 18:50:03 +00:00
|
|
|
import os
|
2019-12-18 19:02:17 +00:00
|
|
|
|
2019-12-27 18:50:03 +00:00
|
|
|
from crc import db, app
|
|
|
|
from crc.models import StudyModel, WorkflowSpecModel, FileType, FileModel, FileDataModel
|
2019-12-18 19:02:17 +00:00
|
|
|
|
|
|
|
|
|
|
|
class ExampleDataLoader:
|
2019-12-30 21:00:33 +00:00
|
|
|
def make_data(self):
|
|
|
|
studies = [
|
|
|
|
StudyModel(
|
|
|
|
id=1,
|
|
|
|
title='The impact of fried pickles on beer consumption in bipedal software developers.',
|
|
|
|
last_updated=datetime.datetime.now(),
|
|
|
|
protocol_builder_status='in_process',
|
|
|
|
primary_investigator_id='dhf8r',
|
|
|
|
sponsor='Sartography Pharmaceuticals',
|
|
|
|
ind_number='1234'
|
|
|
|
),
|
|
|
|
StudyModel(
|
|
|
|
id=2,
|
|
|
|
title='Requirement of hippocampal neurogenesis for the behavioral effects of soft pretzels',
|
|
|
|
last_updated=datetime.datetime.now(),
|
|
|
|
protocol_builder_status='in_process',
|
|
|
|
primary_investigator_id='dhf8r',
|
|
|
|
sponsor='Makerspace & Co.',
|
|
|
|
ind_number='5678'
|
|
|
|
),
|
|
|
|
]
|
2019-12-18 19:02:17 +00:00
|
|
|
|
2019-12-30 21:00:33 +00:00
|
|
|
workflow_specs = [WorkflowSpecModel(
|
|
|
|
id="random_fact",
|
|
|
|
display_name="Random Fact Generator",
|
|
|
|
description='Displays a random fact about a topic of your choosing.',
|
|
|
|
)]
|
2019-12-18 19:02:17 +00:00
|
|
|
|
2019-12-30 21:00:33 +00:00
|
|
|
workflow_spec_files = [WorkflowSpecModel(
|
|
|
|
id="random_fact",
|
|
|
|
display_name="Random Fact Generator",
|
|
|
|
description='Displays a random fact about a topic of your choosing.',
|
|
|
|
)]
|
2019-12-27 18:50:03 +00:00
|
|
|
|
2019-12-30 21:00:33 +00:00
|
|
|
workflow_spec_files = [FileModel(name="random_fact.bpmn",
|
|
|
|
type=FileType.bpmn,
|
|
|
|
version="1",
|
|
|
|
last_updated=datetime.datetime.now(),
|
|
|
|
primary=True,
|
|
|
|
workflow_spec_id=workflow_specs[0].id)]
|
2019-12-27 18:50:03 +00:00
|
|
|
|
2019-12-30 21:00:33 +00:00
|
|
|
filename = os.path.join(app.root_path, 'static', 'bpmn', 'random_fact', 'random_fact.bpmn')
|
|
|
|
file = open(filename, "rb")
|
|
|
|
workflow_data = [FileDataModel(data=file.read(), file_model=workflow_spec_files[0])]
|
|
|
|
all_data = studies+workflow_specs+workflow_spec_files+workflow_data
|
|
|
|
return all_data
|
2019-12-27 18:50:03 +00:00
|
|
|
|
2019-12-30 18:03:57 +00:00
|
|
|
@staticmethod
|
|
|
|
def clean_db():
|
|
|
|
db.session.flush() # Clear out any transactions before deleting it all to avoid spurious errors.
|
|
|
|
for table in reversed(db.metadata.sorted_tables):
|
|
|
|
db.session.execute(table.delete())
|
|
|
|
db.session.flush()
|
|
|
|
|
2019-12-18 19:02:17 +00:00
|
|
|
def load_all(self):
|
2019-12-30 21:00:33 +00:00
|
|
|
db.session.add_all(self.make_data())
|
2019-12-18 19:02:17 +00:00
|
|
|
db.session.commit()
|
2019-12-30 21:00:33 +00:00
|
|
|
db.session.flush()
|