Merge branch 'feature/update-task-data' of github.com:sartography/cr-connect-workflow into feature/update-task-data

This commit is contained in:
Dan Funk 2020-02-04 15:45:05 -05:00
commit b1a81957ef
4 changed files with 25 additions and 12 deletions

View File

@ -296,6 +296,12 @@ paths:
description: The unique id of a study
schema:
type: integer
- name: workflow_id
in: query
required: false
description: The unique id of a workflow instance
schema:
type: integer
- name: task_id
in: query
required: false

View File

@ -23,6 +23,8 @@ def update_file_from_request(file_model):
# Verify the extension
basename, file_extension = os.path.splitext(file.filename)
file_extension = file_extension.lower().strip()[1:]
print('\n\n\n', 'file_extension = "%s"' % file_extension, '\n\n\n')
print('FileType._member_names_', FileType._member_names_)
if file_extension not in FileType._member_names_:
return ApiErrorSchema().dump(ApiError('unknown_extension',
'The file you provided does not have an accepted extension:' +
@ -36,10 +38,10 @@ def update_file_from_request(file_model):
else:
file_data_model.data = file.stream.read()
session.add(file_data_model)
session.add(file_model)
session.add_all([file_model, file_data_model])
session.commit()
session.flush() # Assure the id is set on the model before returning it.
return FileModelSchema().dump(file_model)
def get_files(workflow_spec_id=None, study_id=None, workflow_id=None, task_id=None):
@ -73,16 +75,14 @@ def add_file(workflow_spec_id=None, study_id=None, workflow_id=None, task_id=Non
workflow_id=workflow_id,
task_id=task_id
)
update_file_from_request(file_model)
return FileModelSchema().dump(file_model)
return update_file_from_request(file_model)
def update_file_data(file_id):
file_model = session.query(FileModel).filter_by(id=file_id).with_for_update().first()
if file_model is None:
return ApiErrorSchema().dump(ApiError('no_such_file', 'The file id you provided does not exist')), 404
update_file_from_request(file_model)
return FileModelSchema().dump(file_model)
return update_file_from_request(file_model)
def get_file_data(file_id):

View File

@ -9,9 +9,16 @@ from crc import db
class FileType(enum.Enum):
bpmn = "bpmm"
svg = "svg"
dmn = "dmn"
# docx = "docx"
docx = "docx"
gif = 'gif'
jpg = 'jpg'
pdf = 'pdf'
png = 'png'
svg = "svg"
xlsx = 'xlsx'
zip = 'zip'
image = 'image'
class FileDataModel(db.Model):

View File

@ -1,8 +1,8 @@
"""empty message
Revision ID: 8db96620031b
Revision ID: f9c4e92a8afe
Revises:
Create Date: 2020-02-04 09:54:36.297614
Create Date: 2020-02-04 12:49:57.265041
"""
from alembic import op
@ -10,7 +10,7 @@ import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '8db96620031b'
revision = 'f9c4e92a8afe'
down_revision = None
branch_labels = None
depends_on = None
@ -51,7 +51,7 @@ def upgrade():
sa.Column('name', sa.String(), nullable=True),
sa.Column('version', sa.Integer(), nullable=True),
sa.Column('last_updated', sa.DateTime(timezone=True), nullable=True),
sa.Column('type', sa.Enum('bpmn', 'svg', 'dmn', name='filetype'), nullable=True),
sa.Column('type', sa.Enum('bpmn', 'dmn', 'docx', 'gif', 'jpg', 'pdf', 'png', 'svg', 'xlsx', 'zip', 'image', name='filetype'), nullable=True),
sa.Column('primary', sa.Boolean(), nullable=True),
sa.Column('content_type', sa.String(), nullable=True),
sa.Column('workflow_spec_id', sa.String(), nullable=True),