mirror of
				https://github.com/ae-utbm/sith.git
				synced 2025-11-03 18:43:04 +00:00 
			
		
		
		
	* ruff: apply rule F * ruff: apply rule E * ruff: apply rule SIM * ruff: apply rule TCH * ruff: apply rule ERA * ruff: apply rule PLW * ruff: apply rule FLY * ruff: apply rule PERF * ruff: apply rules FURB & RUF
		
			
				
	
	
		
			42 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			42 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
from typing import Annotated
 | 
						|
 | 
						|
from ninja import ModelSchema, Schema
 | 
						|
from pydantic import Field, NonNegativeInt, PositiveInt, TypeAdapter
 | 
						|
from pydantic_extra_types.phone_numbers import PhoneNumber, PhoneNumberValidator
 | 
						|
 | 
						|
from counter.models import BillingInfo
 | 
						|
 | 
						|
 | 
						|
class PurchaseItemSchema(Schema):
 | 
						|
    product_id: NonNegativeInt = Field(alias="id")
 | 
						|
    name: str
 | 
						|
    unit_price: float
 | 
						|
    quantity: PositiveInt
 | 
						|
 | 
						|
 | 
						|
# The eboutic deals with data that is dict mixed with JSON.
 | 
						|
# Hence it would be a hassle to manage it with a proper Schema class,
 | 
						|
# and we use a TypeAdapter instead
 | 
						|
PurchaseItemList = TypeAdapter(list[PurchaseItemSchema])
 | 
						|
 | 
						|
 | 
						|
class BillingInfoSchema(ModelSchema):
 | 
						|
    class Meta:
 | 
						|
        model = BillingInfo
 | 
						|
        fields = [
 | 
						|
            "customer",
 | 
						|
            "first_name",
 | 
						|
            "last_name",
 | 
						|
            "address_1",
 | 
						|
            "address_2",
 | 
						|
            "zip_code",
 | 
						|
            "city",
 | 
						|
            "country",
 | 
						|
        ]
 | 
						|
        fields_optional = ["customer"]
 | 
						|
 | 
						|
    # for reasons described in the model, BillingInfo.phone_number
 | 
						|
    # in nullable, but null values shouldn't be actually allowed,
 | 
						|
    # so we force the field to be required
 | 
						|
    phone_number: Annotated[PhoneNumber, PhoneNumberValidator(default_region="FR")]
 |