NDOJ/judge/widgets/datetime.py

20 lines
623 B
Python
Raw Normal View History

from django import forms
2024-04-13 03:26:17 +00:00
from django.templatetags.static import static
from django.utils.html import format_html
from django.forms.utils import flatatt
class DateTimePickerWidget(forms.DateTimeInput):
2024-04-13 03:26:17 +00:00
input_type = "datetime-local"
2024-04-13 03:26:17 +00:00
def render(self, name, value, attrs=None, renderer=None):
if value is None:
value = ""
else:
value = value.strftime("%Y-%m-%dT%H:%M")
2024-04-13 03:26:17 +00:00
final_attrs = self.build_attrs(
attrs, {"type": self.input_type, "name": name, "value": value}
)
2024-04-13 03:26:17 +00:00
return format_html("<input{}>", flatatt(final_attrs))