55 lines
1.4 KiB
Python
55 lines
1.4 KiB
Python
import uuid
|
|
|
|
from datetime import date, datetime
|
|
from typing import Optional
|
|
|
|
from luthor.schemas.court_status import CourtStatusLink
|
|
from pydantic import BaseModel, Field, validator
|
|
|
|
from . import to_camel
|
|
|
|
|
|
class HearingIn(BaseModel):
|
|
court_number: str
|
|
item_number: str
|
|
bench: str
|
|
proceedings: str
|
|
compliance_date: Optional[date]
|
|
next_hearing_date: date
|
|
court_status: Optional[CourtStatusLink]
|
|
|
|
class Config:
|
|
anystr_strip_whitespace = True
|
|
alias_generator = to_camel
|
|
json_encoders = {datetime: lambda v: v.strftime("%d-%b-%Y %H:%M"), date: lambda v: v.strftime("%d-%b-%Y")}
|
|
|
|
@validator("compliance_date", pre=True)
|
|
def parse_compliance_date(cls, value):
|
|
if isinstance(value, date):
|
|
return value
|
|
if value is None:
|
|
return None
|
|
return datetime.strptime(value, "%d-%b-%Y").date()
|
|
|
|
@validator("next_hearing_date", pre=True)
|
|
def parse_next_hearing_date(cls, value):
|
|
if isinstance(value, date):
|
|
return value
|
|
return datetime.strptime(value, "%d-%b-%Y").date()
|
|
|
|
|
|
class Hearing(HearingIn):
|
|
id_: Optional[uuid.UUID]
|
|
|
|
class Config:
|
|
anystr_strip_whitespace = True
|
|
alias_generator = to_camel
|
|
json_encoders = {datetime: lambda v: v.strftime("%d-%b-%Y %H:%M"), date: lambda v: v.strftime("%d-%b-%Y")}
|
|
|
|
|
|
class HearingLink(BaseModel):
|
|
id_: uuid.UUID = Field(...)
|
|
|
|
class Config:
|
|
fields = {"id_": "id"}
|