class CryptoCurrencyMetaSchema(Schema): id = fields.Str() type = fields.Str() exchange = fields.Str() code = fields.Str() name = fields.Str() listDate = Date()
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 BillSchema(ModelSchema): place = String(required=True, validate=not_blank) billed_at = Date(required=True) wallet_uid = UUID(required=True, allow_none=False) items = Nested( BillItemSchema, many=True, only=("uid", "name", "quantity", "value", "group_uid"), ) @pre_dump def make_dict(self, obj): return dict( uid=obj.uid, place=obj.place, billed_at=_to_date(obj.billed_at), wallet_uid=obj.wallet_uid, items=[item for item in obj.items], ) @post_load def make_model(self, data): return Bill( uid=data.get("uid"), place=data.get("place"), billed_at=data.get("billed_at"), wallet_uid=data.get("wallet_uid"), items=[item for item in data.get("items", [])], total=data.get("total"), )
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')
class UserUpdateSchema(Schema): full_name = Str() user_name = Str() email = Email() date_of_born = Date() address = Nested(AddressSchema) phone = Str() admin = Boolean() active = Boolean()
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 UserSchema(Schema): id = Integer(dump_only=True) first_name = String(required=True, validate=Length(1, 64)) last_name = String(required=True, validate=Length(1, 64)) birth_date = Date(required=True) email = Email(required=True) password = String(required=True, validate=Length(5, 32), load_only=True) created_at = DateTime(dump_only=True) updated_at = DateTime(dump_only=True) deleted_at = DateTime(dump_only=True)
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 UserSchema(Schema): full_name = Str(required=True, error_messages={"required": MSG_FIELD_REQUIRED}) user_name = Str(required=True, error_messages={"required": MSG_FIELD_REQUIRED}) email = Email(required=True, error_messages={"required": MSG_FIELD_REQUIRED}) date_of_born = Date() address = Nested(AddressSchema) phone = Str() admin = Boolean() active = Boolean()
class Motherboard(Component): __doc__ = m.Motherboard.__doc__ slots = Integer(validate=Range(0, 20), description=m.Motherboard.slots.comment) usb = Integer(validate=Range(0, 20), description=m.Motherboard.usb.comment) firewire = Integer(validate=Range(0, 20), description=m.Motherboard.firewire.comment) serial = Integer(validate=Range(0, 20), description=m.Motherboard.serial.comment) pcmcia = Integer(validate=Range(0, 20), description=m.Motherboard.pcmcia.comment) bios_date = Date(validate=Range(datetime.date(year=1980, month=1, day=1), datetime.date(year=2030, month=1, day=1)), data_key='biosDate', description=m.Motherboard.bios_date) ram_slots = Integer(validate=Range(1), data_key='ramSlots') ram_max_size = Integer(validate=Range(1), data_key='ramMaxSize')
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 BillSummarySchema(ModelSchema): place = String(required=True, validate=not_blank) billed_at = Date(required=True) wallet_uid = UUID(required=True, allow_none=False) items = Nested( BillItemSchema, many=True, only=("uid", "name", "quantity", "value", "group_uid"), ) total = Decimal(as_string=True, required=False, places=2, allow_none=True) @pre_dump def make_dict(self, obj): return dict( uid=obj.uid, place=obj.place, billed_at=_to_date(obj.billed_at), wallet_uid=obj.wallet_uid, total=obj.total, )
class PredictRequestSchema(Schema): date = Date(required=True) # '2018-09-15', cnt_rooms = Integer(validate=[Range(min=1)], required=True) # 1, flat_area = Float(validate=[Range(min=0)], required=True) # 36.0, rent_base = Float(validate=[Range(min=0)], required=True) # 530.0, rent_total = Float(validate=[Range(min=0)], required=True) # 650.0, flat_type = String(validate=OneOf(FLAT_TYPE_OPTIONS), required=True) # 'apartment', flat_interior_quality = String(validate=OneOf(FLAT_INTERIOR_QUALITY_OPTIONS), required=True) # 'average', flat_condition = String(validate=OneOf(FLAT_CONDITION_OPTIONS), required=True) # 'good', flat_age = String(validate=OneOf(FLAT_AGE_OPTIONS), required=True) # '60+', flat_thermal_characteristic = Float(validate=[Range(min=0)], required=True) # nan, has_elevator = String(validate=OneOf(['t', 'f']), required=True) # 'f', has_balcony = String(validate=OneOf(['t', 'f']), required=True) # 't', has_garden = String(validate=OneOf(['t', 'f']), required=True) # 't', has_kitchen = String(validate=OneOf(['t', 'f']), required=True) # 't', has_guesttoilet = String(validate=OneOf(['t', 'f']), required=True) # 'f', geo_city = String(validate=OneOf(['hamburg']), required=True) # 'hamburg', geo_city_part = String(validate=OneOf(GEO_CITY_PART_OPTIONS), required=True) # 'wandsbek' @validates_schema def validate_numbers(self, data, **kwargs): if data["rent_base"] > data["rent_total"]: raise ValidationError("rent_base must be greater than rent_total")
class AulaModel(Schema): id = Integer(primary_key=True, default=PK_DEFAULT_VALUE) dia = Date(required=True) aluno = Nested(AlunoModel) curso = Nested(CursoModel) presente = Boolean()
# -*- coding: utf-8 -*- """Console script for mac_data.""" import sys import click import itertools as it import logging import mac_data from mac_data.support import date_range from mac_data.api_keys import get_api_key from mac_data import output from mac_data.data_sources import weather_underground as wu from marshmallow.fields import Date log = logging.getLogger(__name__) date_t = Date().deserialize def _log_level_from_verbosity(v): return { 0: logging.WARNING, 1: logging.INFO, 2: logging.DEBUG }.get(v, logging.DEBUG) @click.group() @click.pass_context @click.version_option(mac_data.__version__) @click.option('--key-file', default='api_keys.ini',
class _Schema(Schema): _key = String(required=True) name = String(required=True, allow_none=False) dob = Date()
class ClientRequest(BaseSchema): name = String(required=True, validate=Length(min=1, error="Field cannot be empty.")) address = String(required=True, validate=Length(min=1, error="Field cannot be empty.")) dob = Date(required=True)
class CardRequest(BaseSchema): number = String(required=True, validate=Length(equal=16, error="Not a valid card number.")) expiration_date = Date(required=True)