Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancement: Utilize Jinja loops to clean up partial.html #22

Merged
merged 1 commit into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>