added custom jsonencoder w/ burnettk

This commit is contained in:
jasquat 2022-06-30 11:18:55 -04:00
parent 2614193640
commit 4c780df7bf
5 changed files with 26 additions and 13 deletions

View File

@ -1,8 +1,8 @@
"""empty message
Revision ID: 602d035583e9
Revision ID: 2cbb6d60f0ac
Revises:
Create Date: 2022-06-29 15:53:50.319748
Create Date: 2022-06-30 10:45:49.832257
"""
from alembic import op
@ -10,7 +10,7 @@ import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '602d035583e9'
revision = '2cbb6d60f0ac'
down_revision = None
branch_labels = None
depends_on = None
@ -97,7 +97,7 @@ def upgrade():
sa.Column('assigned_principal_id', sa.Integer(), nullable=True),
sa.Column('process_instance_data', sa.Text(), nullable=True),
sa.Column('status', sa.String(length=20), nullable=False),
sa.Column('form_file_name', sa.String(length=50), nullable=False),
sa.Column('form_file_name', sa.String(length=50), nullable=True),
sa.Column('updated_at_in_seconds', sa.Integer(), nullable=True),
sa.Column('created_at_in_seconds', sa.Integer(), nullable=True),
sa.ForeignKeyConstraint(['assigned_principal_id'], ['principal.id'], ),
@ -126,7 +126,7 @@ def upgrade():
)
op.create_table('task_event',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('user_id', sa.Integer, nullable=False),
sa.Column('user_id', sa.Integer(), nullable=False),
sa.Column('process_instance_id', sa.Integer(), nullable=False),
sa.Column('spec_version', sa.String(length=50), nullable=True),
sa.Column('action', sa.String(length=50), nullable=True),

View File

@ -16,6 +16,18 @@ from spiffworkflow_backend.routes.api_blueprint import api_blueprint
from spiffworkflow_backend.routes.process_api_blueprint import process_api_blueprint
from spiffworkflow_backend.routes.user_blueprint import user_blueprint
import flask.json
class MyJSONEncoder(flask.json.JSONEncoder):
"""MyJSONEncoder."""
def default(self, obj):
"""Default."""
if hasattr(obj, 'serialized'):
return obj.serialized
return super(MyJSONEncoder, self).default(obj)
def create_app() -> flask.app.Flask:
"""Create_app."""
@ -59,4 +71,6 @@ def create_app() -> flask.app.Flask:
mail = Mail(app)
app.config["MAIL_APP"] = mail
app.json_encoder = MyJSONEncoder
return app # type: ignore

View File

@ -7,6 +7,7 @@ from typing import Optional
from flask_bpmn.models.db import db
from flask_bpmn.models.db import SpiffworkflowBaseDBModel
from sqlalchemy import ForeignKey
from sqlalchemy.orm import relationship
from spiffworkflow_backend.models.principal import PrincipalModel
from spiffworkflow_backend.models.process_instance import ProcessInstanceModel
@ -25,6 +26,7 @@ class ActiveTaskModel(SpiffworkflowBaseDBModel):
form_json: Optional[str] = ""
bpmn_json: str = ""
assigned_principal: PrincipalModel = relationship(PrincipalModel)
id: int = db.Column(db.Integer, primary_key=True)
task_id: str = db.Column(db.String(50), nullable=False)
process_instance_id: int = db.Column(ForeignKey(ProcessInstanceModel.id), nullable=False)

View File

@ -1,4 +1,5 @@
"""Principal."""
from dataclasses import dataclass
from flask_bpmn.models.db import db
from flask_bpmn.models.db import SpiffworkflowBaseDBModel
from sqlalchemy import ForeignKey
@ -8,6 +9,7 @@ from spiffworkflow_backend.models.group import GroupModel
from spiffworkflow_backend.models.user import UserModel
@dataclass
class PrincipalModel(SpiffworkflowBaseDBModel):
"""PrincipalModel."""

View File

@ -357,21 +357,16 @@ def process_instance_list(
ProcessInstanceModel.start_in_seconds.desc(), ProcessInstanceModel.id.desc() # type: ignore
).paginate(page, per_page, False)
serialized_results = []
for process_instance in process_instances.items:
process_instance_serialized = process_instance.serialized
process_instance_serialized["process_group_id"] = process_model.process_group_id
serialized_results.append(process_instance_serialized)
response_json = {
"results": serialized_results,
"results": process_instances.items,
"pagination": {
"count": len(process_instances.items),
"total": process_instances.total,
"pages": process_instances.pages,
},
}
return Response(json.dumps(response_json), status=200, mimetype="application/json")
return make_response(jsonify(response_json), 200)
def process_instance_delete(