Exemplo n.º 1
0
    def test__first_weekday(self):
        # make sure, plone.app.event is available and mock it.
        mock = Mock()
        modules = {
            'plone': mock,
            'plone.app': mock.module,
            'plone.app.event': mock.module.module,
            'plone.app.event.base': mock.module.module.module,
        }
        with patch('Products.CMFCore.utils.getToolByName', new=MockTool), \
             patch.dict('sys.modules', modules):
            # test for plone.app.event installed
            from plone.app.event import base
            base.first_weekday = lambda: 0
            base.wkday_to_mon1 = lambda x: x
            from plone.app.widgets import utils
            reload(utils)  # reload utils, so that plone.app.event mock import
            # works, even if it was imported before.,,
            orig_HAS_PAE = utils.HAS_PAE
            utils.HAS_PAE = True
            self.assertEquals(utils.first_weekday(), 0)
            base.first_weekday = lambda: 1
            self.assertEquals(utils.first_weekday(), 1)
            base.first_weekday = lambda: 5
            self.assertEquals(utils.first_weekday(), 1)

            # test without plone.app.event installed
            utils.HAS_PAE = False
            self.assertEquals(utils.first_weekday(), 0)

        # restore original state
        utils.HAS_PAE = orig_HAS_PAE
        reload(utils)
    def test__first_weekday(self):
        # make sure, plone.app.event is available and mock it.
        mock = Mock()
        modules = {
            'plone': mock,
            'plone.app': mock.module,
            'plone.app.event': mock.module.module,
            'plone.app.event.base': mock.module.module.module,
        }
        with patch.dict('sys.modules', modules):
            # test for plone.app.event installed
            from plone.app.event import base
            base.first_weekday = lambda: 0
            base.wkday_to_mon1 = lambda x: x
            from plone.app.widgets import utils
            reload(utils)  # reload utils, so that plone.app.event mock import
                           # works, even if it was imported before.,,
            orig_HAS_PAE = utils.HAS_PAE
            utils.HAS_PAE = True
            self.assertEquals(utils.first_weekday(), 0)
            base.first_weekday = lambda: 1
            self.assertEquals(utils.first_weekday(), 1)
            base.first_weekday = lambda: 5
            self.assertEquals(utils.first_weekday(), 1)

            # test without plone.app.event installed
            utils.HAS_PAE = False
            self.assertEquals(utils.first_weekday(), 0)

            # restore original state
            utils.HAS_PAE = orig_HAS_PAE
            reload(utils)
Exemplo n.º 3
0
    def _new_fiddle(self, schema):
        self._old_fiddle(schema)
        for field in schema.fields():
            old = field.widget

            if field.__name__ in ["startDate"]:
                field.widget = ATTypeADatetimeWidget(
                    label=old.label,
                    description=old.description,
                    pattern_options={"date": {"firstDay": first_weekday()}},
                )

            if field.__name__ in ["endDate"]:
                field.widget = ATTypeADatetimeWidget(
                    label=old.label,
                    description=old.description,
                    pattern_options={"date": {"firstDay": first_weekday()}},
                )

            if field.__name__ in ["effectiveDate", "expirationDate"]:
                field.widget = ATTypeADatetimeWidget(
                    label=old.label,
                    description=old.description,
                    pattern_options={"date": {"firstDay": first_weekday()}},
                )
Exemplo n.º 4
0
    def _new_fiddle(self, schema):
        self._old_fiddle(schema)
        for field in schema.fields():
            old = field.widget

            if field.__name__ in ['startDate']:
                field.widget = ATTypeADatetimeWidget(
                    label=old.label,
                    description=old.description,
                    pattern_options={'date': {'firstDay': first_weekday()}},
                )

            if field.__name__ in ['endDate']:
                field.widget = ATTypeADatetimeWidget(
                    label=old.label,
                    description=old.description,
                    pattern_options={'date': {'firstDay': first_weekday()}},
                )

            if field.__name__ in ['effectiveDate', 'expirationDate']:
                field.widget = ATTypeADatetimeWidget(
                    label=old.label,
                    description=old.description,
                    pattern_options={'date': {'firstDay': first_weekday()}},
                )
Exemplo n.º 5
0
def DateFieldWidget(field, request):
    widget = FieldWidget(field, DateWidget(request))
    widget.pattern_options.setdefault('date', {})
    try:
        widget.pattern_options['date']['firstDay'] = first_weekday()
    except ComponentLookupError:
        pass
    return widget
Exemplo n.º 6
0
def DateFieldWidget(field, request):
    widget = FieldWidget(field, DateWidget(request))
    widget.pattern_options.setdefault('date', {})
    try:
        widget.pattern_options['date']['firstDay'] = first_weekday()
    except ComponentLookupError:
        pass
    return widget
Exemplo n.º 7
0
def ExpirationDateFieldWidget(field, request):
    widget = FieldWidget(field, TypeADatetimeWidget(request))
    widget.pattern_options.setdefault("date", {})
    widget.pattern_options["date"]["firstDay"] = first_weekday()
    return widget
Exemplo n.º 8
0
    def fiddle(self, schema):

        for field in schema.fields():
            old = field.widget

            if field.__name__ in ['startDate']:
                field.widget = at.DatetimeWidget(
                    label=old.label,
                    description=old.description,
                    pattern_options={'date': {
                        'firstDay': first_weekday()
                    }},
                )

            if field.__name__ in ['endDate']:
                field.widget = at.DatetimeWidget(
                    label=old.label,
                    description=old.description,
                    pattern_options={'date': {
                        'firstDay': first_weekday()
                    }},
                )

            if field.__name__ in ['subject']:
                field.widget = at.KeywordsWidget(
                    label=old.label,
                    description=old.description,
                )

            if field.__name__ in ['language']:
                field.widget = at.SelectWidget(
                    label=old.label,
                    description=old.description,
                )

            if field.__name__ in ['effectiveDate', 'expirationDate']:
                field.widget = at.DatetimeWidget(
                    label=old.label,
                    description=old.description,
                    pattern_options={'date': {
                        'firstDay': first_weekday()
                    }},
                )

            if field.__name__ in ['contributors']:
                field.widget = at.AjaxSelectWidget(
                    label=old.label,
                    description=_plone(u"The names of people that have "
                                       u"contributed to this item."),
                    vocabulary="plone.app.vocabularies.Users",
                )

            if field.__name__ in ['creators']:
                field.widget = at.AjaxSelectWidget(
                    label=old.label,
                    description=_plone(u"The names of people that are "
                                       u"creators to this item."),
                    vocabulary="plone.app.vocabularies.Users",
                )

            richtexteditor = getAdapter(self.context, name='richtexteditor')
            if richtexteditor.is_selected('TinyMCE'):
                if field.__name__ in ['text']:
                    field.widget = at.TinyMCEWidget(
                        label=old.label,
                        description=old.description,
                    )

            if field.__name__ == 'query':
                field.widget = at.QueryStringWidget(
                    label=old.label, description=old.description)

            if field.__name__ == 'relatedItems':
                field.widget = at.RelatedItemsWidget(
                    label=old.label, description=old.description)
Exemplo n.º 9
0
def ExpirationDateFieldWidget(field, request):
    widget = FieldWidget(field, DatetimeWidget(request))
    widget.pattern_options.setdefault('date', {})
    widget.pattern_options['date']['firstDay'] = first_weekday()
    return widget
Exemplo n.º 10
0
def ExpirationDateFieldWidget(field, request):
    widget = FieldWidget(field, DatetimeWidget(request))
    widget.pattern_options.setdefault('date', {})
    widget.pattern_options['date']['firstDay'] = first_weekday()
    return widget
Exemplo n.º 11
0
    def fiddle(self, schema):
        for field in schema.fields():
            old = field.widget

            if field.__name__ in ['startDate']:
                field.widget = at.DatetimeWidget(
                    label=old.label,
                    description=old.description,
                    pattern_options={'date': {'firstDay': first_weekday()}},
                )

            if field.__name__ in ['endDate']:
                field.widget = at.DatetimeWidget(
                    label=old.label,
                    description=old.description,
                    pattern_options={'date': {'firstDay': first_weekday()}},
                )

            if field.__name__ in ['subject']:
                field.widget = at.KeywordsWidget(
                    label=old.label,
                    description=old.description,
                )

            if field.__name__ in ['language']:
                field.widget = at.SelectWidget(
                    label=old.label,
                    description=old.description,
                )

            if field.__name__ in ['effectiveDate', 'expirationDate']:
                field.widget = at.DatetimeWidget(
                    label=old.label,
                    description=old.description,
                    pattern_options={'date': {'firstDay': first_weekday()}},
                )

            if field.__name__ in ['contributors']:
                field.widget = at.AjaxSelectWidget(
                    label=old.label,
                    description=_plone(u"The names of people that have "
                                       u"contributed to this item."),
                    vocabulary="plone.app.vocabularies.Users",
                )

            if field.__name__ in ['creators']:
                field.widget = at.AjaxSelectWidget(
                    label=old.label,
                    description=_plone(u"The names of people that are "
                                       u"creators to this item."),
                    vocabulary="plone.app.vocabularies.Users",
                )

            if field.__name__ in ['text']:
                field.widget = at.TinyMCEWidget(
                    label=old.label,
                    description=old.description,
                )

            if field.__name__ == 'query':
                field.widget = at.QueryStringWidget(
                    label=old.label,
                    description=old.description
                )