class _Account(BaseModel): balance: condecimal(max_digits=10, decimal_places=2) # type: ignore person_id: int max_daily_withdrawal: condecimal(max_digits=10, decimal_places=2) = None # type: ignore is_active: Optional[StrictBool]
class Model(BaseModel): name: constr(max_length=150) category: int public: bool = True timezone: TzInfo date: DateModel mode: EventMode = EventMode.tickets class LocationModel(BaseModel): lat: float lng: float name: constr(max_length=63) location: LocationModel = None ticket_limit: PositiveInt = None price: condecimal(ge=1, max_digits=6, decimal_places=2) = None suggested_donation: condecimal(ge=1, max_digits=6, decimal_places=2) = None donation_target: condecimal(ge=0, max_digits=9, decimal_places=2) = None long_description: str short_description: str = None youtube_video_id: str = None description_image: str = None description_intro: str = None external_ticket_url: HttpUrl = None external_donation_url: HttpUrl = None @validator('public', pre=True) def none_bool(cls, v): return v or False
class Model(BaseModel): short_bytes: conbytes(min_length=2, max_length=10) strip_bytes: conbytes(strip_whitespace=True) short_str: constr(min_length=2, max_length=10) regex_str: constr(regex='apple (pie|tart|sandwich)') strip_str: constr(strip_whitespace=True) big_int: conint(gt=1000, lt=1024) mod_int: conint(multiple_of=5) pos_int: PositiveInt neg_int: NegativeInt big_float: confloat(gt=1000, lt=1024) unit_interval: confloat(ge=0, le=1) mod_float: confloat(multiple_of=0.5) pos_float: PositiveFloat neg_float: NegativeFloat short_list: conlist(int, min_items=1, max_items=4) decimal_positive: condecimal(gt=0) decimal_negative: condecimal(lt=0) decimal_max_digits_and_places: condecimal(max_digits=2, decimal_places=2) mod_decimal: condecimal(multiple_of=Decimal('0.25'))
class Model(BaseModel): cos_function: PyObject = None path_to_something: Path = None path_to_file: FilePath = None path_to_directory: DirectoryPath = None short_bytes: conbytes(min_length=2, max_length=10) = None strip_bytes: conbytes(strip_whitespace=True) short_str: constr(min_length=2, max_length=10) = None regex_str: constr(regex='apple (pie|tart|sandwich)') = None strip_str: constr(strip_whitespace=True) big_int: conint(gt=1000, lt=1024) = None mod_int: conint(multiple_of=5) = None pos_int: PositiveInt = None neg_int: NegativeInt = None big_float: confloat(gt=1000, lt=1024) = None unit_interval: confloat(ge=0, le=1) = None mod_float: confloat(multiple_of=0.5) = None pos_float: PositiveFloat = None neg_float: NegativeFloat = None email_address: EmailStr = None email_and_name: NameEmail = None url: UrlStr = None password: SecretStr = None password_bytes: SecretBytes = None db_name = 'foobar' db_user = '******' db_password: str = None db_host = 'localhost' db_port = '5432' db_driver = 'postgres' db_query: dict = None dsn: DSN = None decimal: Decimal = None decimal_positive: condecimal(gt=0) = None decimal_negative: condecimal(lt=0) = None decimal_max_digits_and_places: condecimal(max_digits=2, decimal_places=2) = None mod_decimal: condecimal(multiple_of=Decimal('0.25')) = None uuid_any: UUID = None uuid_v1: UUID1 = None uuid_v3: UUID3 = None uuid_v4: UUID4 = None uuid_v5: UUID5 = None ipvany: IPvAnyAddress = None ipv4: IPv4Address = None ipv6: IPv6Address = None ip_vany_network: IPvAnyNetwork = None ip_v4_network: IPv4Network = None ip_v6_network: IPv6Network = None ip_vany_interface: IPvAnyInterface = None ip_v4_interface: IPv4Interface = None ip_v6_interface: IPv6Interface = None
class ConstrainedNumbersModel(pydantic.BaseModel): conintt: pydantic.conint(gt=10, lt=100) coninte: pydantic.conint(ge=10, le=100) conintmul: pydantic.conint(ge=10, le=100, multiple_of=7) confloatt: pydantic.confloat(gt=10, lt=100) confloate: pydantic.confloat(ge=10, le=100) condecimalt: pydantic.condecimal(gt=10, lt=100) condecimale: pydantic.condecimal(ge=10, le=100)
class AddBalanceResponceShema(BaseModel): """ Responce for adding balance """ id: int username: str total: condecimal(max_digits=12, decimal_places=2) added: condecimal(max_digits=12, decimal_places=2) currency: str
class ConstrainedNumbersModel(pydantic.BaseModel): conintt: pydantic.conint(gt=10, lt=100) coninte: pydantic.conint(ge=10, le=100) conintmul: pydantic.conint(ge=10, le=100, multiple_of=7) confloatt: pydantic.confloat(gt=10, lt=100) confloate: pydantic.confloat(ge=10, le=100) confloatemul: pydantic.confloat(ge=10, le=100, multiple_of=4.2) confloattmul: pydantic.confloat(gt=10, lt=100, multiple_of=10) condecimalt: pydantic.condecimal(gt=10, lt=100) condecimale: pydantic.condecimal(ge=10, le=100) condecimaltplc: pydantic.condecimal(gt=10, lt=100, decimal_places=5) condecimaleplc: pydantic.condecimal(ge=10, le=100, decimal_places=2)
class Account(BaseModel): id: Optional[int] balance: condecimal(max_digits=10, decimal_places=2) # type: ignore max_daily_withdrawal: condecimal(max_digits=10, decimal_places=2) = None # type: ignore is_active: Optional[bool] created_at: datetime person_id: int class Config: orm_mode = True
class OrderInfo(ObjectValue): class StatusEnum(str, Enum): new = 'NEW' partially_filled = 'PARTIALLY_FILLED' filled = 'FILLED' canceled = 'CANCELED' pending_cancel = 'PENDING_CANCEL' rejected = 'REJECTED' expired = 'EXPIRED' status: StatusEnum price: condecimal(gt=0) cummulative_quote_quantity: condecimal(ge=0) executed_quantity: condecimal(ge=0)
class DieCutCreateSchema(BaseModel): cut_name: str = Field(..., example='Ex_cut') zub_num: int = Field(..., example='80') vsheet: int = Field(..., example='200') hcountitem: int = Field(..., example='4') vcountitem: int = Field(..., example='5') hgap: condecimal(max_digits=10, decimal_places=4) = Field(..., example='3.3567') vgap: condecimal(max_digits=10, decimal_places=4) = Field(..., example='3.456') cf2: str = Field(None, example='ex_cut.cf2') mfg: str = Field(None, example='ex_cut.mfg') pict: str = Field(None, example='ex_cut.png') descript: str = Field(None, example='описание к штампу')
class UpdateVenueStockBodyModel(BaseModel): """Available stock quantity for a book""" ref: str = Field(title="ISBN", description="Format: EAN13") available: NonNegativeInt price: condecimal(decimal_places=2) = Field( None, description="(Optionnel) Prix en Euros avec 2 décimales possibles") @validator("price", pre=True) def empty_string_price_casted_to_none(cls, v): # pylint: disable=no-self-argument # Performed before Pydantic validators to catch empty strings but will not get "0" if not v: return None return v @validator("price") def zero_price_casted_to_none(cls, v): # pylint: disable=no-self-argument # Performed before Pydantic validators to catch empty strings but will not get "0" if not v: return None return v class Config: title = "Stock"
class WalletEntity(BaseModel): """Representation of wallet entity.""" id: int user_id: int balance: condecimal(ge=0) # type: ignore currency: CurrencyEnum
class OrderItemBase(BaseSchema): order_uid: Optional[UID] = None catalog_item_uid: Optional[UID] = None quantity: Optional[conint(ge=0)] = 1 base_price: Optional[condecimal(max_digits=10, decimal_places=2, ge=Decimal(0.0))] = None
class EntryCreate(NoExtraModel): account_id: int value: condecimal(decimal_places=10) asset_id: int quantity: condecimal(decimal_places=10) @validator("value") def value_should_be_not_zero(cls, value): if value == 0: raise ValueError("Value should be not zero") return value @validator("quantity") def quantity_should_be_not_zero(cls, quantity): if quantity == 0: raise ValueError("Quantity should be not zero") return quantity
class TransferBalanceResponceShema(BaseModel): """ Responce for money transfer """ id: int recipient_balance: int amount: condecimal(max_digits=12, decimal_places=2) currency: str
class WalletOperationEntity(BaseModel): """Represents entity for wallet operations""" id: int operation: Operations wallet_from: int wallet_to: int amount: condecimal(ge=0) # type: ignore
class Model(BaseModel): category: int name: constr(max_length=255) amount: condecimal(ge=1, max_digits=6, decimal_places=2) live: bool = True short_description: str long_description: str sort_index: int = None
class LimitOrder(Order): price: condecimal(gt=0) quantity: condecimal(gt=0) @root_validator(allow_reuse=True) def attribute_validation(cls, values: dict) -> dict: validated_values = cls._validate_price(values, 'price') validated_values = cls._validate_qty(validated_values) return validated_values @staticmethod def _validate_price(values: dict, price_attr_name: str): if not (price := values.get(price_attr_name)): raise ValueError("Price attribute is required.") if not (symbol := values.get('symbol')): raise ValueError("Symbol attribute is required.")
class Transaction(TransactionCreate): id: int entries: list[Entry] timestamp: dt.datetime datetime: dt.datetime value: condecimal(decimal_places=10) cancel: bool fund_id: int
class OperationShema(BaseModel): """Схема для одной операции""" id: int created: datetime operation_type: OperationsTypeType amount: condecimal(max_digits=12, decimal_places=2) owner_balance_id: int more_balance_id: int
class OCOOrder(StopLimitOrder): stop_limit_price: condecimal(gt=0) @root_validator(allow_reuse=True) def attribute_validation(cls, values: dict) -> dict: validated_values = super().attribute_validation(values) validated_values = cls._validate_price(validated_values, 'stop_limit_price') return validated_values
class BalanceSchema(BaseModel): """ Model for balance """ id: int username: str is_active: bool amount: condecimal(max_digits=12, decimal_places=2) currency: str
def test_pydantic_condecimal_field(self, normalize_sdl): value = pydantic2graphene.to_graphene( to_pydantic_class(pydantic.condecimal())) expected_value = """ type FakeGql { field: Float! } """ assert normalize_sdl(value) == normalize_sdl(expected_value)
class Model(BaseModel): cos_function: PyObject = None path_to_something: Path = None path_to_file: FilePath = None path_to_directory: DirectoryPath = None short_str: constr(min_length=2, max_length=10) = None regex_str: constr(regex='apple (pie|tart|sandwich)') = None strip_str: constr(strip_whitespace=True) big_int: conint(gt=1000, lt=1024) = None pos_int: PositiveInt = None neg_int: NegativeInt = None big_float: confloat(gt=1000, lt=1024) = None unit_interval: confloat(ge=0, le=1) = None pos_float: PositiveFloat = None neg_float: NegativeFloat = None email_address: EmailStr = None email_and_name: NameEmail = None url: UrlStr = None db_name = 'foobar' db_user = '******' db_password: str = None db_host = 'localhost' db_port = '5432' db_driver = 'postgres' db_query: dict = None dsn: DSN = None decimal: Decimal = None decimal_positive: condecimal(gt=0) = None decimal_negative: condecimal(lt=0) = None decimal_max_digits_and_places: condecimal(max_digits=2, decimal_places=2) = None uuid_any: UUID = None uuid_v1: UUID1 = None uuid_v3: UUID3 = None uuid_v4: UUID4 = None uuid_v5: UUID5 = None
class Transaction(BaseModel): id: Optional[int] value: condecimal(max_digits=10, decimal_places=2) = None # type: ignore processed_at: datetime account_id: int account: Optional[Account] class Config: orm_mode = True
class Model(BaseModel): name: str live: bool = True description: constr(max_length=140) = None sort_index: int = 1 suggested_price: condecimal(ge=1, max_digits=6, decimal_places=2) = None event_content: str = None host_advice: str = None booking_trust_message: str = None cover_costs_message: str = None cover_costs_percentage: condecimal(ge=0, le=100, max_digits=5, decimal_places=2) = None terms_and_conditions_message: str = None allow_marketing_message: str = None post_booking_message: str = None ticket_extra_title: constr(max_length=140) = None ticket_extra_help_text: str = None
class DieCutSchema(BaseModel): cut_name: str = Field(..., example='Ex_cut') @validator('cut_name') def cut_name_must_upper(cls, v): if v.isupper(): return v.upper() return v.upper() zub_num: int = Field(..., example='80') vsheet: int = Field(..., example='200') hcountitem: int = Field(..., example='4') vcountitem: int = Field(..., example='5') hgap: condecimal(max_digits=10, decimal_places=4) = Field(..., example='3.3567') vgap: condecimal(max_digits=10, decimal_places=4) = Field(..., example='3.456') cf2: str = Field(None, example='ex_cut.cf2') mfg: str = Field(None, example='ex_cut.mfg') pict: str = Field(None, example='ex_cut.png') descript: str = Field(None, example='описание к штампу')
class MarketOrder(Order): total: condecimal(gt=0) = None @root_validator def attribute_validation(cls, values: dict) -> dict: """ `total` checked against the MARKET_LOT_SIZE_FILTER. """ if not (total := values.get('total')): raise ValueError("Total attribute is required.") if not (symbol := values.get('symbol')): raise ValueError("Symbol attribute is required.")
class Transaction(BaseModel): id: uuid.UUID account: Account timestamp: datetime.datetime amount: condecimal(gt=Decimal('0'), decimal_places=2) currency: str direction: str type: str category: Category = None vat_rate: str = None attachments: List[Attachment] = None
class CalcParams(BaseModel): count: conint(gt=0) price: condecimal(gt=Decimal(0)) state: States @property def discount(self): amount = self.price * self.count for discount_price, discount_pct in DISCOUNTS.items(): if amount >= discount_price: return discount_pct return 0 @property def tax(self): return TAXES[self.state]