Example #1
0
    def subsite_logo_behaviour(self):
        # Copy of ftw.subsite.viewlets.subsitelogoviewlet
        self.navigation_root_url = self.portal_state.navigation_root_url()
        portal = self.portal_state.portal()

        subsite_logo = getattr(self.context, 'getLogo', None)
        in_factory = IFactoryTempFolder.providedBy(
            self.context.aq_inner.aq_parent)

        if subsite_logo and subsite_logo() and not in_factory:
            # we are in a subsite
            navigation_root_path = self.portal_state.navigation_root_path()

            self.title = self.context.restrictedTraverse(
                getNavigationRoot(self.context)).Title()

            scales = portal.restrictedTraverse(navigation_root_path +
                                               '/@@images')
            # Create our own tag, because we want to prune the title attr
            scale = scales.scale('logo', scale="logo")
            self.logo_tag = ('<img src="{url}" width="{width}" '
                             'height="{height}" alt="{alt}" />'.format(
                                 **dict(url=scale.url,
                                        width=scale.width,
                                        height=scale.height,
                                        alt=self.navigation_root_title)))
        else:
            # onegov default
            self.onegov_logo_behaviour()
Example #2
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)
        current_path = folder.absolute_url()[len(generator.portal_url):]

        image_types = settings.image_objects or []
        folder_types = settings.contains_objects or []
        configuration = {
            'relatedItems': {
                'vocabularyUrl':
                    '%s/@@getVocabulary?name=plone.app.vocabularies.Catalog' % (
                        generator.portal_url)
            },
            'upload': {
                'initialFolder': initial,
                'currentPath': current_path,
                'baseUrl': generator.portal_url,
                'relativePath': '@@fileUpload',
                'uploadMultiple': False,
                'maxFiles': 1,
                'showTitle': False
            },
            'base_url': self.context.absolute_url(),
            'tiny': generator.get_tiny_config(),
            # This is for loading the languages on tinymce
            'loadingBaseUrl': '%s/++plone++static/components/tinymce-builded/js/tinymce' % generator.portal_url,  # noqa
            'prependToUrl': '{0}/resolveuid/'.format(generator.portal_url),
            'linkAttribute': 'UID',
            'prependToScalePart': '/@@images/image/',
            'folderTypes': folder_types,
            'imageTypes': image_types
            # 'anchorSelector': utility.anchor_selector,
        }

        return {'data-pat-tinymce': json.dumps(configuration)}
Example #3
0
    def subsite_logo_behaviour(self):
        # Copy of ftw.subsite.viewlets.subsitelogoviewlet
        self.navigation_root_url = self.portal_state.navigation_root_url()
        portal = self.portal_state.portal()

        subsite_logo = getattr(self.context, 'getLogo', None)
        in_factory = IFactoryTempFolder.providedBy(
            self.context.aq_inner.aq_parent)

        if subsite_logo and subsite_logo() and not in_factory:
            # we are in a subsite
            navigation_root_path = self.portal_state.navigation_root_path()

            self.title = self.context.restrictedTraverse(
                getNavigationRoot(self.context)).Title()

            scales = portal.restrictedTraverse(
                navigation_root_path + '/@@images')
            # Create our own tag, because we want to prune the title attr
            scale = scales.scale('logo', scale="logo")
            self.logo_tag = ('<img src="{url}" width="{width}" '
                             'height="{height}" alt="{alt}" />'.format(
                                 **dict(url=scale.url,
                                        width=scale.width,
                                        height=scale.height,
                                        alt=self.navigation_root_title)))
        else:
            # onegov default
            self.onegov_logo_behaviour()
Example #4
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)
        current_path = folder.absolute_url()[len(generator.portal_url):]

        image_types = settings.image_objects or []
        folder_types = settings.contains_objects or []
        configuration = {
            'relatedItems': {
                'vocabularyUrl':
                    '%s/@@getVocabulary?name=plone.app.vocabularies.Catalog' % (
                        generator.portal_url),
                'folderTypes': folder_types
            },
            'upload': {
                'initialFolder': initial,
                'currentPath': current_path,
                'baseUrl': generator.portal_url,
                'relativePath': '@@fileUpload',
                'uploadMultiple': False,
                'maxFiles': 1,
                'showTitle': False
            },
            'base_url': self.context.absolute_url(),
            'tiny': generator.get_tiny_config(),
            # This is for loading the languages on tinymce
            'loadingBaseUrl': '%s/++plone++static/components/tinymce-builded/js/tinymce' % generator.portal_url,  # noqa
            'prependToUrl': '{0}/resolveuid/'.format(generator.portal_url),
            'linkAttribute': 'UID',
            'prependToScalePart': '/@@images/image/',
            'imageTypes': image_types
            # 'anchorSelector': utility.anchor_selector,
        }

        return {'data-pat-tinymce': json.dumps(configuration)}
Example #5
0
    def has_items(self, voc_name):
        factory = getUtility(IVocabularyFactory, name=voc_name)
        parent = aq_parent(self)
        obj = self
        if IFactoryTempFolder.providedBy(parent):
            obj = aq_parent(aq_parent(parent))

        return len([term for term in factory(obj) if term.value])
Example #6
0
    def tinymce(self):
        generator = CastleTinyMCESettingsGenerator(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)
        current_path = folder.absolute_url()[len(generator.portal_url):]

        scales = []
        for name, info in sorted(getAllowedSizes().items(), key=lambda x: x[1][0]):
            scales.append({
                'part': name,
                'name': name,
                'label': '{} ({}x{})'.format(
                    name.capitalize(),
                    info[0],
                    info[1])
            })
        image_types = settings.image_objects or []
        folder_types = settings.contains_objects or []
        configuration = {
            'relatedItems': {
                'vocabularyUrl':
                    '%s/@@getVocabulary?name=plone.app.vocabularies.Catalog' % (
                        generator.portal_url)
            },
            'upload': {
                'initialFolder': initial,
                'currentPath': current_path,
                'baseUrl': generator.portal_url,
                'relativePath': '@@fileUpload',
                'uploadMultiple': False,
                'maxFiles': 1,
                'showTitle': False
            },
            'base_url': self.context.absolute_url(),
            'tiny': generator.get_tiny_config(),
            # This is for loading the languages on tinymce
            'loadingBaseUrl': '%s/++plone++static/components/tinymce-builded/js/tinymce' % generator.portal_url,  # noqa
            'prependToUrl': 'resolveuid/',
            'linkAttribute': 'UID',
            'prependToScalePart': '/@@images/image/',
            'folderTypes': folder_types,
            'imageTypes': image_types,
            'scales': scales
        }

        return {'data-pat-tinymce': json.dumps(configuration)}
    def _translations(self, missing):
        # Figure out the "closest" translation in the parent chain of the
        # context. We stop at both an INavigationRoot or an ISiteRoot to look
        # for translations. We do want to find something that is definitely
        # in the language the user asked for.
        context = aq_inner(self.context)
        translations = {}
        chain = aq_chain(context)
        first_pass = True
        _checkPermission = getSecurityManager().checkPermission
        for item in chain:
            if ISiteRoot.providedBy(item):
                # We have a site root, which works as a fallback
                has_view_permission = bool(_checkPermission('View', item))
                for c in missing:
                    translations[c] = (item, first_pass, has_view_permission)
                break

            elif IFactoryTempFolder.providedBy(item) or \
                    IFactoryTool.providedBy(item):
                # TempFolder or portal_factory, can't have a translation
                continue

            canonical = ITranslationManager(item, None)

            item_trans = canonical.get_translations()
            for code, trans in item_trans.items():
                code = str(code)
                if code not in translations:
                    # make a link to a translation only if the user
                    # has view permission
                    has_view_permission = bool(_checkPermission('View', trans))
                    if (not INavigationRoot.providedBy(item)
                            and not has_view_permission):
                        continue
                    # If we don't yet have a translation for this language
                    # add it and mark it as found
                    translations[code] = (trans, first_pass,
                            has_view_permission)
                    missing = missing - set((code, ))

            if len(missing) <= 0:
                # We have translations for all
                break
            if INavigationRoot.providedBy(item):
                # Don't break out of the navigation root jail
                has_view_permission = bool(_checkPermission('View', item))
                for c in missing:
                    translations[c] = (item, False, has_view_permission)
                break
            first_pass = False
        # return a dict of language code to tuple. the first tuple element is
        # the translated object, the second argument indicates wether the
        # translation is a direct translation of the context or something from
        # higher up the translation chain
        return translations
    def _translations(self, missing):
        # Figure out the "closest" translation in the parent chain of the
        # context. We stop at both an INavigationRoot or an ISiteRoot to look
        # for translations. We do want to find something that is definitely
        # in the language the user asked for.
        context = aq_inner(self.context)
        translations = {}
        chain = aq_chain(context)
        first_pass = True
        _checkPermission = getSecurityManager().checkPermission
        for item in chain:
            if ISiteRoot.providedBy(item):
                # We have a site root, which works as a fallback
                has_view_permission = bool(_checkPermission('View', item))
                for c in missing:
                    translations[c] = (item, first_pass, has_view_permission)
                break

            elif IFactoryTempFolder.providedBy(item) or \
                    IFactoryTool.providedBy(item):
                # TempFolder or portal_factory, can't have a translation
                continue

            canonical = ITranslationManager(item, None)

            item_trans = canonical.get_translations()
            for code, trans in item_trans.items():
                code = str(code)
                if code not in translations:
                    # make a link to a translation only if the user
                    # has view permission
                    has_view_permission = bool(_checkPermission('View', trans))
                    if (not INavigationRoot.providedBy(item)
                            and not has_view_permission):
                        continue
                    # If we don't yet have a translation for this language
                    # add it and mark it as found
                    translations[code] = (trans, first_pass,
                                          has_view_permission)
                    missing = missing - set((code, ))

            if len(missing) <= 0:
                # We have translations for all
                break
            if INavigationRoot.providedBy(item):
                # Don't break out of the navigation root jail
                has_view_permission = bool(_checkPermission('View', item))
                for c in missing:
                    translations[c] = (item, False, has_view_permission)
                break
            first_pass = False
        # return a dict of language code to tuple. the first tuple element is
        # the translated object, the second argument indicates wether the
        # translation is a direct translation of the context or something from
        # higher up the translation chain
        return translations
Example #9
0
 def __init__(self, context, request, view, manager, data):
     self.context = context
     self.request = request
     self.parent = aq_parent(aq_inner(context))
     plone = getMultiAdapter((context, request), name="plone")
     self.is_default_page = plone.isDefaultPageInFolder()
     in_factory = IFactoryTempFolder.providedBy(
         self.parent)
     if in_factory:
         self.parent = aq_parent(aq_parent(aq_inner(self.parent)))
     elif self.is_default_page:
         self.parent = aq_parent(aq_inner(self.parent))
Example #10
0
    def __init__(self, context, request, view, manager, data):
        self.context = context
        self.request = request
        self.parent = aq_parent(aq_inner(context))
        self.data = data
        plone = getMultiAdapter((context, request), name="plone")
        self.is_default_page = plone.isDefaultPageInFolder()
        in_factory = IFactoryTempFolder.providedBy(self.parent)
        if in_factory:
            self.parent = aq_parent(aq_parent(aq_inner(self.parent)))
        elif self.is_default_page:
            self.parent = aq_parent(aq_inner(self.parent))

        properties = getToolByName(self.context, "portal_properties")
        self.hidden_types = properties.navtree_properties.metaTypesNotToList
Example #11
0
    def __init__(self, obj, event):
        super(AddMoveCopy, self).__init__(obj, event)

        # Do nothing if we are in the factory
        if IFactoryTempFolder.providedBy(self.parent):
            return None

        # Move
        if self.event.oldParent and self.event.newParent:
            self.mark()

            self.parent = self.event.oldParent
            self.unmark()

        # Copy / Add
        if self.event.newParent and not self.event.oldParent:
            self.mark()
Example #12
0
    def __init__(self, context, request, view, manager, data):
        self.context = context
        self.request = request
        self.parent = aq_parent(aq_inner(context))
        self.data = data
        plone = getMultiAdapter((context, request), name="plone")
        self.is_default_page = plone.isDefaultPageInFolder()
        in_factory = IFactoryTempFolder.providedBy(self.parent)
        if in_factory:
            self.parent = aq_parent(aq_parent(aq_inner(self.parent)))
        elif self.is_default_page:
            self.parent = aq_parent(aq_inner(self.parent))

        properties = getToolByName(self.context, 'portal_properties')
        self.hidden_types = properties.navtree_properties.metaTypesNotToList
        self.view_action_types = properties.site_properties.getProperty(
            'typesUseViewActionInListings', ())
Example #13
0
    def subsite_logo_behaviour(self):
        # Copy of ftw.subsite.viewlets.subsitelogoviewlet
        self.navigation_root_url = self.portal_state.navigation_root_url()

        subsite_logo = getattr(self.context, 'getLogo', None)
        in_factory = IFactoryTempFolder.providedBy(
            self.context.aq_inner.aq_parent)

        if subsite_logo and subsite_logo() and not in_factory:
            # we are in a subsite
            navigation_root_path = self.portal_state.navigation_root_path()

            self.title = self.context.restrictedTraverse(
                getNavigationRoot(self.context)).Title()

            self.logo_tag = "<img src='%s/logo' alt='%s Logo' />" % (
                navigation_root_path, self.title)

        else:
            # onegov default
            self.onegov_logo_behaviour()
Example #14
0
    def subsite_logo_behaviour(self):
        # Copy of ftw.subsite.viewlets.subsitelogoviewlet
        self.navigation_root_url = self.portal_state.navigation_root_url()

        subsite_logo = getattr(self.context, 'getLogo', None)
        in_factory = IFactoryTempFolder.providedBy(
            self.context.aq_inner.aq_parent)

        if subsite_logo and subsite_logo() and not in_factory:
            # we are in a subsite
            navigation_root_path = self.portal_state.navigation_root_path()

            self.title = self.context.restrictedTraverse(
                getNavigationRoot(self.context)).Title()

            self.logo_tag = "<img src='%s/logo' alt='%s Logo' />" % (
                navigation_root_path,
                self.title)

        else:
            # onegov default
            self.onegov_logo_behaviour()
Example #15
0
def find_quota_parent(parent):
    """ Find the first parent container that has quota support.
    """

    obj = parent
    while obj:
        if IFactoryTempFolder.providedBy(obj):
            # Go up twice
            obj = aq_parent(aq_parent(aq_inner(obj)))

        if not IBaseObject.providedBy(obj):
            return None

        elif ISiteRoot.providedBy(obj):
            return None

        elif IQuotaSupport.providedBy(obj):
            return obj

        else:
            obj = aq_parent(aq_inner(obj))

    return None
Example #16
0
 def getDefaultAddressTitle(self):
     parent = aq_parent(self)
     if IFactoryTempFolder.providedBy(parent):
         parent = aq_parent(aq_parent(parent))
     return parent.Title()
    def getClosestDestination(self):
        """Get the "closest translated object" URL.
        """
        # We should travel the parent chain using the catalog here,
        # but I think using the acquisition chain is faster
        # (or well, __parent__ pointers) because the catalog
        # would require a lot of queries, while technically,
        # having done traversal up to this point you should
        # have the objects in memory already

        # As we don't have any content object we are going to look
        # for the best option

        site = getSite()
        root = getToolByName(site, 'portal_url')
        ltool = getToolByName(site, 'portal_languages')

        # We are using TranslationManager to get the translations of a
        # string tg
        manager = TranslationManager(self.tg)
        context = None
        languages = manager.get_translations()
        if len(languages) == 0:
            # If there is no results there are no translations
            # we move to portal root
            return self.wrapDestination(root(), postpath=False)

        # We are going to see if there is the preferred language translation
        # Otherwise we get the first as context to look for translation
        prefered = ltool.getPreferredLanguage(self.request)
        if prefered in languages:
            context = languages[prefered]
        else:
            context = languages[languages.keys()[0]]

        checkPermission = getSecurityManager().checkPermission
        chain = self.getParentChain(context)
        for item in chain:
            if ISiteRoot.providedBy(item) \
               and not ILanguageRootFolder.providedBy(item):
                # We do not care to get a permission error
                # if the whole of the portal cannot be viewed.
                # Having a permission issue on the root is fine;
                # not so much for everything else so that is checked there
                return self.wrapDestination(item.absolute_url())
            elif IFactoryTempFolder.providedBy(item) or \
                    IFactoryTool.providedBy(item):
                # TempFolder or portal_factory, can't have a translation
                continue
            try:
                canonical = ITranslationManager(item)
            except TypeError:
                if not ITranslatable.providedBy(item):
                    # In case there it's not translatable go to parent
                    # This solves the problem when a parent is not
                    # ITranslatable
                    continue
                else:
                    raise
            translation = canonical.get_translation(self.lang)
            if translation and (
                INavigationRoot.providedBy(translation) or
                bool(checkPermission('View', translation))
            ):
                # Not a direct translation, therefore no postpath
                # (the view might not exist on a different context)
                return self.wrapDestination(translation.absolute_url(),
                                            postpath=False)
        # Site root's the fallback
        return self.wrapDestination(root(), postpath=False)
    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)}
Example #19
0
    def _get_translations_by_closest(self, supported_langs):
        """ Return the translations information by
            figuring out the 'closest' translation in the parent chain of the
            context. We stop at both an INavigationRoot or an ISiteRoot to look
            for translations. We do want to find something that is definitely
            in the language the user asked for regardless anything else.
        """
        context = aq_inner(self.context)
        missing = set([str(c) for c in supported_langs])
        translations = {}
        chain = aq_chain(context)
        first_pass = True
        _checkPermission = getSecurityManager().checkPermission
        for item in chain:
            if ISiteRoot.providedBy(item):
                # We have a site root, which works as a fallback
                has_view_permission = bool(_checkPermission('View', item))
                for c in missing:
                    translations[c] = (item, first_pass, has_view_permission)
                break

            elif IFactoryTempFolder.providedBy(item) or \
                    IFactoryTool.providedBy(item):
                # TempFolder or portal_factory, can't have a translation
                continue

            try:
                canonical = ITranslationManager(item)
            except TypeError:
                if not ITranslatable.providedBy(item):
                    # In case there it's not translatable go to parent
                    # This solves the problem when a parent is not ITranslatable
                    continue
                else:
                    raise

            item_trans = canonical.get_translations()
            for code, trans in item_trans.items():
                code = str(code)
                if code not in translations:
                    # make a link to a translation only if the user
                    # has view permission
                    has_view_permission = bool(_checkPermission('View', trans))
                    if (not INavigationRoot.providedBy(item)
                            and not has_view_permission):
                        continue
                    # If we don't yet have a translation for this language
                    # add it and mark it as found
                    translations[code] = (trans, first_pass,
                            has_view_permission)
                    missing = missing - set((code, ))

            if len(missing) <= 0:
                # We have translations for all
                break
            if INavigationRoot.providedBy(item):
                # Don't break out of the navigation root jail
                has_view_permission = bool(_checkPermission('View', item))
                for c in missing:
                    translations[c] = (item, False, has_view_permission)
                break
            first_pass = False
        # return a dict of language code to tuple. the first tuple element is
        # the translated object, the second argument indicates wether the
        # translation is a direct translation of the context or something from
        # higher up the translation chain
        return translations
Example #20
0
    def getClosestDestination(self):
        """Get the "closest translated object" URL.
        """
        # We should travel the parent chain using the catalog here,
        # but I think using the acquisition chain is faster
        # (or well, __parent__ pointers) because the catalog
        # would require a lot of queries, while technically,
        # having done traversal up to this point you should
        # have the objects in memory already

        # As we don't have any content object we are going to look
        # for the best option

        site = getSite()
        root = getToolByName(site, 'portal_url')
        ltool = getToolByName(site, 'portal_languages')

        # We are using TranslationManager to get the translations of a
        # string tg
        try:
            manager = TranslationManager(self.tg)
            languages = manager.get_translations()
        except AttributeError:
            languages = []
        if len(languages) == 0:
            # If there is no results there are no translations
            # we move to portal root
            return self.wrapDestination(root(), postpath=False)

        # We are going to see if there is the preferred language translation
        # Otherwise we get the first as context to look for translation
        prefered = ltool.getPreferredLanguage(self.request)
        if prefered in languages:
            context = languages[prefered]
        else:
            context = languages[list(languages.keys())[0]]

        checkPermission = getSecurityManager().checkPermission
        chain = self.getParentChain(context)
        for item in chain:
            if ISiteRoot.providedBy(item) \
               and not ILanguageRootFolder.providedBy(item):
                # We do not care to get a permission error
                # if the whole of the portal cannot be viewed.
                # Having a permission issue on the root is fine;
                # not so much for everything else so that is checked there
                return self.wrapDestination(item.absolute_url())
            elif IFactoryTempFolder.providedBy(item) or \
                    IFactoryTool.providedBy(item):
                # TempFolder or portal_factory, can't have a translation
                continue
            try:
                canonical = ITranslationManager(item)
            except TypeError:
                if not ITranslatable.providedBy(item):
                    # In case there it's not translatable go to parent
                    # This solves the problem when a parent is not
                    # ITranslatable
                    continue
                else:
                    raise
            translation = canonical.get_translation(self.lang)
            if translation and (INavigationRoot.providedBy(translation)
                                or bool(checkPermission('View', translation))):
                # Not a direct translation, therefore no postpath
                # (the view might not exist on a different context)
                return self.wrapDestination(translation.absolute_url(),
                                            postpath=False)
        # Site root's the fallback
        return self.wrapDestination(root(), postpath=False)
Example #21
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)}
Example #22
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()
        nav_root = getNavigationRootObject(folder, portal)
        nav_root_url = nav_root.absolute_url()
        current_path = folder.absolute_url()[len(portal_url):]

        image_types = settings.image_objects or []
        folder_types = settings.contains_objects or []

        server_url = self.request.get('SERVER_URL', '')
        site_path = portal_url[len(server_url):]
        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': {
                'folderTypes': folder_types,
                'rootPath': '/'.join(nav_root.getPhysicalPath())
                            if nav_root else '/',
                'sort_on': 'sortable_title',
                'sort_order': 'ascending',
                'vocabularyUrl':
                    '{0}/@@getVocabulary?name=plone.app.vocabularies.'
                    'Catalog'.format(nav_root_url),
            },
            '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)}
Example #23
0
 def is_factory(self):
     return IFactoryTempFolder.providedBy(aq_parent(aq_inner(self.context)))
Example #24
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()
        nav_root = getNavigationRootObject(folder, portal)
        nav_root_url = nav_root.absolute_url()
        current_path = folder.absolute_url()[len(portal_url):]

        image_types = settings.image_objects or []
        folder_types = settings.contains_objects or []

        server_url = self.request.get('SERVER_URL', '')
        site_path = portal_url[len(server_url):]
        configuration = {
            'base_url':
            self.context.absolute_url(),
            'imageTypes':
            image_types,
            'linkAttribute':
            'UID',
            # This is for loading the languages on tinymce
            'loadingBaseUrl':
            '{0}/++plone++static/components/tinymce-builded/'
            'js/tinymce'.format(portal_url),
            'relatedItems': {
                'folderTypes':
                folder_types,
                'rootPath':
                '/'.join(nav_root.getPhysicalPath()) if nav_root else '/',
                'sort_on':
                'sortable_title',
                'sort_order':
                'ascending',
                'vocabularyUrl':
                '{0}/@@getVocabulary?name=plone.app.vocabularies.'
                'Catalog'.format(nav_root_url),
            },
            '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)}
Example #25
0
 def is_factory(self):
     return IFactoryTempFolder.providedBy(
         aq_parent(aq_inner(self.context)))