예제 #1
0
    def testWidgetExtract(self):
        from zope.interface import Interface, implementer
        from plone.app.textfield import RichText
        from zope.publisher.browser import TestRequest
        from Products.CMFCore.PortalContent import PortalContent
        from plone.app.textfield.widget import RichTextWidget
        from z3c.form.widget import FieldWidget
        from z3c.form.interfaces import NOVALUE

        class IWithText(Interface):

            text = RichText(title=u"Text",
                            default_mime_type='text/structured',
                            output_mime_type='text/html')

        @implementer(IWithText)
        class Context(PortalContent):

            text = None

        request = TestRequest()

        widget = FieldWidget(IWithText['text'], RichTextWidget(request))
        widget.update()

        value = widget.extract()
        self.assertEquals(NOVALUE, value)

        request.form['%s' % widget.name] = u"Sample **text**"
        request.form['%s.mimeType' % widget.name] = 'text/structured'

        value = widget.extract()
        self.assertEquals(
            u"<p>Sample <strong>text</strong></p>",
            value.output.strip())
예제 #2
0
    def testWidgetConverter(self):
        from zope.interface import Interface
        from plone.app.textfield import RichText
        from zope.publisher.browser import TestRequest
        from plone.app.textfield.value import RichTextValue
        from plone.app.textfield.widget import RichTextWidget
        from plone.app.textfield.widget import RichTextConverter
        from z3c.form.widget import FieldWidget

        _marker = object()

        class IWithText(Interface):

            text = RichText(title=u"Text",
                            default_mime_type='text/structured',
                            output_mime_type='text/html',
                            missing_value=_marker)

        request = TestRequest()

        widget = FieldWidget(IWithText['text'], RichTextWidget(request))
        widget.update()

        converter = RichTextConverter(IWithText['text'], widget)
        self.assertTrue(converter.toFieldValue(u'') is _marker)
        self.assertTrue(converter.toFieldValue(RichTextValue(u'')) is _marker)
예제 #3
0
    def testWidgetAllowedTypesField(self):
        from zope.interface import Interface, implementer
        from plone.app.textfield import RichText
        from zope.publisher.browser import TestRequest
        from Products.CMFCore.PortalContent import PortalContent
        from plone.app.textfield.widget import RichTextWidget
        from z3c.form.widget import FieldWidget

        class IWithText(Interface):

            text = RichText(
                title=u"Text",
                default_mime_type='text/structured',
                output_mime_type='text/html',
                allowed_mime_types=(
                    'text/structured',
                    'text/html'))

        @implementer(IWithText)
        class Context(PortalContent):

            text = None

        request = TestRequest()

        widget = FieldWidget(IWithText['text'], RichTextWidget(request))
        widget.update()

        self.portal['portal_properties']['site_properties']._setPropValue(
            'forbidden_contenttypes',
            ['text/structured'])

        allowed = widget.allowedMimeTypes()
        self.failUnless('text/html' in allowed)
        self.failUnless('text/structured' in allowed)
def DateFieldWidget(field, request):
    """IFieldWidget factory for DatetimeWidget."""
    widget = FieldWidget(field, DateWidget(request))
    currentYear = datetime.date.today().year
    minimumYearRange = currentYear - 1900  # don't display dates before 1900
    widget.years_range = (-minimumYearRange, 1)
    return widget
예제 #5
0
def ImageFieldWidget(field, request):
    image = FieldWidget(field, ImageWidget(request))
    image.value = field.title
    # Get the full resource URL for the image:
    site = hooks.getSite()
    image.src = unicode(zope.traversing.api.traverse(site, "++resource++" + field.image, request=request)())
    return image
예제 #6
0
def OptgroupFieldWidget(field, request):
    """Factory for OptgroupWidget."""
    widget = FieldWidget(field, OptgroupWidget(request))
    if hasattr(field, "value_type"):
        widget.multiple = getMultiAdapter((field, field.value_type, request), interfaces.IFieldWidget).multiple
    else:
        widget.multiple = getMultiAdapter((field, request), interfaces.IFieldWidget).multiple
    return widget
예제 #7
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
def CarouselBackgroundLinkWidget(field, request):
    widget = FieldWidget(field, RelatedItemsWidget(request))
    widget.vocabulary = 'plone.app.vocabularies.Catalog'
    widget.pattern_options = widget.pattern_options.copy()
    widget.pattern_options.update({
        'selectableTypes': ['Image'],
        'maximumSelectionSize': 1
    })
    return widget
def CarouselReferencesWidget(field, request):
    widget = FieldWidget(field, RelatedItemsWidget(request))
    widget.vocabulary = 'plone.app.vocabularies.Catalog'
    widget.pattern_options = widget.pattern_options.copy()
    widget.pattern_options.update({
        'selectableTypes': None,
        'maximumSelectionSize': None
    })
    return widget
예제 #10
0
    def test_widget_values(self):
        from plone.app.widgets.dx import RichTextWidget
        from plone.app.textfield.value import RichTextValue

        widget = FieldWidget(self.field, RichTextWidget(self.request))
        # set the context so we can get tinymce settings
        widget.context = self.portal
        widget.value = RichTextValue(u'Lorem ipsum \u2026')
        base_args = widget._base_args()
        self.assertEquals(base_args['value'], u'Lorem ipsum \u2026')
예제 #11
0
def RecurrenceFieldWidget(field, request):
    # Please note: If you create a new behavior with superclasses IEventBasic
    # and IRecurrence, then you have to reconfigure the dotted path value of
    # the start_field parameter for the RecurrenceWidget to the new
    # behavior name, like: IMyNewBehaviorName.start.
    widget = FieldWidget(field, RecurrenceWidget(request))
    widget.start_field = 'IEventBasic.start'
    widget.first_day = first_weekday_sun0
    widget.show_repeat_forever = False
    return widget
예제 #12
0
    def testRichTextAreaWidgetConverter(self):
        from zope.interface import Interface
        from plone.app.textfield import RichText
        from zope.publisher.browser import TestRequest
        from plone.app.textfield.value import RichTextValue
        from plone.app.textfield.widget import RichTextWidget
        from plone.app.textfield.widget import RichTextAreaConverter
        from z3c.form.widget import FieldWidget

        _marker = object()

        class IWithText(Interface):

            text = RichText(title=u"Text",
                            default_mime_type='text/structured',
                            output_mime_type='text/html',
                            missing_value=_marker)

        request = TestRequest()

        widget = FieldWidget(IWithText['text'], RichTextWidget(request))
        widget.update()

        converter = RichTextAreaConverter(IWithText['text'], widget)

        # Test with None input.
        self.assertRaises(ValueError, converter.toFieldValue, None)
        self.assertTrue(converter.toWidgetValue(None) is None)

        # Test with string input.
        self.assertTrue(converter.toFieldValue('') is _marker)
        self.assertRaises(ValueError, converter.toFieldValue, b'Foo')
        self.assertRaises(ValueError, converter.toWidgetValue, b'')
        self.assertRaises(ValueError, converter.toWidgetValue, b'Foo')

        # Test with unicode input.
        self.assertTrue(converter.toFieldValue(u'') is _marker)
        self.assertEqual(converter.toFieldValue(u'Foo').raw, u'Foo')
        self.assertTrue(
            isinstance(converter.toFieldValue(u'Foo'), RichTextValue)
        )
        self.assertEqual(converter.toWidgetValue(u''), u'')
        self.assertEqual(converter.toWidgetValue(u'Foo'), u'Foo')

        # Test with RichTextValue input.
        self.assertTrue(converter.toFieldValue(RichTextValue(u'')) is _marker)
        rich_text = RichTextValue(u'Foo')
        self.assertEqual(converter.toFieldValue(rich_text), rich_text)
        self.assertEqual(converter.toFieldValue(rich_text).raw, u'Foo')
        self.assertEqual(converter.toWidgetValue(rich_text), u'Foo')
예제 #13
0
파일: behaviors.py 프로젝트: upiq/uu.task
def NotificationRulesFieldWidget(field, request):
    widget = FieldWidget(field, PatternWidget(request))
    widget.pattern = 'uutask-notification-rules'
    widget.pattern_options = dict()
    widget.pattern_options['rule'] = dict(
        field2=[i[:2] for i in TIME_UNITS],
        field3=[i[:2] for i in TIME_RELATIONS],
        field4=[i[:2] for i in SOURCE_NOTIFY_DATE],
    )
    widget.pattern_options['i18n'] = dict(
        add_rule=_(u"Add rule"),
        remove=_(u"Remove"),
    )
    alsoProvides(widget, IInheritParentValue)
    return widget
예제 #14
0
    def test_dx_tinymcewidget_single_mimetype(self):
        """A RichTextWidget with only one available mimetype should render the
        pattern class directly on itself.
        """
        if IMarkupSchema:
            # if not, don't run this test
            self._set_mimetypes(allowed=('text/html',))
            from plone.app.z3cform.widget import RichTextWidget
            widget = FieldWidget(self.field, RichTextWidget(self.request))
            # set the context so we can get tinymce settings
            widget.context = self.portal
            rendered = widget.render()

            self.assertTrue('<select' not in rendered)
            self.assertTrue('pat-tinymce' in rendered)
            self.assertTrue('data-pat-tinymce' in rendered)
예제 #15
0
    def test_widget_params(self):
        from plone.app.z3cform.widget import RichTextWidget

        widget = FieldWidget(self.field, RichTextWidget(self.request))
        # set the context so we can get tinymce settings
        widget.context = self.portal
        widget.update()
        base_args = widget._base_args()
        self.assertEqual(base_args['name'], 'text')
        self.assertEqual(base_args['value'], u'')
        self.assertEqual(base_args['pattern'], 'tinymce')

        self.assertEqual(base_args['pattern_options']['prependToUrl'],
                         'resolveuid/')
        self.assertEqual(
            base_args['pattern_options']['upload']['relativePath'],
            '@@fileUpload')
예제 #16
0
    def test_widget_params(self):
        from plone.app.widgets.dx import RichTextWidget

        widget = FieldWidget(self.field, RichTextWidget(self.request))
        widget.update()
        base_args = widget._base_args()
        self.assertEqual(base_args['name'], 'text')
        self.assertEqual(base_args['value'], u'')
        self.assertEqual(base_args['pattern'], 'tinymce')

        if PLONE50:
            self.assertEqual(base_args['pattern_options'], {})
        else:
            self.assertEqual(base_args['pattern_options']['prependToUrl'],
                             'resolveuid/')
            self.assertEqual(base_args['pattern_options']['prependToUrl'],
                             'resolveuid/')
            self.assertEqual(base_args['pattern_options']['anchorSelector'],
                             self.portal.portal_tinymce.anchor_selector)
예제 #17
0
    def test_widget_params(self):
        from plone.app.widgets.dx import RichTextWidget

        widget = FieldWidget(self.field, RichTextWidget(self.request))
        # set the context so we can get tinymce settings
        widget.context = self.portal
        widget.update()
        base_args = widget._base_args()
        self.assertEqual(base_args['name'], 'text')
        self.assertEqual(base_args['value'], u'')
        self.assertEqual(base_args['pattern'], 'tinymce')

        self.assertEqual(base_args['pattern_options']['prependToUrl'],
                         'resolveuid/')
        self.assertEqual(base_args['pattern_options']['rel_upload_path'],
                         '@@fileUpload')

        if not PLONE50:
            self.assertEqual(base_args['pattern_options']['anchorSelector'],
                             self.portal.portal_tinymce.anchor_selector)
예제 #18
0
    def test_dx_tinymcewidget_multiple_mimetypes_create(self):
        """A RichTextWidget with multiple available mimetypes should render a
        mimetype selection widget along with the textfield. When there is no
        field value, the default mimetype should be preselected.
        """
        if IMarkupSchema:
            # if not, don't run this test
            self._set_mimetypes(allowed=('text/html', 'text/plain'))
            from plone.app.z3cform.widget import RichTextWidget
            widget = FieldWidget(self.field, RichTextWidget(self.request))
            # set the context so we can get tinymce settings
            widget.context = self.portal
            rendered = widget.render()

            self.assertTrue('<select' in rendered)
            self.assertTrue('pat-textareamimetypeselector' in rendered)
            self.assertTrue('data-pat-textareamimetypeselector' in rendered)
            self.assertTrue(
                '<option value="text/html" selected="selected">' in rendered)
            self.assertTrue('pat-tinymce' not in rendered)
예제 #19
0
 def test_extract(self):
     class IWithText(Interface):
         
         text = XMLText(title=u"Text")
     
     class Context(PortalContent):
         implements(IWithText)
         
         text = None
     
     widget = FieldWidget(IWithText['text'], XMLTextWidget(self.request))
     widget.update()
     
     value = widget.extract()
     self.assertEquals(NOVALUE, value)
     
     self.request.form['%s' % widget.name] = u"<html><body>test</body></html>"
     self.request.form['%s.mimeType' % widget.name] = 'text/xml'
     
     value = widget.extract()
     self.assertEquals(u"<html><body>test</body></html>", value.raw)
    def test_dx_tinymcewidget_multiple_mimetypes_edit(self):
        """A RichTextWidget with multiple available mimetypes should render a
        mimetype selection widget along with the textfield. When there is
        already a RichTextValue, it's mimetype should be preselected.
        """
        if IMarkupSchema:
            # if not, don't run this test
            self._set_mimetypes(allowed=('text/html', 'text/plain'))
            from collective.patterns.widgets.dx import RichTextWidget
            from plone.app.textfield.value import RichTextValue
            widget = FieldWidget(self.field, RichTextWidget(self.request))
            # set the context so we can get tinymce settings
            widget.context = self.portal
            widget.value = RichTextValue(u'Hello world', mimeType='text/plain')
            rendered = widget.render()

            self.assertTrue('<select' in rendered)
            self.assertTrue('pat-textareamimetypeselector' in rendered)
            self.assertTrue('data-pat-textareamimetypeselector' in rendered)
            self.assertTrue(
                '<option value="text/plain" selected="selected">' in rendered)
            self.assertTrue('pat-tinymce' not in rendered)
예제 #21
0
    def test_converter(self):
        _marker = object()

        class IWithText(Interface):
            
            text = XMLText(title=u"Text", missing_value = _marker)

        widget = FieldWidget(IWithText['text'], XMLTextWidget(self.request))
        widget.update()

        converter = XMLTextConverter(IWithText['text'], widget)
        self.assertTrue(converter.toFieldValue(u'') is _marker)
        self.assertTrue(converter.toFieldValue(XMLTextValue(u'')) is _marker)

        self.assertEquals(converter.toWidgetValue(None), None)
        self.assertTrue(IXMLTextValue.providedBy(
            converter.toWidgetValue(XMLTextValue(u''))))
        self.request.form['%s' % widget.name] = u"<html><body>test</body></html>"
        self.request.form['%s.mimeType' % widget.name] = 'text/xml'
        widget.update()
        self.assertTrue(IXMLTextValue.providedBy(
            converter.toWidgetValue(u"<html><body>test</body></html>")))
        with self.assertRaises(ValueError):
            converter.toWidgetValue(int)
예제 #22
0
파일: behaviors.py 프로젝트: upiq/uu.task
def DueFieldWidget(field, request):
    widget = FieldWidget(field, PatternWidget(request))
    widget.pattern = 'uutask-due'
    widget.pattern_options = dict()
    widget.pattern_options['date'] = dict()
    widget.pattern_options['computed'] = dict(
        field2=[i[:2] for i in TIME_UNITS],
        field3=[i[:2] for i in TIME_RELATIONS],
        field4=[i[:2] for i in SOURCE_DATE],
    )
    widget.pattern_options['computed_dow'] = dict(
        field2=[i[:2] for i in DAYS_OF_WEEK],
        field3=[i[:2] for i in TIME_RELATIONS],
        field4=[i[:2] for i in SOURCE_DATE],
    )
    alsoProvides(widget, IInheritParentValue)
    return widget
예제 #23
0
def ExpirationDateFieldWidget(field, request):
    widget = FieldWidget(field, TypeADatetimeWidget(request))
    widget.pattern_options.setdefault("date", {})
    widget.pattern_options["date"]["firstDay"] = first_weekday()
    return widget
 def RelatedItemsFieldWidget(field, request):
     widget = FieldWidget(field, RelatedItemsWidget(request))
     widget.vocabulary = 'plone.app.vocabularies.Catalog'
     return widget
예제 #25
0
파일: button.py 프로젝트: CGTIC/Plone_SP
def ButtonFieldWidget(field, request):
    button = FieldWidget(field, ButtonWidget(request))
    button.value = field.title
    return button
예제 #26
0
def RelatedAttachmentsFieldWidget(field, request, extra=None):
    if extra is not None:
        request = extra
    return FieldWidget(field, RelatedAttachmentsWidget(request))
예제 #27
0
def ColorDictInputFieldWidget(field, request):
    """IFieldWidget factory for TextWidget."""
    return FieldWidget(field, ColorDictInputWidget(request))
예제 #28
0
def ExperimentResultProjectionFieldWidget(field, request):
    return FieldWidget(field, ExperimentResultProjectionWidget(request))
예제 #29
0
def FunctionsFieldWidget(field, request):
    return FieldWidget(field, FunctionsWidget(request))
예제 #30
0
def FutureDatasetsFieldWidget(field, request):
    """
    Widget to select datasets and layers
    """
    return FieldWidget(field, FutureDatasetsWidget(request))
예제 #31
0
def ExperimentResultFieldWidget(field, request):
    return FieldWidget(field, ExperimentResultWidget(request))
예제 #32
0
def ExperimentSDMFieldWidget(field, request):
    return FieldWidget(field, ExperimentSDMWidget(request))
예제 #33
0
def DatasetDictFieldWidget(field, request):
    """
    Widget to select datasets and layers
    """
    return FieldWidget(field, DatasetDictWidget(request))
예제 #34
0
def DatasetFieldWidget(field, request):
    return FieldWidget(field, DatasetWidget(request))
예제 #35
0
def YearFieldWidget(field, request):
    """IFieldWidget factory for YearWidget."""
    return FieldWidget(field, YearWidget(request))
예제 #36
0
def BoolRadioFieldWidget(field, request):
    return FieldWidget(field, BoolRadioWidget(request))
def ScheduleFieldWidget(field, request):
    """IFieldWidget factory for cheduleWidget."""
    return FieldWidget(field, ScheduleWidget(request))
예제 #38
0
def PaymentProcessorFieldWidget(field, request):
    """IFieldWidget factory for PaymentProcessorWidget."""
    return FieldWidget(field, PaymentProcessorWidget(request))
예제 #39
0
def RelatedImagesFieldWidget(field, request, extra=None):
    if extra is not None:
        request = extra
    return FieldWidget(field, RelatedImagesWidget(request))
예제 #40
0
def StreamNamedFileFieldWidget(field, request):
    return FieldWidget(field, StreamNamedFileWidget(request))
예제 #41
0
def RelatedMediaFieldWidget(field, request, extra=None):
    if extra is not None:
        request = extra
    return FieldWidget(field, RelatedMediaWidget(request))
def DateFieldWidget(field, request):
    widget = FieldWidget(field, DateWidget(request))
    widget.years_range = (-100, 10)
    widget.update()
    return widget
예제 #43
0
def TableRadioFieldWidget(field, request):
    """IFieldWidget factory for TableRadioWidget."""

    return FieldWidget(field, TableRadioWidget(request))
예제 #44
0
def RelatedItemsAddFieldWidget(field, request, extra=None):
    """An advanced related items widget for Plone."""
    if extra is not None:
        request = extra
    return FieldWidget(field, RelatedItemsAddWidget(request))
예제 #45
0
파일: submit.py 프로젝트: CGTIC/Plone_SP
def SubmitFieldWidget(field, request):
    submit = FieldWidget(field, SubmitWidget(request))
    submit.value = field.title
    return submit
예제 #46
0
def SelectFieldWidget(field, request):
    return FieldWidget(field, SelectWidget(request))
예제 #47
0
파일: behaviors.py 프로젝트: upiq/uu.task
def AssigneeFieldWidget(field, request):
    widget = FieldWidget(field, AjaxSelectWidget(request))
    widget.vocabulary = 'uu.task.Users'
    widget.pattern_options['allowNewItems'] = False
    alsoProvides(widget, IInheritParentValue)
    return widget
예제 #48
0
def AjaxSelectFieldWidget(field, request, extra=None):
    if extra is not None:
        request = extra
    return FieldWidget(field, AjaxSelectWidget(request))
예제 #49
0
def DateFieldWidget(field, request):
    """IFieldWidget factory for DateWidget."""
    return FieldWidget(field, DateWidget(request))
예제 #50
0
def RichTextFieldWidget(field, request):
    return FieldWidget(field, RichTextWidget(request))
예제 #51
0
def EndDateFieldWidget(field, request):
    widget = FieldWidget(field, DatetimeWidget(request))
    widget.default_timezone = default_timezone
    return widget
예제 #52
0
def QueryStringFieldWidget(field, request, extra=None):
    if extra is not None:
        request = extra
    return FieldWidget(field, QueryStringWidget(request))
예제 #53
0
def MonthYearFieldWidget(field, request):
    """IFieldWidget factory for MonthYearWidget."""
    return FieldWidget(field, MonthYearWidget(request))
예제 #54
0
def DataGridFieldObjectFactory(field, request):
    """IFieldWidget factory for DataGridField."""
    return FieldWidget(field, DataGridFieldObject(request))
예제 #55
0
def FunctionsRadioFieldWidget(field, request):
    return FieldWidget(field, FunctionsRadioWidget(request))
예제 #56
0
def QueryStringFieldWidget(field, request):
    return FieldWidget(field, QueryStringWidget(request))
예제 #57
0
def _custom_field_widget(field, request):
    from plone.app.z3cform.widget import AjaxSelectWidget
    widget = FieldWidget(field, AjaxSelectWidget(request))
    widget.vocabulary = 'plone.app.vocabularies.PortalTypes'
    return widget
예제 #58
0
def FunkyFieldWidget(field, request):
    """IFieldWidget factory for FunkyWidget."""
    return FieldWidget(field, FunkyWidget(request))
예제 #59
0
def DataSubsetsFieldWidget(field, request):
    return FieldWidget(field, DataSubsetsWidget(request))
예제 #60
0
def DatetimeFieldWidget(field, request):
    return FieldWidget(field, DatetimeWidget(request))