From a3ed93c1542a3def622c9578085efcc60c338b39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Kucharczyk?= Date: Sat, 9 Nov 2024 21:28:52 +0000 Subject: [PATCH] handle non-existent icons --- common/components.py | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/common/components.py b/common/components.py index f16e0ba..9d7e276 100644 --- a/common/components.py +++ b/common/components.py @@ -2,6 +2,7 @@ from random import choices as random_choices from string import ascii_lowercase from typing import Any, Callable +from django.template import TemplateDoesNotExist from django.template.loader import render_to_string from django.urls import NoReverseMatch, reverse from django.utils.safestring import SafeText, mark_safe @@ -124,11 +125,38 @@ def Div( return Component(tag_name="div", attributes=attributes, children=children) +def Input( + type: str = "text", + attributes: list[HTMLAttribute] = [], + children: list[HTMLTag] | HTMLTag = [], +): + return Component( + tag_name="input", attributes=attributes + [("type", type)], children=children + ) + + +def Form( + action="", + method="get", + attributes: list[HTMLAttribute] = [], + children: list[HTMLTag] | HTMLTag = [], +): + return Component( + tag_name="form", + attributes=attributes + [("action", action), ("method", method)], + children=children, + ) + + def Icon( name: str, attributes: list[HTMLAttribute] = [], ): - return Component(template=f"cotton/icon/{name}.html", attributes=attributes) + try: + result = Component(template=f"cotton/icon/{name}.html", attributes=attributes) + except TemplateDoesNotExist: + result = Icon(name="unspecified", attributes=attributes) + return result def LinkedNameWithPlatformIcon(name: str, game_id: int, platform: str) -> SafeText: