From 0d2ffcecb385870071e25801248a5e75303bbf6b Mon Sep 17 00:00:00 2001 From: Kevin Deldycke <kevin@nexedi.com> Date: Wed, 8 Mar 2006 16:35:59 +0000 Subject: [PATCH] Set a default output format. git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@6045 20353a03-c40f-0410-a6d1-a30d3c3de9de --- product/ERP5Form/FormulatorPatch.py | 35 +++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/product/ERP5Form/FormulatorPatch.py b/product/ERP5Form/FormulatorPatch.py index e55941c585..07cf1c832f 100755 --- a/product/ERP5Form/FormulatorPatch.py +++ b/product/ERP5Form/FormulatorPatch.py @@ -643,6 +643,41 @@ class PatchedDateTimeWidget(DateTimeWidget): else: return date_result + def render_view(self, field, value): + if value is None: + return '' + + use_ampm = field.get_value('ampm_time_style') + + year = "%04d" % value.year() + month = "%02d" % value.month() + day = "%02d" % value.day() + if use_ampm: + hour = "%02d" % value.h_12() + else: + hour = "%02d" % value.hour() + minute = "%02d" % value.minute() + ampm = value.ampm() + + order = field.get_value('input_order') + if order == 'ymd': + output = [year, month, day] + elif order == 'dmy': + output = [day, month, year] + elif order == 'mdy': + output = [month, day, year] + else: + output = [year, month, day] + date_result = string.join(output, field.get_value('date_separator')) + + if not field.get_value('date_only'): + time_result = hour + field.get_value('time_separator') + minute + if use_ampm: + time_result += ' ' + ampm + return date_result + ' ' + time_result + else: + return date_result + DateTimeField.widget = PatchedDateTimeWidget() from Products.Formulator.Validator import DateTimeValidator, ValidationError, DateTime -- 2.30.9