Exemplo n.º 1
0
    def test_tuple(self):
        from plone.app.z3cform.utils import call_callables

        test_in = (1, 2, 3, lambda x: x)
        test_compare = (1, 2, 3, 'funny return value')
        test_out = call_callables(test_in, 'funny return value')
        self.assertEqual(test_out, test_compare)
Exemplo n.º 2
0
    def test_simple(self):
        from plone.app.z3cform.utils import call_callables

        test_in = 1
        test_compare = 1
        test_out = call_callables(test_in, 'funny return value')
        self.assertEqual(test_out, test_compare)
Exemplo n.º 3
0
    def test_simple_function(self):
        from plone.app.z3cform.utils import call_callables

        def test_in(x):
            return x

        test_compare = 'funny return value'
        test_out = call_callables(test_in, 'funny return value')
        self.assertEqual(test_out, test_compare)
Exemplo n.º 4
0
    def test_simple(self):
        from plone.app.z3cform.utils import call_callables

        test_in = 1
        test_compare = 1
        test_out = call_callables(
            test_in,
            'funny return value',
        )
        self.assertEqual(test_out, test_compare)
Exemplo n.º 5
0
    def test_tuple(self):
        from plone.app.z3cform.utils import call_callables

        test_in = (1, 2, 3, lambda x: x)
        test_compare = (1, 2, 3, 'funny return value')
        test_out = call_callables(
            test_in,
            'funny return value',
        )
        self.assertEqual(test_out, test_compare)
Exemplo n.º 6
0
    def test_list(self):
        from plone.app.z3cform.utils import call_callables

        test_in = [1, 2, 3, lambda x: x]
        test_compare = [1, 2, 3, 'funny return value']
        test_out = call_callables(
            test_in,
            'funny return value',
        )
        self.assertEqual(test_out, test_compare)
Exemplo n.º 7
0
    def test_complex(self):
        from plone.app.z3cform.utils import call_callables

        test_in = {
            'normal':
            123,
            'list': [
                1, 2, 3, lambda x: x,
                [11, 22, 33, lambda x: x, (44, 55, 66, lambda x: x)]
            ],  # noqa
            'tuple': (1, 2, 3, lambda x: x, (11, 22, 33, lambda x: x,
                                             [44, 55, 66,
                                              lambda x: x])),  # noqa
            'dict': {
                'subnormal': 456,
                'sublist': [4, 5, 6, lambda x: x],
                'subtuple': (4, 5, 6, lambda x: x),
                'subdict': {
                    'subsubnormal': 789,
                    'subsublist': [7, 8, 9, lambda x: x],
                    'subsubtuple': (7, 8, 9, lambda x: x),
                }
            }
        }

        test_compare = {
            'normal':
            123,
            'list': [
                1, 2, 3, 'funny return value',
                [
                    11, 22, 33, 'funny return value',
                    (44, 55, 66, 'funny return value')
                ]
            ],  # noqa
            'tuple': (1, 2, 3, 'funny return value',
                      (11, 22, 33, 'funny return value',
                       [44, 55, 66, 'funny return value'])),  # noqa
            'dict': {
                'subnormal': 456,
                'sublist': [4, 5, 6, 'funny return value'],
                'subtuple': (4, 5, 6, 'funny return value'),
                'subdict': {
                    'subsubnormal': 789,
                    'subsublist': [7, 8, 9, 'funny return value'],
                    'subsubtuple': (7, 8, 9, 'funny return value'),
                }
            }
        }

        test_out = call_callables(test_in, 'funny return value')

        self.assertEqual(test_out, test_compare)
Exemplo n.º 8
0
    def test_simple_function(self):
        from plone.app.z3cform.utils import call_callables

        def test_in(x):
            return x

        test_compare = 'funny return value'
        test_out = call_callables(
            test_in,
            'funny return value',
        )
        self.assertEqual(test_out, test_compare)
Exemplo n.º 9
0
    def render(self):
        """Render widget.

        :returns: Widget's HTML.
        :rtype: string
        """
        if self.mode != 'input':
            return super(BaseWidget, self).render()

        _base_args = self._base_args()
        _base_args['pattern_options'] = call_callables(
            _base_args['pattern_options'], self.context)

        pattern_widget = self._base(**_base_args)
        if getattr(self, 'klass', False):
            pattern_widget.klass = u'{0} {1}'.format(pattern_widget.klass,
                                                     self.klass)
        return pattern_widget.render()
Exemplo n.º 10
0
    def test_complex(self):
        from plone.app.z3cform.utils import call_callables

        test_in = {
            'normal': 123,
            'list': [1, 2, 3, lambda x: x, [11, 22, 33, lambda x: x, (44, 55, 66, lambda x: x)]],  # noqa
            'tuple': (1, 2, 3, lambda x: x, (11, 22, 33, lambda x: x, [44, 55, 66, lambda x: x])),  # noqa
            'dict': {
                'subnormal': 456,
                'sublist': [4, 5, 6, lambda x: x],
                'subtuple': (4, 5, 6, lambda x: x),
                'subdict': {
                    'subsubnormal': 789,
                    'subsublist': [7, 8, 9, lambda x: x],
                    'subsubtuple': (7, 8, 9, lambda x: x),
                },
            },
        }

        test_compare = {
            'normal': 123,
            'list': [1, 2, 3, 'funny return value', [11, 22, 33, 'funny return value', (44, 55, 66, 'funny return value')]],  # noqa
            'tuple': (1, 2, 3, 'funny return value', (11, 22, 33, 'funny return value', [44, 55, 66, 'funny return value'])),  # noqa
            'dict': {
                'subnormal': 456,
                'sublist': [4, 5, 6, 'funny return value'],
                'subtuple': (4, 5, 6, 'funny return value'),
                'subdict': {
                    'subsubnormal': 789,
                    'subsublist': [7, 8, 9, 'funny return value'],
                    'subsubtuple': (7, 8, 9, 'funny return value'),
                },
            },
        }

        test_out = call_callables(
            test_in,
            'funny return value',
        )

        self.assertEqual(test_out, test_compare)
Exemplo n.º 11
0
    def render(self):
        """Render widget.

        :returns: Widget's HTML.
        :rtype: string
        """
        if self.mode != 'input':
            return super(BaseWidget, self).render()

        _base_args = self._base_args()
        _base_args['pattern_options'] = call_callables(
            _base_args['pattern_options'],
            self.context
        )

        pattern_widget = self._base(**_base_args)
        if getattr(self, 'klass', False):
            pattern_widget.klass = u'{0} {1}'.format(
                pattern_widget.klass, self.klass
            )
        return pattern_widget.render()
Exemplo n.º 12
0
    def tinymce(self):
        """
        data-pat-tinymce : JSON.stringify({
            relatedItems: {
              vocabularyUrl: config.portal_url +
                '/@@getVocabulary?name=plone.app.vocabularies.Catalog'
            },
            tiny: config,
            prependToUrl: 'resolveuid/',
            linkAttribute: 'UID',
            prependToScalePart: '/@@images/image/'
          })
        """

        generator = TinyMCESettingsGenerator(self.context, self.request)
        settings = generator.settings
        folder = aq_inner(self.context)

        # Test if we are currently creating an Archetype object
        if IFactoryTempFolder.providedBy(aq_parent(folder)):
            folder = aq_parent(aq_parent(aq_parent(folder)))
        if not IFolderish.providedBy(folder):
            folder = aq_parent(folder)

        if IPloneSiteRoot.providedBy(folder):
            initial = None
        else:
            initial = IUUID(folder, None)

        portal = get_portal()
        portal_url = portal.absolute_url()
        current_path = folder.absolute_url()[len(portal_url):]

        image_types = settings.image_objects or []

        server_url = self.request.get('SERVER_URL', '')
        site_path = portal_url[len(server_url):]

        related_items_config = get_relateditems_options(
            context=self.context,
            value=None,
            separator=';',
            vocabulary_name='plone.app.vocabularies.Catalog',
            vocabulary_view='@@getVocabulary',
            field_name=None
        )
        related_items_config = call_callables(
            related_items_config,
            self.context
        )

        configuration = {
            'base_url': self.context.absolute_url(),
            'imageTypes': image_types,
            'imageScales': self.image_scales,
            'linkAttribute': 'UID',
            # This is for loading the languages on tinymce
            'loadingBaseUrl': '{}/++plone++static/components/tinymce-builded/'
                              'js/tinymce'.format(portal_url),
            'relatedItems': related_items_config,
            'prependToScalePart': '/@@images/image/',
            'prependToUrl': '{}/resolveuid/'.format(site_path.rstrip('/')),
            'tiny': generator.get_tiny_config(),
            'upload': {
                'baseUrl': portal_url,
                'currentPath': current_path,
                'initialFolder': initial,
                'maxFiles': 1,
                'relativePath': '@@fileUpload',
                'showTitle': False,
                'uploadMultiple': False,
            },
        }
        return {'data-pat-tinymce': json.dumps(configuration)}
Exemplo n.º 13
0
    def tinymce(self):
        """
        data-pat-tinymce : JSON.stringify({
            relatedItems: {
              vocabularyUrl: config.portal_url +
                '/@@getVocabulary?name=plone.app.vocabularies.Catalog'
            },
            tiny: config,
            prependToUrl: 'resolveuid/',
            linkAttribute: 'UID',
            prependToScalePart: '/@@images/image/'
          })
        """

        generator = TinyMCESettingsGenerator(self.context, self.request)
        settings = generator.settings
        folder = aq_inner(self.context)

        # Test if we are currently creating an Archetype object
        if IFactoryTempFolder.providedBy(aq_parent(folder)):
            folder = aq_parent(aq_parent(aq_parent(folder)))
        if not IFolderish.providedBy(folder):
            folder = aq_parent(folder)

        if IPloneSiteRoot.providedBy(folder):
            initial = None
        else:
            initial = IUUID(folder, None)

        portal = get_portal()
        portal_url = portal.absolute_url()
        current_path = folder.absolute_url()[len(portal_url):]

        image_types = settings.image_objects or []

        server_url = self.request.get("SERVER_URL", "")
        site_path = portal_url[len(server_url):]

        related_items_config = get_relateditems_options(
            context=self.context,
            value=None,
            separator=";",
            vocabulary_name="plone.app.vocabularies.Catalog",
            vocabulary_view="@@getVocabulary",
            field_name=None,
        )
        related_items_config = call_callables(related_items_config,
                                              self.context)

        configuration = {
            "base_url":
            self.context.absolute_url(),
            "imageTypes":
            image_types,
            "imageScales":
            self.image_scales,
            "linkAttribute":
            "UID",
            # This is for loading the languages on tinymce
            "loadingBaseUrl":
            "{}/++plone++static/components/tinymce-builded/"
            "js/tinymce".format(portal_url),
            "relatedItems":
            related_items_config,
            "prependToScalePart":
            "/@@images/image/",
            "prependToUrl":
            "{}/resolveuid/".format(site_path.rstrip("/")),
            "tiny":
            generator.get_tiny_config(),
            "upload": {
                "baseUrl": portal_url,
                "currentPath": current_path,
                "initialFolder": initial,
                "maxFiles": 1,
                "relativePath": "@@fileUpload",
                "showTitle": False,
                "uploadMultiple": False,
            },
        }
        return {"data-pat-tinymce": json.dumps(configuration)}
Exemplo n.º 14
0
    def tinymce(self):
        """
        data-pat-tinymce : JSON.stringify({
            relatedItems: {
              vocabularyUrl: config.portal_url +
                '/@@getVocabulary?name=plone.app.vocabularies.Catalog'
            },
            tiny: config,
            prependToUrl: 'resolveuid/',
            linkAttribute: 'UID',
            prependToScalePart: '/@@images/image/'
          })
        """

        generator = TinyMCESettingsGenerator(self.context, self.request)
        settings = generator.settings
        folder = aq_inner(self.context)

        # Test if we are currently creating an Archetype object
        if IFactoryTempFolder.providedBy(aq_parent(folder)):
            folder = aq_parent(aq_parent(aq_parent(folder)))
        if not IFolderish.providedBy(folder):
            folder = aq_parent(folder)

        if IPloneSiteRoot.providedBy(folder):
            initial = None
        else:
            initial = IUUID(folder, None)

        portal = get_portal()
        portal_url = portal.absolute_url()
        current_path = folder.absolute_url()[len(portal_url):]

        image_types = settings.image_objects or []

        server_url = self.request.get('SERVER_URL', '')
        site_path = portal_url[len(server_url):]

        related_items_config = get_relateditems_options(
            context=self.context,
            value=None,
            separator=';',
            vocabulary_name='plone.app.vocabularies.Catalog',
            vocabulary_view='@@getVocabulary',
            field_name=None
        )
        related_items_config = call_callables(
            related_items_config,
            self.context
        )

        configuration = {
            'base_url': self.context.absolute_url(),
            'imageTypes': image_types,
            'imageScales': self.image_scales,
            'linkAttribute': 'UID',
            # This is for loading the languages on tinymce
            'loadingBaseUrl': '{0}/++plone++static/components/tinymce-builded/'
                              'js/tinymce'.format(portal_url),
            'relatedItems': related_items_config,
            'prependToScalePart': '/@@images/image/',
            'prependToUrl': '{0}/resolveuid/'.format(site_path.rstrip('/')),
            'tiny': generator.get_tiny_config(),
            'upload': {
                'baseUrl': portal_url,
                'currentPath': current_path,
                'initialFolder': initial,
                'maxFiles': 1,
                'relativePath': '@@fileUpload',
                'showTitle': False,
                'uploadMultiple': False,
            },
        }
        return {'data-pat-tinymce': json.dumps(configuration)}