Example #1
0
class DatetimeWidgetTests(unittest.TestCase):

    def setUp(self):
        from plone.app.widgets.at import DatetimeWidget
        self.request = TestRequest(environ={'HTTP_ACCEPT_LANGUAGE': 'en'})
        self.context = mock.Mock()
        self.field = mock.Mock()
        self.field.getAccessor.return_value = lambda: u''
        self.field.getName.return_value = 'fieldname'
        self.widget = DatetimeWidget()

    def test_widget(self):
        self.assertEqual(
            {
                'pattern': 'pickadate',
                'value': u'',
                'name': 'fieldname',
                'pattern_options': {
                    'date': {
                        'min': [1913, 1, 1],
                        'max': [2033, 1, 1],
                        'clear': u'Clear',
                        'format': 'mmmm d, yyyy',
                        'monthsFull': [u'January', u'February', u'March',
                                       u'April', u'May', u'June', u'July',
                                       u'August', u'September', u'October',
                                       u'November', u'December'],
                        'weekdaysShort': [u'Sun', u'Mon', u'Tue', u'Wed',
                                          u'Thu', u'Fri', u'Sat'],
                        'weekdaysFull': [u'Sunday', u'Monday', u'Tuesday',
                                         u'Wednesday', u'Thursday', u'Friday',
                                         u'Saturday'],
                        'today': u'Today',
                        'selectYears': 200,
                        'placeholder': u'Enter date...',
                        'monthsShort': [u'Jan', u'Feb', u'Mar', u'Apr', u'May',
                                        u'Jun', u'Jul', u'Aug', u'Sep', u'Oct',
                                        u'Nov', u'Dec']
                    },
                    'time': {
                        'placeholder': u'Enter time...',
                        'today': u'Today',
                        'format': 'h:i a'
                    }
                }
            },
            self.widget._base_args(self.context, self.field, self.request),
        )

    def test_process_form(self):
        form = {
            'fieldname': '2011-11-22 13:30',
        }
        self.assertEqual(
            self.widget.process_form(
                self.context, self.field, form)[0].asdatetime(),
            (datetime(2011, 11, 22, 13, 30))
        )
Example #2
0
 def setUp(self):
     from plone.app.widgets.at import DatetimeWidget
     self.request = TestRequest(environ={'HTTP_ACCEPT_LANGUAGE': 'en'})
     self.context = Mock()
     self.field = Mock()
     self.field.getAccessor.return_value = lambda: DateTime(
         '2013-11-13 10:20 Europe/Amsterdam')
     self.field.getName.return_value = 'fieldname'
     self.widget = DatetimeWidget()
Example #3
0
    def test_localization(self):
        from plone.app.widgets.base import DatetimeWidget
        request_en = TestRequest(environ={'HTTP_ACCEPT_LANGUAGE': 'en'})
        widget_en = DatetimeWidget(request=request_en)
        self.assertEqual(
            widget_en.render(),
            '<input class="pat-pickadate" type="datetime-local" data-pat-pickadate="{&quot;date&quot;: {&quot;format&quot;: &quot;mmmm d, yyyy&quot;, &quot;max&quot;: [2033, 1, 1], &quot;clear&quot;: &quot;Clear&quot;, &quot;min&quot;: [1913, 1, 1], &quot;monthsFull&quot;: [&quot;January&quot;, &quot;February&quot;, &quot;March&quot;, &quot;April&quot;, &quot;May&quot;, &quot;June&quot;, &quot;July&quot;, &quot;August&quot;, &quot;September&quot;, &quot;October&quot;, &quot;November&quot;, &quot;December&quot;], &quot;weekdaysShort&quot;: [&quot;Sun&quot;, &quot;Mon&quot;, &quot;Tue&quot;, &quot;Wed&quot;, &quot;Thu&quot;, &quot;Fri&quot;, &quot;Sat&quot;], &quot;weekdaysFull&quot;: [&quot;Sunday&quot;, &quot;Monday&quot;, &quot;Tuesday&quot;, &quot;Wednesday&quot;, &quot;Thursday&quot;, &quot;Friday&quot;, &quot;Saturday&quot;], &quot;today&quot;: &quot;Today&quot;, &quot;selectYears&quot;: 200, &quot;formatSubmit&quot;: &quot;yyyy-mm-dd&quot;, &quot;monthsShort&quot;: [&quot;Jan&quot;, &quot;Feb&quot;, &quot;Mar&quot;, &quot;Apr&quot;, &quot;May&quot;, &quot;Jun&quot;, &quot;Jul&quot;, &quot;Aug&quot;, &quot;Sep&quot;, &quot;Oct&quot;, &quot;Nov&quot;, &quot;Dec&quot;]}, &quot;time&quot;: {&quot;formatSubmit&quot;: &quot;HH:i&quot;, &quot;format&quot;: &quot;HH:i&quot;}}"/>')  # noqa

        request_de = TestRequest(environ={'HTTP_ACCEPT_LANGUAGE': 'de'})
        widget_de = DatetimeWidget(request=request_de)
        self.assertEqual(
            widget_de.render(),
            '<input class="pat-pickadate" type="datetime-local" data-pat-pickadate="{&quot;date&quot;: {&quot;format&quot;: &quot;mmmm d, yyyy&quot;, &quot;max&quot;: [2033, 1, 1], &quot;clear&quot;: &quot;Clear&quot;, &quot;min&quot;: [1913, 1, 1], &quot;monthsFull&quot;: [&quot;Januar&quot;, &quot;Februar&quot;, &quot;M\\u00e4rz&quot;, &quot;April&quot;, &quot;Mai&quot;, &quot;Juni&quot;, &quot;Juli&quot;, &quot;August&quot;, &quot;September&quot;, &quot;Oktober&quot;, &quot;November&quot;, &quot;Dezember&quot;], &quot;weekdaysShort&quot;: [&quot;So&quot;, &quot;Mo&quot;, &quot;Di&quot;, &quot;Mi&quot;, &quot;Do&quot;, &quot;Fr&quot;, &quot;Sa&quot;], &quot;weekdaysFull&quot;: [&quot;Sonntag&quot;, &quot;Montag&quot;, &quot;Dienstag&quot;, &quot;Mittwoch&quot;, &quot;Donnerstag&quot;, &quot;Freitag&quot;, &quot;Samstag&quot;], &quot;today&quot;: &quot;Today&quot;, &quot;selectYears&quot;: 200, &quot;formatSubmit&quot;: &quot;yyyy-mm-dd&quot;, &quot;monthsShort&quot;: [&quot;Jan&quot;, &quot;Feb&quot;, &quot;Mrz&quot;, &quot;Apr&quot;, &quot;Mai&quot;, &quot;Jun&quot;, &quot;Jul&quot;, &quot;Aug&quot;, &quot;Sep&quot;, &quot;Okt&quot;, &quot;Nov&quot;, &quot;Dez&quot;]}, &quot;time&quot;: {&quot;formatSubmit&quot;: &quot;HH:i&quot;, &quot;format&quot;: &quot;HH:i&quot;}}"/>')  # noqa
Example #4
0
 def setUp(self):
     from plone.app.widgets.at import DatetimeWidget
     self.request = TestRequest(environ={'HTTP_ACCEPT_LANGUAGE': 'en'})
     self.context = mock.Mock()
     self.field = mock.Mock()
     self.field.getAccessor.return_value = lambda: u''
     self.field.getName.return_value = 'fieldname'
     self.widget = DatetimeWidget()
Example #5
0
 def setUp(self):
     from plone.app.widgets.at import DatetimeWidget
     self.request = TestRequest(environ={'HTTP_ACCEPT_LANGUAGE': 'en'})
     self.context = Mock()
     self.field = Mock()
     self.field.getAccessor.return_value = lambda: DateTime(
         '2013-11-13 10:20 Europe/Amsterdam'
     )
     self.field.getName.return_value = 'fieldname'
     self.widget = DatetimeWidget()
Example #6
0
 def test_defaults(self):
     from plone.app.widgets.base import DatetimeWidget
     widget = DatetimeWidget()
     self.assertEqual(
         widget.render(),
         '<input class="pat-pickadate" type="datetime-local" data-pat-pickadate="{&quot;date&quot;: {&quot;formatSubmit&quot;: &quot;yyyy-mm-dd&quot;, &quot;format&quot;: &quot;mmmm d, yyyy&quot;}, &quot;time&quot;: {&quot;formatSubmit&quot;: &quot;HH:i&quot;, &quot;format&quot;: &quot;HH:i&quot;}}"/>')  # noqa
Example #7
0
 def createWidget(self, lang='en', **kw):
     from plone.app.widgets.at import DatetimeWidget
     widget = DatetimeWidget(**kw)
     widget.request = TestRequest(environ={'HTTP_ACCEPT_LANGUAGE': lang})
     return widget
Example #8
0
class DatetimeWidgetTests(unittest.TestCase):
    def setUp(self):
        from plone.app.widgets.at import DatetimeWidget
        self.request = TestRequest(environ={'HTTP_ACCEPT_LANGUAGE': 'en'})
        self.context = Mock()
        self.field = Mock()
        self.field.getAccessor.return_value = lambda: DateTime(
            '2013-11-13 10:20 Europe/Amsterdam')
        self.field.getName.return_value = 'fieldname'
        self.widget = DatetimeWidget()

    def test_widget(self):
        self.assertEqual(
            {
                'pattern': 'pickadate',
                'value': '2013-11-13 10:20',
                'name': 'fieldname',
                'pattern_options': {
                    'date': {
                        'firstDay':
                        0,
                        'min': [1914, 1, 1],
                        'max': [2034, 1, 1],
                        'clear':
                        u'Clear',
                        'format':
                        'mmmm d, yyyy',
                        'monthsFull': [
                            u'January', u'February', u'March', u'April',
                            u'May', u'June', u'July', u'August', u'September',
                            u'October', u'November', u'December'
                        ],
                        'weekdaysShort': [
                            u'Sun', u'Mon', u'Tue', u'Wed', u'Thu', u'Fri',
                            u'Sat'
                        ],
                        'weekdaysFull': [
                            u'Sunday', u'Monday', u'Tuesday', u'Wednesday',
                            u'Thursday', u'Friday', u'Saturday'
                        ],
                        'today':
                        u'Today',
                        'selectYears':
                        200,
                        'placeholder':
                        u'Enter date...',
                        'monthsShort': [
                            u'Jan', u'Feb', u'Mar', u'Apr', u'May', u'Jun',
                            u'Jul', u'Aug', u'Sep', u'Oct', u'Nov', u'Dec'
                        ]
                    },
                    'time': {
                        'placeholder': u'Enter time...',
                        'today': u'Today',
                        'format': 'h:i a'
                    }
                }
            },
            self.widget._base_args(self.context, self.field, self.request),
        )

    def test_process_form(self):
        form = {
            'fieldname': '2011-11-22 13:30',
        }
        self.assertEqual(
            self.widget.process_form(self.context, self.field,
                                     form)[0].asdatetime(),
            (datetime(2011, 11, 22, 13, 30)))
Example #9
0
 def createWidget(self, lang='en', **kw):
     from plone.app.widgets.at import DatetimeWidget
     widget = DatetimeWidget(**kw)
     widget.request = TestRequest(environ={'HTTP_ACCEPT_LANGUAGE': lang})
     return widget