Commit 5256e4da authored by Romain Courteaud's avatar Romain Courteaud

Change rendering of duration: it's better inline.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@13295 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent efef67ae
......@@ -41,7 +41,7 @@ MINUTE_IN_SECOND = 60
HOUR_IN_SECOND = 3600
# DAY_IN_SECOND = 86400
class DurationWidget(FormulatorPatch.FloatWidget):
class DurationWidget(FormulatorPatch.IntegerWidget):
"""
Duration Widget is used to enter time duration.
It may be used in movement of Labour (in Task, Calendat Period, ...).
......@@ -51,7 +51,7 @@ class DurationWidget(FormulatorPatch.FloatWidget):
The field purpose is to display second quantity in hour, minute and second,
in order to make it more readable.
"""
def render_htmlgrid(self, field, key, value, REQUEST):
def render_view(self, field, value):
sub_field_render_list = []
for title, sub_key, convertion in (('Hour', 'hour', HOUR_IN_SECOND),
('Minute', 'minute', MINUTE_IN_SECOND)):
......@@ -59,27 +59,40 @@ class DurationWidget(FormulatorPatch.FloatWidget):
sub_value = ''
else:
sub_value, value = divmod(value, convertion)
sub_field_render_list.append((title, self.render_sub_field(
sub_field_render_list.append(str(sub_value))
# Render second
sub_field_render_list.append(str(value))
return ':'.join(sub_field_render_list)
def render(self, field, key, value, REQUEST):
sub_field_render_list = []
for title, sub_key, convertion in (('Hour', 'hour', HOUR_IN_SECOND),
('Minute', 'minute', MINUTE_IN_SECOND)):
if value == '':
sub_value = ''
else:
sub_value, value = divmod(value, convertion)
sub_field_render_list.append(self.render_sub_field(
field, key,
sub_value, REQUEST, sub_key)))
sub_value, REQUEST, sub_key))
# Render second
sub_field_render_list.append(('Second', self.render_sub_field(
sub_field_render_list.append(self.render_sub_field(
field, key,
value, REQUEST, 'second')))
return sub_field_render_list
value, REQUEST, 'second'))
return ':'.join(sub_field_render_list)
def render_sub_field(self, field, key, value, REQUEST, keyword):
"""
Render dynamically a subfield
"""
return FormulatorPatch.FloatWidgetInstance.render(
return FormulatorPatch.IntegerFieldWidgetInstance.render(
field,
field.generate_subfield_key(keyword,
key=key),
value,
REQUEST)
class DurationValidator(Validator.FloatValidator):
class DurationValidator(Validator.IntegerValidator):
"""
Duration Validator
"""
......@@ -98,7 +111,7 @@ class DurationValidator(Validator.FloatValidator):
"""
Validates a subfield (as part of field validation).
"""
sub_field_value = Validator.FloatValidatorInstance.validate(
sub_field_value = Validator.IntegerValidatorInstance.validate(
field,
field.generate_subfield_key(
sub_key,
......@@ -112,17 +125,6 @@ class DurationValidator(Validator.FloatValidator):
second_value = sub_field_value * convertion
return second_value
def render_htmlgrid(self, value=None, REQUEST=None, key=None):
"""
render_htmlgrid returns a list of tuple (title, html render)
We will use title generated by the widget.
"""
key = self.generate_field_key(key=key)
value = self._get_default(key, value, REQUEST)
html = self.widget.render_htmlgrid(self, key, value, REQUEST)
return html
DurationWidgetInstance = DurationWidget()
DurationFieldValidatorInstance = DurationValidator()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment