diff --git a/app/domain/calculator/controllers/calculator.py b/app/domain/calculator/controllers/calculator.py index e038da8..d538b73 100644 --- a/app/domain/calculator/controllers/calculator.py +++ b/app/domain/calculator/controllers/calculator.py @@ -82,6 +82,6 @@ async def ip( return HTMXTemplate( template_name="partial.html", - context=network_info.dict(), # Convert the pydantic model to a dict + context={"network_info": network_info.model_dump(by_alias=True)}, push_url=False, ) diff --git a/app/domain/calculator/schema.py b/app/domain/calculator/schema.py index fc410be..dfbcaa6 100644 --- a/app/domain/calculator/schema.py +++ b/app/domain/calculator/schema.py @@ -39,6 +39,7 @@ class NetworkInfo(BaseModel): ..., description="The subnet mask in standard IPv4 format.", pattern=r"^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$", + serialization_alias="Subnet Mask", ), ] wildcard_subnet_mask: Annotated[ @@ -47,21 +48,48 @@ class NetworkInfo(BaseModel): ..., description="The wildcard subnet mask in standard IPv4 format.", pattern=r"^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$", + serialization_alias="Wildcard Subnet Mask", ), ] - total_ips: Annotated[int, Field(..., description="The total number of IPs in the network.")] - usable_ips: Annotated[int, Field(..., description="The total number of usable IPs in the network.")] + total_ips: Annotated[ + int, Field(..., description="The total number of IPs in the network.", serialization_alias="Total IPs") + ] + usable_ips: Annotated[ + int, Field(..., description="The total number of usable IPs in the network.", serialization_alias="Usable IPs") + ] network_ip: Annotated[ str, - Field(..., description="The network IP in standard IPv4 format.", pattern=r"^(?:[0-9]{1,3}\.){3}[0-9]{1,3}$"), + Field( + ..., + description="The network IP in standard IPv4 format.", + pattern=r"^(?:[0-9]{1,3}\.){3}[0-9]{1,3}$", + serialization_alias="Network IP", + ), ] broadcast_ip: Annotated[ str, - Field(..., description="The broadcast IP in standard IPv4 format.", pattern=r"^(?:[0-9]{1,3}\.){3}[0-9]{1,3}$"), + Field( + ..., + description="The broadcast IP in standard IPv4 format.", + pattern=r"^(?:[0-9]{1,3}\.){3}[0-9]{1,3}$", + serialization_alias="Broadcast IP", + ), ] first_ip: Annotated[ - str, Field(..., description="The first IP in standard IPv4 format.", pattern=r"^(?:[0-9]{1,3}\.){3}[0-9]{1,3}$") + str, + Field( + ..., + description="The first IP in standard IPv4 format.", + pattern=r"^(?:[0-9]{1,3}\.){3}[0-9]{1,3}$", + serialization_alias="First IP", + ), ] last_ip: Annotated[ - str, Field(..., description="The last IP in standard IPv4 format.", pattern=r"^(?:[0-9]{1,3}\.){3}[0-9]{1,3}$") + str, + Field( + ..., + description="The last IP in standard IPv4 format.", + pattern=r"^(?:[0-9]{1,3}\.){3}[0-9]{1,3}$", + serialization_alias="Last IP", + ), ] diff --git a/app/domain/web/templates/partial.html b/app/domain/web/templates/partial.html index 35e1da3..40d4449 100644 --- a/app/domain/web/templates/partial.html +++ b/app/domain/web/templates/partial.html @@ -16,85 +16,17 @@ + {% for key, value in network_info.items() %} - Subnet Mask + {{ key }} - {{ subnet_mask }} - - - - - Wildcard Subnet Mask - - - {{ wildcard_subnet_mask }} - - - - - Total IPs - - - {{ total_ips }} - - - - - Usable IPs - - - {{ usable_ips }} - - - - - Network IP - - - {{ network_ip }} - - - - - Broadcast IP - - - {{ broadcast_ip }} - - - - - First IP - - - {{ first_ip }} - - - - - Last IP - - - {{ last_ip }} + {{ value }} + {% endfor %}