class DocumentMovement(Schema): id = fields.UUID() document = fields.Str(required=True) value = fields.Float(required=True) input_type = fields.String(required=True) def __init__(self): super().__init__() self.cryp = Cryptography() def to_database(self, doc): doc['document'] = self.cryp.encrypt(doc['document']) return doc def from_database(self, doc): doc['document'] = self.cryp.decrypt(doc['document']) return doc
class DocumentConsult(Schema): id = fields.UUID() document = fields.Str(required=True) company = fields.Str(required=True) consult_date = fields.Date(required=True) def __init__(self): super().__init__() self.cryp = Cryptography() def to_database(self, doc): doc['document'] = self.cryp.encrypt(doc['document']) doc['company'] = self.cryp.encrypt(doc['company']) return doc def from_database(self, doc): doc['document'] = self.cryp.decrypt(doc['document']) doc['company'] = self.cryp.decrypt(doc['company']) doc['consult_date'] = parse(doc['consult_date']).date() return doc
class DocumentAcquisition(Schema): id = fields.UUID() document = fields.Str(required=True) value = fields.Float(required=True) store = fields.Str(required=True) def __init__(self): super().__init__() self.cryp = Cryptography() def to_database(self, doc): doc['document'] = self.cryp.encrypt(doc['document']) doc['store'] = self.cryp.encrypt(doc['store']) return doc def from_database(self, doc): doc['document'] = self.cryp.decrypt(doc['document']) doc['store'] = self.cryp.decrypt(doc['store']) return doc
def __init__(self): super().__init__() self.cryp = Cryptography()
def process_bind_param(self, value, dialect): if value: return Cryptography().encrypt(value) return None
def process_result_value(self, value, dialect): if value: if isinstance(value, (bytes, bytearray)): value = value.decode() return Cryptography().decrypt(value) return None