Commit b6713cc9 authored by Kazuhiko Shiozaki's avatar Kazuhiko Shiozaki

Formulator: prepare DateTimeField's sub_form dynamically.

otherwise TALES in input_style does not work and changes in the original proxy field will not be reflected.
parent 57ace587
This diff is collapsed.
...@@ -1455,10 +1455,6 @@ class DateTimeWidget(Widget): ...@@ -1455,10 +1455,6 @@ class DateTimeWidget(Widget):
def render(self, field, key, value, REQUEST, render_prefix=None): def render(self, field, key, value, REQUEST, render_prefix=None):
use_ampm = field.get_value('ampm_time_style') use_ampm = field.get_value('ampm_time_style')
use_timezone = field.get_value('timezone_style') use_timezone = field.get_value('timezone_style')
# FIXME: backwards compatibility hack:
if not hasattr(field, 'sub_form'):
from StandardFields import create_datetime_text_sub_form
field.sub_form = create_datetime_text_sub_form()
# Is it still usefull to test the None value, # Is it still usefull to test the None value,
# as DateTimeField should be considerer as the other field # as DateTimeField should be considerer as the other field
......
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import unittest, re import unittest, re
from DateTime import DateTime
import Zope2 import Zope2
# XXX this does not work for zope2.x if x < 3 # XXX this does not work for zope2.x if x < 3
...@@ -120,14 +121,10 @@ class FormTestCase(unittest.TestCase): ...@@ -120,14 +121,10 @@ class FormTestCase(unittest.TestCase):
self.form.manage_addProduct['Formulator']\ self.form.manage_addProduct['Formulator']\
.manage_addField('date_time','Test Field','DateTimeField') .manage_addField('date_time','Test Field','DateTimeField')
field = self.form.date_time field = self.form.date_time
sub_form = field.sub_form field._edit({'timezone_style': 0})
if sub_form.has_field('timezone'): self.assertFalse('<select size="1" name="subfield_field_date_time_timezone" >' in field.render())
del sub_form.fields['timezone']
#now timezone is not presented
self.assertFalse(self.form.date_time.sub_form.has_field('timezone'))
field._edit({'timezone_style': 1}) field._edit({'timezone_style': 1})
#test if timezone's presented self.assertTrue('<select size="1" name="subfield_field_date_time_timezone" >' in field.render())
self.assertTrue(self.form.date_time.sub_form.has_field('timezone'))
def test_datetime_css_class_rendering(self): def test_datetime_css_class_rendering(self):
...@@ -177,6 +174,22 @@ class FormTestCase(unittest.TestCase): ...@@ -177,6 +174,22 @@ class FormTestCase(unittest.TestCase):
self.assertEqual(0, len(css_matches)) self.assertEqual(0, len(css_matches))
def test_datetime_number_style(self):
# test that a bug is fixed, which causing the css_class value
# not to be rendered
self.form.manage_addProduct['Formulator']\
.manage_addField('date_time','Test Field','DateTimeField')
field = self.form.date_time
field._edit({'input_style': 'number'})
self.assertTrue('<input name="subfield_field_date_time_year" value="" maxlength="4" type="number" size="4" min="0" max="9999" />' in field.render())
field._edit({'start_datetime': DateTime('1900/01/01'), 'end_datetime': None})
self.assertTrue('<input name="subfield_field_date_time_year" value="" maxlength="4" type="number" size="4" min="1900" max="9999" />' in field.render())
field._edit({'start_datetime': None, 'end_datetime': DateTime('2099/12/31')})
self.assertTrue('<input name="subfield_field_date_time_year" value="" maxlength="4" type="number" size="4" min="0" max="2099" />' in field.render())
field._edit({'start_datetime': DateTime('1900/01/01'), 'end_datetime': DateTime('2099/12/31')})
self.assertTrue('<input name="subfield_field_date_time_year" value="" maxlength="4" type="number" size="4" min="1900" max="2099" />' in field.render())
def test_suite(): def test_suite():
suite = unittest.TestSuite() suite = unittest.TestSuite()
......
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