Exemplo n.º 1
0
 def setUp(self):
     from plone.app.widgets.at import DateWidget
     self.request = TestRequest(environ={'HTTP_ACCEPT_LANGUAGE': 'en'})
     self.context = Mock()
     self.field = Mock()
     self.field.getAccessor.return_value = lambda: u''
     self.field.getName.return_value = 'fieldname'
     self.widget = DateWidget()
Exemplo n.º 2
0
class DateWidgetTests(unittest.TestCase):

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

    def test_widget(self):
        self.assertEqual(
            {
                'pattern': 'pickadate',
                'value': u'',
                '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': False
                }
            },
            self.widget._base_args(self.context, self.field, self.request),
        )

    def test_process_form(self):
        form = {
            'fieldname': '2011-11-22',
        }
        self.assertEqual(
            self.widget.process_form(
                self.context, self.field, form)[0].asdatetime(),
            (datetime(2011, 11, 22))
        )
Exemplo n.º 3
0
    def test_localization(self):
        from plone.app.widgets.base import DateWidget
        request_en = TestRequest(environ={'HTTP_ACCEPT_LANGUAGE': 'en'})
        widget_en = DateWidget(request=request_en)
        self.assertEqual(
            widget_en.render(),
            '<input class="pat-pickadate" type="date" 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;false&quot;}"/>')  # noqa

        request_de = TestRequest(environ={'HTTP_ACCEPT_LANGUAGE': 'de'})
        widget_de = DateWidget(request=request_de)
        self.assertEqual(
            widget_de.render(),
            '<input class="pat-pickadate" type="date" 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;false&quot;}"/>')  # noqa
Exemplo n.º 4
0
 def setUp(self):
     from plone.app.widgets.at import DateWidget
     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 = DateWidget()
Exemplo n.º 5
0
 def test_defaults(self):
     from plone.app.widgets.base import DateWidget
     widget = DateWidget()
     self.assertEqual(
         widget.render(),
         '<input class="pat-pickadate" type="date" 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;false&quot;}"/>')  # noqa
Exemplo n.º 6
0
 def createWidget(self, lang='en', **kw):
     from plone.app.widgets.at import DateWidget
     widget = DateWidget(**kw)
     widget.request = TestRequest(environ={'HTTP_ACCEPT_LANGUAGE': lang})
     return widget
Exemplo n.º 7
0
class DateWidgetTests(unittest.TestCase):
    def setUp(self):
        from plone.app.widgets.at import DateWidget
        self.request = TestRequest(environ={'HTTP_ACCEPT_LANGUAGE': 'en'})
        self.context = Mock()
        self.field = Mock()
        self.field.getAccessor.return_value = lambda: u''
        self.field.getName.return_value = 'fieldname'
        self.widget = DateWidget()

    def test_widget(self):
        self.assertEqual(
            {
                'pattern': 'pickadate',
                'value': u'',
                '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': False
                }
            },
            self.widget._base_args(self.context, self.field, self.request),
        )

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