changed react and python server for Download

This commit is contained in:
2024-07-08 19:38:15 +02:00
parent 409e79f362
commit e124141d0b
44 changed files with 1629 additions and 233 deletions

26
union.py Normal file
View File

@@ -0,0 +1,26 @@
# encoding: utf-8
"""
Marshmallow fields
------------------
Extension on the already available marshmallow fields
"""
from marshmallow import ValidationError, fields
class UnionField(fields.Field):
"""Field that deserializes multi-type input data to app-level objects."""
def __init__(self, types: list = [], *args, **kwargs) -> None:
super().__init__(*args, **kwargs)
if types:
self.types = types
else:
raise AttributeError('No types provided on union field')
def _deserialize(self, value, attr, data, **kwargs):
if bool([isinstance(value, i) for i in self.types if isinstance(value, i)]):
return value
else:
raise ValidationError(
f'Field shoud be any of the following types: [{", ".join([str(i) for i in self.types])}]'
)