class HCPRequestSchema(Schema): urgency = Int(validate=OneOf([1, 2, 3])) notes = Str() region = Int(description='Get region ids from /region') facility = Nested(FacilitySchema) contact = Nested(ContactSchema) items = Nested(ItemsSchema)
class BaseCitizenRequestSchema(Schema): name = Str(validate=BASIC_STRING_LENGTH, required=True) gender = Str(validate=OneOf([gender.name for gender in Gender]), required=True) birth_date = Date(format=DATE_FORMAT, required=True) town = Str(validate=BASIC_STRING_LENGTH, required=True) street = Str(validate=BASIC_STRING_LENGTH, required=True) building = Str(validate=BASIC_STRING_LENGTH, required=True) apartment = Int(validate=POSITIVE_VALUE, required=True) relatives = List(Int(validate=POSITIVE_VALUE), required=True) @validates("birth_date") def validate_birth_date(self, value: date) -> None: """ Валидация на то, что дата рождения не может быть датой из будущего. :param value: дата для валидации """ if value > date.today(): raise ValidationError("Birth date can not be in future") @validates("relatives") def validate_relatives_unique(self, value: list) -> None: """ Валидация на уникальной id-шников родственников. :param value: список id-шников родственников """ if len(value) != len(set(value)): raise ValidationError("Relatives must be unique")
class LicenseSwitchScheme(BaseModelScheme): user_email = Str(validate=[validate.Length(max=128)]) type = Int() ip = Str(required=True, allow_none=False, validate=[validate.Length(max=16), validate.Regexp(IP_REGEXP)]) switch_port = Int() minute_count = Int() amount = Int() license_switch_uuid = Str(validate=[validate.Length(max=36)]) package_switch_uuid = Str(validate=[ validate.Length(max=36), lambda value: _valid('PackageSwitch', 'package_switch_uuid', value) ]) user_uuid = Str(validate=[ validate.Length( max=36), lambda value: _valid('User', 'user_uuid', value) ]) start_time = DateTime() end_time = DateTime() duration = Choice() ordered_amount = Int() cost = Float() package = Nested('PackageSwitchScheme', many=False) enabled = Bool() switch_uuid = Str(validate=[ validate.Length( max=64), lambda value: _valid('DnlLicenseInfo', 'uuid', value) ]) class Meta: model = model.LicenseSwitch fields = ('package_switch_uuid', 'ip', 'start_time', 'duration', 'switch_uuid')
class ClienteUnidadeConsumidoraSchema(Schema): codClienteUnidadeConsumidora = Int() codCliente = Int() numeroUC = Str(required=True, error_messages={'required': MSG_FIELD_REQUIRED}) endereco = Str() numero = Str() codCidade = Int() bairro = Str() consumoMedioMensal = Float() taxaDisponibilidade = Float() classe = EnumField(ClassesEnum, by_value=True) fase = EnumField(FasesEnum, by_value=True) seq = Int() def getClasse(self, obj): print(obj.classe.value) return obj.classe.value def getFase(self, obj): print(obj.fase.value) return obj.fase.value @post_load def make_clienteUnidadeConsumidora(self, data, **kwargs): return ClienteUnidadeConsumidora(**data)
class PatchCitizenRequestSchema(BaseCitizenRequestSchema): name = Str(validate=BASIC_STRING_LENGTH) gender = Str(validate=OneOf([gender.name for gender in Gender])) birth_date = Date(format=DATE_FORMAT) town = Str(validate=BASIC_STRING_LENGTH) street = Str(validate=BASIC_STRING_LENGTH) building = Str(validate=BASIC_STRING_LENGTH) apartment = Int(validate=POSITIVE_VALUE) relatives = List(Int(validate=POSITIVE_VALUE))
class CitizenSchema(PatchCitizenSchema): citizen_id = Int(validate=Range(min=0), strict=True, required=True) name = Str(validate=Length(min=1, max=256), required=True) gender = Str(validate=OneOf([gender.value for gender in Gender]), required=True) birth_date = Date(format=BIRTH_DATE_FORMAT, required=True) town = Str(validate=Length(min=1, max=256), required=True) street = Str(validate=Length(min=1, max=256), required=True) building = Str(validate=Length(min=1, max=256), required=True) apartment = Int(validate=Range(min=0), strict=True, required=True) relatives = List(Int(validate=Range(min=0), strict=True), required=True)
class DenoiseBaseSchema(argschema.schemas.DefaultSchema): video_path = argschema.fields.InputFile( required=True, description=("path to hdf5 video with movie stored " "in dataset 'data' nframes x nrow x ncol")) video_output = argschema.fields.OutputFile( required=True, description="destination path to filtered hdf5 video ") h5_chunk_shape = argschema.fields.Tuple( (Int(), Int(), (Int())), default=(50, 32, 32), description="passed to h5py.File.create_dataset(chunks=)")
class ExtractROISchema(Schema): """This ROI format is the expected input of AllenSDK's extract_traces 'rois' field """ id = Int(required=True, description=("Unique ID of the ROI, gets overwritten writting " "to LIMS")) x = Int(required=True, description="X location of top left corner of ROI in pixels") y = Int(required=True, description="Y location of top left corner of ROI in pixels") width = Int(required=True, description="Width of the ROI in pixels") height = Int(required=True, description="Height of the ROI in pixels") mask = List(List(Bool), required=False, description=("Bool nested list describing which pixels " "in the ROI area are part of the cell" "'mask' and 'mask_matrix' are aliases and " "one must be specified.")) mask_matrix = List(List(Bool), required=False, description=("Bool nested list describing which pixels " "in the ROI area are part of the cell" "'mask' and 'mask_matrix' are aliases and " "one must be specified.")) valid = Bool(required=False, description=("Boolean indicating if the ROI is a valid " "cell or not. 'valid' and 'valid_roi' are " "aliases and one must be specified.")) valid_roi = Bool(required=False, description=("Boolean indicating if the ROI is a valid " "cell or not. 'valid' and 'valid_roi' are " "aliases and one must be specified.")) @post_load def check_aliases(self, data, **kwargs): # decrosstalk strategy using 'mask_matrix' and 'valid_roi' # trace_extraction strategy using 'mask' and 'valid' def check(k1, k2): if (k1 not in data) & (k2 not in data): raise ValidationError(f"one of {k1} or {k2} needed") if (k1 in data) & (k2 in data): if data[k1] != data[k2]: raise ValidationError(f"{k1} and {k2} provided, " "but they differ") check("valid_roi", "valid") check("mask_matrix", "mask") return data
class SymptonSchema(Schema): sympton_name = Str( required=True, error_messages={'required': MSG_FIELD_REQUIRED} ) value = Int( required=True, error_messages={'required': MSG_FIELD_REQUIRED} )
class ResellerPurchaseUpdateSchema(Schema): code = Str(required=True, error_messages=SCHEMA_MESSAGE_REQUIRED) value = Float(required=True, error_messages=SCHEMA_MESSAGE_REQUIRED) date = DateTime(format='%Y-%m-%d %H:%M:%S', required=True, error_messages=SCHEMA_MESSAGE_REQUIRED) status_code = Int(required=True) status_description = Str(required=True)
class PackageSwitchScheme(BaseModelScheme): package_switch_uuid = Str(validate=[validate.Length(max=36)]) package_name = Str(validate=[validate.Length(max=64)]) type = Choice() sub_type = Choice() switch_port = Int() minute_count = Int() amount = Int() enabled = Bool() start_date = DateTime() expire_date = DateTime() licenses = Nested('LicenseSwitchScheme', many=True) class Meta: model = model.PackageSwitch fields = ('package_name', 'type', 'sub_type', 'switch_port', 'minute_count', 'amount', 'enabled', 'start_date', 'expire_date')
class XMLResourceSchema(ResourceMixin, Schema): ext_ident = Str(data_key='extIdent', validate=validate.Length(max=36), required=True) int_ident = Int(data_key='intIdent') status = Str(data_key='@status', validate=validate.OneOf(choices=['draft', 'published'])) link = URL(data_key='url') title_pl = Str() title_en = Str() description_pl = Str() description_en = Str() availability = Str(validate=validate.OneOf(choices=['local', 'remote'])) data_date = Date(data_key='dataDate') created = DateTime(data_key='created', allow_none=True) modified = DateTime(data_key='lastUpdateDate', allow_none=True) special_signs = List(Str()) class Meta: ordered = True unknown = EXCLUDE @pre_load def prepare_data(self, data, **kwargs): if 'title' in data and isinstance(data.get('title'), dict): data['title_en'] = data['title'].get('english', '') data['title_pl'] = data['title'].get('polish', '') if 'description' in data and isinstance(data.get('description'), dict): data['description_en'] = data['description'].get('english', '') data['description_pl'] = data['description'].get('polish', '') data['availability'] = data.get('availability', 'local') special_signs = data.pop('specialSigns', {}) if 'specialSign' in special_signs: data['special_signs'] = special_signs['specialSign'] return data @validates_schema def validate_int_ident(self, data, **kwargs): int_ident = data.get('int_ident') dataset_int_ident = self.context.get('dataset_int_ident') organization = self.context['organization'] if int_ident and not dataset_int_ident: raise ValidationError( _('intIdent value for related dataset is also required!'), field_name='int_ident') if int_ident and dataset_int_ident and organization and not Resource.raw.filter( id=int_ident, dataset_id=dataset_int_ident, dataset__organization=organization).exists(): msg = _( 'Resource with id: %(r_id)s, dataset\'s id: %(d_id)s and institution "%(ins)s" was not found.' ) % { 'r_id': int_ident, 'd_id': dataset_int_ident, "ins": organization.title } raise ValidationError(msg, field_name='int_ident')
def get(self, schedule_id): arg_fields = {'time_period_offset': Int(missing=0)} args = parser.parse(arg_fields) schedule_info = ScheduleDAO().get_by_schedule_id(schedule_id) logging.info('Successfully retrieved schedule ({0}?).'.format( schedule_id, )) return jsonify(ScheduleMarshal().dump(schedule_info).data)
class DatasetSchema(Schema): author = Str() author_email = Str() creator_user_id = UUID() extras = Nested(ExtraSchema, many=True) groups = Nested(CategorySchema, many=True) license_id = Str() license_title = Str() license_url = URL() maintainer = Str() maintainer_email = Str() created = DateTime(data_key='metadata_created') modified = DateTime(data_key='metadata_modified', allow_none=True) slug = Str(data_key='name') notes = Str() num_resources = Int() num_tags = Int() ext_ident = Str(data_key='id', validate=validate.Length(max=36)) isopen = Bool() organization = Nested(OrganizationSchema, many=False) owner_org = UUID() private = Bool() relationships_as_object = Nested(RelationshipObjectSchema, many=True) relationships_as_subject = Nested(RelationshipSubjectSchema, many=True) resources = Nested(ResourceSchema, many=True) revision_id = UUID() status = Str(data_key='state') tags = Nested(TagSchema, many=True) title = Str() type = Str() url = Str() version = Str() class Meta: exclude = [ 'author', 'author_email', 'creator_user_id', 'extras', 'groups', 'license_title', 'license_url', 'maintainer', 'maintainer_email', 'num_resources', 'num_tags', 'isopen', 'owner_org', 'private', 'relationships_as_object', 'relationships_as_subject', 'revision_id', 'type', 'status', 'url', 'version' ] ordered = True unknown = EXCLUDE
class PatchCitizenSchema(Schema): name = Str(validate=Length(min=1, max=256)) gender = Str(validate=OneOf([gender.value for gender in Gender])) birth_date = Date(format=BIRTH_DATE_FORMAT) town = Str(validate=Length(min=1, max=256)) street = Str(validate=Length(min=1, max=256)) building = Str(validate=Length(min=1, max=256)) apartment = Int(validate=Range(min=0), strict=True) relatives = List(Int(validate=Range(min=0), strict=True)) @validates('birth_date') def validate_birth_date(self, value: date): if value > date.today(): raise ValidationError("Birth date can't be in future") @validates('relatives') def validate_relatives_unique(self, value: list): if len(value) != len(set(value)): raise ValidationError('relatives must be unique')
class ClienteSchema(Schema): codCliente = Int() nome = Str(required=True, error_messages={'required': MSG_FIELD_REQUIRED}) cnpjCpf = Str(required=True, error_messages={'required': MSG_FIELD_REQUIRED}) celular = Str() email = Str() unidadesConsumidoras = List(Nested(ClienteUnidadeConsumidoraSchema)) @post_load def make_cliente(self, data, **kwargs): return Cliente(**data)
class TriagemSchema(Schema): cpf = Str( required=True, error_messages={'required': MSG_FIELD_REQUIRED} ) doctor = Str( required=True, error_messages={'required': MSG_FIELD_REQUIRED} ) main_complaint = Str( required=True, error_messages={'required': MSG_FIELD_REQUIRED} ) attendance_date = Str( required=True, error_messages={'required': MSG_FIELD_REQUIRED} ) crm = Int( required=True, error_messages={'required': MSG_FIELD_REQUIRED} ) manchester_classification = Int( required=True, error_messages={'required': MSG_FIELD_REQUIRED} ) sympton = List(Nested(SymptonSchema))
class KitSchema(Schema): codKit = Int() nome = Str(required=True, error_messages={'required': MSG_FIELD_REQUIRED}) precoVenda = Float(allow_none=True) qtdeModulos = Int(allow_none=True) potenciaModulo = Float(allow_none=True) tipoModulo = EnumField(TiposModuloEnum, by_value=True, allow_none=True) marcaModulo = Str(allow_none=True) descricaoModulo = Str(allow_none=True) qtdeInversor = Str(allow_none=True) potenciaInversor = Float(allow_none=True) tipoInversor = EnumField(TiposInversorEnum, by_value=True, allow_none=True) marcaInversor = Str(allow_none=True) descricaoInversor = Str(allow_none=True) tipoEstrutura = EnumField(TiposEstruturaEnum, by_value=True, allow_none=True) descricaoCompleta = Str(allow_none=True) @post_load def make_kit(self, data, **kwargs): return Kit(**data)
class PackageSwitchMinuteScheme(BaseModelScheme): package_switch_uuid = Str(validate=[validate.Length(max=36)]) package_name = Str(validate=[validate.Length(max=64)]) amount = Int() enabled = Bool() rate_per_minute = Float() class Meta: model = model.PackageSwitch fields = ('package_switch_uuid', 'package_name', 'amount', 'enabled', 'rate_per_minute')
class ExtractROISchema(Schema): """This ROI format is the expected input of AllenSDK's extract_traces 'rois' field """ id = Int(required=True, description=("Unique ID of the ROI, get's overwritten writting " "to LIMS")) x = Int(required=True, description="X location of top left corner of ROI in pixels") y = Int(required=True, description="Y location of top left corner of ROI in pixels") width = Int(required=True, description="Width of the ROI in pixels") height = Int(required=True, description="Height of the ROI in pixels") valid = Bool(required=True, description=("Boolean indicating if the ROI is a valid " "cell or not")) mask = List(List(Bool), required=True, description=("Bool nested list describing which pixels " "in the ROI area are part of the cell"))
class PointRegistrationSchema(Schema): date = Str( required=True, error_messages={'required': MSG_FIELD_REQUIRED} ) time = Str( required=True, error_messages={'required': MSG_FIELD_REQUIRED} ) rf = Int( required=True, error_messages={'required': MSG_FIELD_REQUIRED} )
def get(self, user_id): arg_fields = {'time_period_offset': Int(missing=0)} args = parser.parse(arg_fields) schedule_info = ScheduleDAO().get(user_id, time_period_offset=args.get( 'time_period_offset', 0)) logging.info( 'Succesfully retrieved all schedules for user {0}'.format(user_id)) return jsonify( {'schedules': ScheduleMarshal(many=True).dump(schedule_info).data})
class TransactionLogScheme(BaseModelScheme): transaction_log_uuid = Str(validate=[validate.Length(max=36)]) transaction_time = DateTime() license_lrn_uuid = Str(validate=[validate.Length(max=36)]) license_switch_uuid = Str(validate=[validate.Length(max=36)]) type = Int() amount_total = Float() amount_lrn = Float() amount_switch = Float() transaction_id = Str(validate=[validate.Length(max=255)]) transaction_type = Str(validate=[validate.Length(max=255)]) from_ip = Str(validate=[validate.Length(max=36)]) transaction_src = Dict() status = Int() result = Str() payment_uuid = Str(validate=[validate.Length(max=36)]) license_lrn_plan_name = Str() license_switch_plan_name = Str() user_uuid = Str() user_name = Str() class Meta: model = model.TransactionLog fields = ( 'transaction_time', 'license_lrn_uuid', 'license_switch_uuid', 'type', 'amount_total', 'amount_lrn', 'amount_switch', 'transaction_id', 'transaction_type', 'from_ip', 'transaction_src', 'status', 'result', 'payment_uuid', )
class DnlLicenseInfoScheme(BaseModelScheme): id = Int() carrier_name = Str(validate=[validate.Length(max=100)]) ss_type = Int() status = Int() ss_name = Str(validate=[validate.Length(max=100)]) uuid = Str(validate=[validate.Length(max=128)]) recv_ip = Str(validate=[validate.Length(max=16)]) recv_port = Int() ss_bind_mac = Str(validate=[validate.Length(max=18)]) ss_bind_ip = Str(validate=[validate.Length(max=16)]) ss_bind_port = Int() max_cap = Int() max_cps = Int() start_time = DateTime() end_time = DateTime() expires = Int() update_time = DateTime() create_time = DateTime() create_user = Int() class Meta: model = model.DnlLicenseInfo fields = ( 'carrier_name', 'ss_type', 'status', 'ss_name', 'uuid', 'recv_ip', 'recv_port', 'ss_bind_mac', 'ss_bind_ip', 'ss_bind_port', 'max_cap', 'max_cps', 'start_time', 'end_time', 'expires', 'update_time', 'create_time', 'create_user', )
class PointSchema(Schema): id = Str() date = Str( required=True, error_messages={'required': MSG_FIELD_REQUIRED} ) time = Str( required=True, error_messages={'required': MSG_FIELD_REQUIRED} ) rf = Int( required=True, error_messages={'required': MSG_FIELD_REQUIRED} )
class PackageLrnScheme(BaseModelScheme): package_lrn_uuid = Str(validate=[validate.Length(max=36)]) package_name = Str(validate=[validate.Length(max=64)]) cps = Int() type = Choice() lrn_port = Int() dip_count = Int() amount = Int() enabled = Bool() create_on = DateTime() licenses = Nested('LicenseLrnScheme', many=True) class Meta: model = model.PackageLrn fields = ( 'package_name', 'cps', 'type', 'lrn_port', 'dip_count', 'amount', 'enabled', )
class UserSchema(BaseModelSchema): """ User schema serializer. """ id = Int(dump_only=True) login = Str(required=True, validate=[validate.Length(min=4)]) name = Str(required=True, validate=[validate.Length(min=2)]) email = Email(required=True, validate=[validate.Length(min=5)]) created_at = DateTime(dump_only=True) updated_at = DateTime(dump_only=True) is_active = Boolean(required=True) is_admin = Boolean() class Meta(BaseModelSchema.Meta): model = User exclude = ("password", )
class ResourceSchema(ResourceMixin, Schema): mimetype = Str(allow_none=True) cache_last_updated = Str(allow_none=True) cache_url = Str(allow_none=True) created = DateTime() description = Str() hash = Str() ext_ident = Str(data_key='id', validate=validate.Length(max=36)) modified = DateTime(data_key='last_modified', allow_none=True) mimetype_inner = Str(allow_none=True) title = Str(data_key='name') format = Str() link = URL(data_key='url') datastore_active = Bool() package_id = UUID() position = Int() resource_type = Str(allow_none=True) revision_id = UUID() size = Str(allow_none=True) state = Str() url_type = Str(allow_none=True) class Meta: fields = ('created', 'modified', 'ext_ident', 'title', 'description', 'link', 'format') unknown = EXCLUDE def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) # TODO: Does it makes sense to validate format here? Disabled for now. self.format_validation = False @validates_schema def validate_format(self, data, **kwargs): value = data.get('format') if self.format_validation and value and value not in SUPPORTED_RESOURCE_FORMATS: error = _('Unsupported format: %(format)s.') % {'format': value} raise ValidationError(error, field_name='format') @pre_load def prepare_data(self, data, **kwargs): if 'format' in data: value = data['format'].lower() if value not in SUPPORTED_RESOURCE_FORMATS: value = '' data['format'] = value return data
class ProdutoSchema(Schema): codProduto = Int() nome = Str(required=True, error_messages={'required': MSG_FIELD_REQUIRED}) marca = Str(allow_none=True) potencia = Float(allow_none=True) custoMedioMensal = Float(allow_none=True) custoUltimaCompra = Float(allow_none=True) tipoProduto = EnumField(TiposProdutoEnum, by_value=True, allow_none=True) tipoModulo = EnumField(TiposModuloEnum, by_value=True, allow_none=True) tipoInversor = EnumField(TiposInversorEnum, by_value=True, allow_none=True) tipoEstrutura = EnumField(TiposEstruturaEnum, by_value=True, allow_none=True) @post_load def make_produto(self, data, **kwargs): return Produto(**data)
class CollaboratorRegistrationSchema(Schema): name = Str( required=True, error_messages={'required': MSG_FIELD_REQUIRED} ) email = Email( required=True, error_messages={'required': MSG_FIELD_REQUIRED} ) password = Str( required=True, error_messages={'required': MSG_FIELD_REQUIRED} ) rf = Int( required=True, error_messages={'required': MSG_FIELD_REQUIRED} )