diff --git a/ereuse_devicehub/migrations/versions/7ecb8ff7abad_documents.py b/ereuse_devicehub/migrations/versions/7ecb8ff7abad_documents.py index 087f272c..83daaf61 100644 --- a/ereuse_devicehub/migrations/versions/7ecb8ff7abad_documents.py +++ b/ereuse_devicehub/migrations/versions/7ecb8ff7abad_documents.py @@ -39,7 +39,7 @@ def upgrade(): comment='The last time Document recorded a change for \n this thing.\n '), sa.Column('created', sa.TIMESTAMP(timezone=True), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=False, comment='When Document created this.'), - sa.Column('type', sa.Unicode(), nullable=False), + sa.Column('document_type', sa.Unicode(), nullable=False), sa.Column('date', sa.TIMESTAMP(timezone=True), nullable=True), sa.Column('id_document', sa.Unicode(), nullable=True), sa.Column('owner_id', postgresql.UUID(as_uuid=True), nullable=False), @@ -54,7 +54,7 @@ def upgrade(): op.create_index('generic_document_id', 'document', ['id'], unique=False, postgresql_using='hash', schema=f'{get_inv()}') op.create_index(op.f('ix_document_created'), 'document', ['created'], unique=False, schema=f'{get_inv()}') op.create_index(op.f('ix_document_updated'), 'document', ['updated'], unique=False, schema=f'{get_inv()}') - op.create_index('document_type_index', 'document', ['type'], unique=False, postgresql_using='hash', schema=f'{get_inv()}') + op.create_index('document_type_index', 'document', ['document_type'], unique=False, postgresql_using='hash', schema=f'{get_inv()}') # DataWipeDocument table diff --git a/ereuse_devicehub/resources/action/views/documents.py b/ereuse_devicehub/resources/action/views/documents.py index 3f3aaa84..e1f685b5 100644 --- a/ereuse_devicehub/resources/action/views/documents.py +++ b/ereuse_devicehub/resources/action/views/documents.py @@ -29,7 +29,6 @@ class ErasedView(): schema = sh_document() [data.pop(x, None) for x in ['severity', 'devices', 'name', 'description']] doc_data = schema.load(data) - doc_data['type'] = 'DataWipe' self.document = DataWipeDocument(**doc_data) db.session.add(self.document) diff --git a/ereuse_devicehub/resources/documents/models.py b/ereuse_devicehub/resources/documents/models.py index ee2ac071..a2b98511 100644 --- a/ereuse_devicehub/resources/documents/models.py +++ b/ereuse_devicehub/resources/documents/models.py @@ -16,7 +16,7 @@ class Document(Thing): id.comment = """The identifier of the device for this database. Used only internally for software; users should not use this. """ - type = Column(Unicode(STR_SM_SIZE), nullable=False) + document_type = Column(Unicode(STR_SM_SIZE), nullable=False) date = Column(db.DateTime, nullable=True) date.comment = """The date of document, some documents need to have one date """ diff --git a/ereuse_devicehub/resources/documents/schemas.py b/ereuse_devicehub/resources/documents/schemas.py index c9df245f..6500777a 100644 --- a/ereuse_devicehub/resources/documents/schemas.py +++ b/ereuse_devicehub/resources/documents/schemas.py @@ -1,4 +1,5 @@ from marshmallow.fields import DateTime, Integer, validate, Boolean +from marshmallow import post_load from teal.marshmallow import SanitizedStr, URL from ereuse_devicehub.resources.schemas import Thing from ereuse_devicehub.resources.documents import models as m @@ -7,7 +8,6 @@ from ereuse_devicehub.resources.documents import models as m class DataWipeDocument(Thing): __doc__ = m.DataWipeDocument.__doc__ id = Integer(description=m.DataWipeDocument.id.comment, dump_only=True) - type = SanitizedStr(default='DataWipeDocument') url = URL(required= False, description=m.DataWipeDocument.url.comment) success = Boolean(required=False, default=False, description=m.DataWipeDocument.success.comment) software = SanitizedStr(description=m.DataWipeDocument.software.comment) @@ -26,3 +26,7 @@ class DataWipeDocument(Thing): default='', description=m.DataWipeDocument.file_hash.comment, validate=validate.Length(max=64)) + + @post_load + def get_trade_document(self, data): + data['document_type'] = 'DataWipeDocument'