コード例 #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)
コード例 #4
0
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
コード例 #8
0
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
コード例 #9
0
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
ファイル: test_dx.py プロジェクト: hoka/plone.app.widgets
    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
ファイル: behaviors.py プロジェクト: takanory/plone.app.event
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
ファイル: tests.py プロジェクト: plone/plone.app.textfield
    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
ファイル: test_dx.py プロジェクト: jcerjak/plone.app.widgets
    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
ファイル: test_dx.py プロジェクト: dimlev/plone.app.widgets
    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)
コード例 #20
0
    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
コード例 #24
0
 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
ファイル: widgets.py プロジェクト: manhinli/org.bccvl.site
def ExperimentResultProjectionFieldWidget(field, request):
    return FieldWidget(field, ExperimentResultProjectionWidget(request))
コード例 #29
0
ファイル: widgets.py プロジェクト: manhinli/org.bccvl.site
def FunctionsFieldWidget(field, request):
    return FieldWidget(field, FunctionsWidget(request))
コード例 #30
0
ファイル: widgets.py プロジェクト: manhinli/org.bccvl.site
def FutureDatasetsFieldWidget(field, request):
    """
    Widget to select datasets and layers
    """
    return FieldWidget(field, FutureDatasetsWidget(request))
コード例 #31
0
ファイル: widgets.py プロジェクト: manhinli/org.bccvl.site
def ExperimentResultFieldWidget(field, request):
    return FieldWidget(field, ExperimentResultWidget(request))
コード例 #32
0
ファイル: widgets.py プロジェクト: manhinli/org.bccvl.site
def ExperimentSDMFieldWidget(field, request):
    return FieldWidget(field, ExperimentSDMWidget(request))
コード例 #33
0
ファイル: widgets.py プロジェクト: manhinli/org.bccvl.site
def DatasetDictFieldWidget(field, request):
    """
    Widget to select datasets and layers
    """
    return FieldWidget(field, DatasetDictWidget(request))
コード例 #34
0
ファイル: widgets.py プロジェクト: manhinli/org.bccvl.site
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
ファイル: widgets.py プロジェクト: manhinli/org.bccvl.site
def BoolRadioFieldWidget(field, request):
    return FieldWidget(field, BoolRadioWidget(request))
コード例 #37
0
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
ファイル: widget.py プロジェクト: seanupton/wildcard.media
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))
コード例 #42
0
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
ファイル: widget.py プロジェクト: BB-Open/pkan_widgets
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
ファイル: widget.py プロジェクト: urska19/Plone_site
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
ファイル: widget.py プロジェクト: urska19/Plone_site
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
ファイル: widget.py プロジェクト: urska19/Plone_site
def RichTextFieldWidget(field, request):
    return FieldWidget(field, RichTextWidget(request))
コード例 #51
0
ファイル: behaviors.py プロジェクト: takanory/plone.app.event
def EndDateFieldWidget(field, request):
    widget = FieldWidget(field, DatetimeWidget(request))
    widget.default_timezone = default_timezone
    return widget
コード例 #52
0
ファイル: widget.py プロジェクト: urska19/Plone_site
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
ファイル: widgets.py プロジェクト: manhinli/org.bccvl.site
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
ファイル: widgets.py プロジェクト: manhinli/org.bccvl.site
def DataSubsetsFieldWidget(field, request):
    return FieldWidget(field, DataSubsetsWidget(request))
コード例 #60
0
ファイル: widget.py プロジェクト: urska19/Plone_site
def DatetimeFieldWidget(field, request):
    return FieldWidget(field, DatetimeWidget(request))