Skip to content

Commit

Permalink
Enhancement: Utilize Jinja loops to clean up partial.html
Browse files Browse the repository at this point in the history
  • Loading branch information
Alc-Alc committed Oct 11, 2023
1 parent 9bbecdb commit b42651a
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 79 deletions.
2 changes: 1 addition & 1 deletion app/domain/calculator/controllers/calculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
40 changes: 34 additions & 6 deletions app/domain/calculator/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -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[
Expand All @@ -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",
),
]
76 changes: 4 additions & 72 deletions app/domain/web/templates/partial.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,85 +16,17 @@
</tr>
</thead>
<tbody>
{% for key, value in network_info.items() %}
<tr class="hover:bg-neutral-900/40">
<td
class="relative py-4 pl-4 pr-3 text-sm sm:pl-6 font-medium text-gray-900 dark:text-neutral-200"
>
Subnet Mask
{{ key }}
</td>
<td class="px-3 py-3.5 text-sm text-gray-500 dark:text-gray-400">
{{ subnet_mask }}
</td>
</tr>
<tr class="hover:bg-neutral-900/40">
<td
class="relative py-4 pl-4 pr-3 text-sm sm:pl-6 font-medium text-gray-900 dark:text-neutral-200"
>
Wildcard Subnet Mask
</td>
<td class="px-3 py-3.5 text-sm text-gray-500 dark:text-gray-400">
{{ wildcard_subnet_mask }}
</td>
</tr>
<tr class="hover:bg-neutral-900/40">
<td
class="relative py-4 pl-4 pr-3 text-sm sm:pl-6 font-medium text-gray-900 dark:text-neutral-200"
>
Total IPs
</td>
<td class="px-3 py-3.5 text-sm text-gray-500 dark:text-gray-400">
{{ total_ips }}
</td>
</tr>
<tr class="hover:bg-neutral-900/40">
<td
class="relative py-4 pl-4 pr-3 text-sm sm:pl-6 font-medium text-gray-900 dark:text-neutral-200"
>
Usable IPs
</td>
<td class="px-3 py-3.5 text-sm text-gray-500 dark:text-gray-400">
{{ usable_ips }}
</td>
</tr>
<tr class="hover:bg-neutral-900/40">
<td
class="relative py-4 pl-4 pr-3 text-sm sm:pl-6 font-medium text-gray-900 dark:text-neutral-200"
>
Network IP
</td>
<td class="px-3 py-3.5 text-sm text-gray-500 dark:text-gray-400">
{{ network_ip }}
</td>
</tr>
<tr class="hover:bg-neutral-900/40">
<td
class="relative py-4 pl-4 pr-3 text-sm sm:pl-6 font-medium text-gray-900 dark:text-neutral-200"
>
Broadcast IP
</td>
<td class="px-3 py-3.5 text-sm text-gray-500 dark:text-gray-400">
{{ broadcast_ip }}
</td>
</tr>
<tr class="hover:bg-neutral-900/40">
<td
class="relative py-4 pl-4 pr-3 text-sm sm:pl-6 font-medium text-gray-900 dark:text-neutral-200"
>
First IP
</td>
<td class="px-3 py-3.5 text-sm text-gray-500 dark:text-gray-400">
{{ first_ip }}
</td>
</tr>
<tr class="hover:bg-neutral-900/40">
<td
class="relative py-4 pl-4 pr-3 text-sm sm:pl-6 font-medium text-gray-900 dark:text-neutral-200"
>
Last IP
</td>
<td class="px-3 py-3.5 text-sm text-gray-500 dark:text-gray-400">
{{ last_ip }}
{{ value }}
</td>
</tr>
{% endfor %}
</tbody>
</table>

0 comments on commit b42651a

Please sign in to comment.