From fb9bc019392fae3caa5415fa99c30d00ce184cb3 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Tue, 14 May 2024 12:17:50 -0500 Subject: [PATCH] Add `` component for oruga --- tailbone/forms/widgets.py | 10 +++ .../themes/butterball/field-components.mako | 66 +++++++++++++++++++ 2 files changed, 76 insertions(+) diff --git a/tailbone/forms/widgets.py b/tailbone/forms/widgets.py index 6b74798c..c0bb0b4d 100644 --- a/tailbone/forms/widgets.py +++ b/tailbone/forms/widgets.py @@ -27,6 +27,7 @@ Form Widgets import json import datetime import decimal +import re import colander from deform import widget as dfwidget @@ -249,6 +250,8 @@ class FalafelDateTimeWidget(dfwidget.DateTimeInputWidget): """ template = 'datetime_falafel' + new_pattern = re.compile(r'^\d\d?:\d\d:\d\d [AP]M$') + def serialize(self, field, cstruct, **kw): """ """ readonly = kw.get('readonly', self.readonly) @@ -260,6 +263,13 @@ class FalafelDateTimeWidget(dfwidget.DateTimeInputWidget): """ """ if pstruct == '': return colander.null + + # nb. we now allow '4:20:00 PM' on the widget side, but the + # true node needs it to be '16:20:00' instead + if self.new_pattern.match(pstruct['time']): + time = datetime.datetime.strptime(pstruct['time'], '%I:%M:%S %p') + pstruct['time'] = time.strftime('%H:%M:%S') + return pstruct diff --git a/tailbone/templates/themes/butterball/field-components.mako b/tailbone/templates/themes/butterball/field-components.mako index 8f9f884a..8c1d1d70 100644 --- a/tailbone/templates/themes/butterball/field-components.mako +++ b/tailbone/templates/themes/butterball/field-components.mako @@ -4,6 +4,7 @@ ${self.make_numeric_input_component()} ${self.make_tailbone_autocomplete_component()} ${self.make_tailbone_datepicker_component()} + ${self.make_tailbone_timepicker_component()} <%def name="make_numeric_input_component()"> @@ -461,3 +462,68 @@ + +<%def name="make_tailbone_timepicker_component()"> + <% request.register_component('tailbone-timepicker', 'TailboneTimepicker') %> + + +