Ejemplo n.º 1
0
    def __call__(self):
        context = aq_inner(self.context)

        manager = IDynamicViewManager(context)
        layout = manager.getLayout()

        if not layout:
            layout, title = manager.getDefaultLayout()

        if ICollageAlias.providedBy(context):
            context = context.get_target()

            # if not set, revert to self.context
            if not context:
                context = self.context

        # transmute request interfaces
        ifaces = mark_request(self.context, self.request)

        view = getMultiAdapter((context, self.request), name=layout)

        # restore interfaces
        directlyProvides(self.request, ifaces)

        return view.index
    def __call__(self):
        context = aq_inner(self.context)
        
        manager = IDynamicViewManager(context)
        layout = manager.getLayout()

        if not layout:
            layout, title = manager.getDefaultLayout()

        if ICollageAlias.providedBy(context):
            context = context.get_target()
            
            # if not set, revert to self.context
            if not context: context = self.context

        # transmute request interfaces
        ifaces = directlyProvidedBy(self.request)
        directlyProvides(self.request, ICollageBrowserLayer)

        view = getMultiAdapter((context, self.request), name=layout)

        # restore interfaces
        directlyProvides(self.request, ifaces)

        return view.index
Ejemplo n.º 3
0
    def getLayouts(self):
        context = self.context

        # handle aliased objects
        alias = getattr(self.__parent__, '__alias__', None)
        if alias:
            context = alias

        manager = IDynamicViewManager(context)

        # lookup active layout
        active = manager.getLayout()

        if not active:
            active, _title = manager.getDefaultLayout()

        # compile list of registered layouts
        layouts = manager.getLayouts()

        # filter out fallback view
        layouts = filter(lambda name_title: name_title[0] != u'fallback',
                         layouts)

        # make sure the active layout (which may not be available) is
        # included
        if active not in [name for name, title in layouts]:
            layouts.append(
                (active, _(u"Missing: $name", mapping={'name': active})))

        return [{
            'id': name,
            'name': title,
            'active': name == active
        } for (name, title) in layouts]
Ejemplo n.º 4
0
    def getLayouts(self):
        context = self.context

        # handle aliased objects
        alias = getattr(self.__parent__, '__alias__', None)
        if alias: context = alias

        manager = IDynamicViewManager(context)

        # lookup active layout
        active = manager.getLayout()

        if not active:
            active, title = manager.getDefaultLayout()

        # compile list of registered layouts
        layouts = manager.getLayouts()

        # filter out fallback view
        layouts = filter(lambda (name, title): name != u'fallback', layouts)

        # make sure the active layout (which may not be available) is
        # included
        if active not in [name for name, title in layouts]:
            layouts.append(
                (active, _(u"Missing: $name", mapping={'name': active})))

        return [{
            'id': name,
            'name': title,
            'active': name == active} for (name, title) in layouts]
    def render_embedded_view(self):
        try:
            return EmbeddedPFGView.__call__(self)
        except Retry:
            # a retry-exception is raised in order for the thank-you
            # page to be rendered; we need to intercept this and do
            # our own rendering of this page
            # and take care in case there's a virtual host monster request involved

            path_translated = self.request._orig_env['PATH_TRANSLATED']

            if 'VirtualHostRoot' in path_translated:
                # Eliminate /VirtualHostBase/ and /VirtualHostRoot parts
                nodes = path_translated.replace('/VirtualHostBase/','').replace('/VirtualHostRoot','').split('/')
                # Eliminates the protocol and server parts
                nodes = nodes[2:]
                path_translated = '/'.join(nodes)

            context = self.context.unrestrictedTraverse(path_translated)
            manager = IDynamicViewManager(context)

            layout = manager.getLayout()
            if not layout:
                layout, title = manager.getDefaultLayout()

            ifaces = mark_request(self.context, self.request)
            view = component.getMultiAdapter((context, self.request), name=layout)
            interface.directlyProvides(self.request, ifaces)

            return view()
    def getItems(self, contents=None):
        # needed to circumvent bug :-(
        self.request.debug = False

        # transmute request interfaces
        ifaces = directlyProvidedBy(self.request)
        directlyProvides(self.request, ICollageBrowserLayer)

        views = []

        if not contents:
            contents = self.context.folderlistingFolderContents()

        for context in contents:
            target = context
            manager = IDynamicViewManager(context)
            layout = manager.getLayout()

            if not layout:
                layout, title = manager.getDefaultLayout()

            if ICollageAlias.providedBy(context):
                target = context.get_target()

                # if not set, revert to context
                if target is None:
                    target = context

                # verify that target is accessible
                try:
                    getSecurityManager().validate(self, self, target.getId(), target)
                except Unauthorized:
                    continue

            # Filter out translation duplicates:
            # If a non-alias object is translatable, check if its language
            # is set to the currently selected language or to neutral,
            # or if it is the canonical version
            elif isTranslatable(target):
                language = self.request.get('LANGUAGE','')
                if target.Language() not in (language, ''):
                    # Discard the object, if it is not the canonical version
                    # or a translation is available in the requested language.
                    if not target.isCanonical() or target.getTranslation(language) in contents:
                        continue

            # assume that a layout is always available
            view = getMultiAdapter((target, self.request), name=layout)

            # store reference to alias if applicable
            if ICollageAlias.providedBy(context):
                view.__alias__ = context

            views.append(view)

        # restore interfaces
        directlyProvides(self.request, ifaces)

        return views
    def getLayouts(self):
        context = self.context

        # handle aliased objects
        alias = getattr(self.__parent__, '__alias__', None)
        if alias: context = alias

        manager = IDynamicViewManager(context)

        # lookup active layout
        active = manager.getLayout()

        if not active:
            active, title = manager.getDefaultLayout()

        # compile list of registered layouts
        layouts = manager.getLayouts()

        # filter out fallback view
        layouts = filter(lambda (name, title): name != u'fallback', layouts)

        return [{'id': name,
                 'name': title,
                 'active': name == active} for (name, title) in layouts]
Ejemplo n.º 8
0
    def getItems(self, contents=None):
        """Items are a views to render.

        @param contents: If given fetch the folderListingFolderContents of
                         context.
        @return: a list of views ready to render.
        """
        # needed to circumvent bug :-(
        self.request.debug = False

        # transmute request interfaces
        ifaces = mark_request(self.context, self.request)

        views = []
        if contents is None:
            contents = self.getContents()
        for context in contents:
            if context is None:
                continue
            target = context
            manager = IDynamicViewManager(context)
            layout = manager.getLayout()

            if not layout:
                layout, title = manager.getDefaultLayout()

            if ICollageAlias.providedBy(context):
                target = context.get_target()

                # if not set, revert to context
                if target is None:
                    target = context

                # verify that target is accessible
                try:
                    getSecurityManager().validate(self, self, target.getId(), target)
                except Unauthorized:
                    continue

            # Filter out translation duplicates:
            # If a non-alias object is translatable, check if its language
            # is set to the currently selected language or to neutral,
            # or if it is the canonical version
            elif isTranslatable(target):
                language = self.request.get('LANGUAGE','')
                if target.Language() not in (language, ''):
                    # Discard the object, if it is not the canonical version
                    # or a translation is available in the requested language.
                    if not target.isCanonical() or target.getTranslation(language) in contents:
                        continue
                # If the target is a translation, get the layout defined on the canonical
                # object, unless a layout has already been defined on the translation.
                # Fallback to default layout.
                if not target.isCanonical():
                    canmanager = IDynamicViewManager(target.getCanonical())
                    layout = manager.getLayout() or canmanager.getLayout() or layout

            # don't assume that a layout is always available; note
            # that we can't use ``queryMultiAdapter`` because even
            # this lookup might fail hard
            try:
                view = getMultiAdapter((target, self.request), name=layout)
            except ComponentLookupError:
                view = getMultiAdapter(
                    (target, self.request), name='error_collage-view-not-found')
                view.notfoundlayoutname = layout

            # store reference to alias if applicable
            if ICollageAlias.providedBy(context):
                view.__alias__ = context

            views.append(view)

        # restore interfaces
        directlyProvides(self.request, ifaces)
        return views
Ejemplo n.º 9
0
    def getItems(self, contents=None):
        """Items are a views to render.

        @param contents: If given fetch the folderListingFolderContents of
                         context.
        @return: a list of views ready to render.
        """
        # needed to circumvent bug :-(
        self.request.debug = False

        # transmute request interfaces
        ifaces = mark_request(self.context, self.request)

        views = []
        if contents is None:
            contents = self.getContents()
        for context in contents:
            if context is None:
                continue
            target = context
            manager = IDynamicViewManager(context)
            layout = manager.getLayout()

            if not layout:
                layout, title = manager.getDefaultLayout()

            if ICollageAlias.providedBy(context):
                target = context.get_target()

                # if not set, revert to context
                if target is None:
                    target = context

                # verify that target is accessible
                try:
                    getSecurityManager().validate(self, self, target.getId(),
                                                  target)
                except Unauthorized:
                    continue

            # Filter out translation duplicates:
            # If a non-alias object is translatable, check if its language
            # is set to the currently selected language or to neutral,
            # or if it is the canonical version
            elif isTranslatable(target):
                language = self.request.get('LANGUAGE', '')
                if target.Language() not in (language, ''):
                    # Discard the object, if it is not the canonical version
                    # or a translation is available in the requested language.
                    if (not target.isCanonical()
                            or target.getTranslation(language) in contents):
                        continue
                # If the target is a translation, get the layout defined on
                # the canonical object, unless a layout has already been
                # defined on the translation.
                # Fallback to default layout.
                if not target.isCanonical():
                    canmanager = IDynamicViewManager(target.getCanonical())
                    layout = (manager.getLayout() or canmanager.getLayout()
                              or layout)

            # don't assume that a layout is always available; note
            # that we can't use ``queryMultiAdapter`` because even
            # this lookup might fail hard
            try:
                view = getMultiAdapter((target, self.request), name=layout)
            except ComponentLookupError:
                view = getMultiAdapter((target, self.request),
                                       name='error_collage-view-not-found')
                view.notfoundlayoutname = layout

            # store reference to alias if applicable
            if ICollageAlias.providedBy(context):
                view.__alias__ = context

            views.append(view)

        # restore interfaces
        directlyProvides(self.request, ifaces)
        return views
Ejemplo n.º 10
0
    def getItems(self, contents=None):
        # needed to circumvent bug :-(
        self.request.debug = False

        # transmute request interfaces
        ifaces = directlyProvidedBy(self.request)
        directlyProvides(self.request, ICollageBrowserLayer)

        views = []

        if not contents:
            contents = self.context.folderlistingFolderContents()

        # make sure the languager passed in via set_language is applied correctly
        plt = getToolByName(self.context, 'portal_languages')
        binding = self.request.get('LANGUAGE_TOOL', None)
        language = self.request.get('set_language', plt.getPreferredLanguage())
        if binding and binding.LANGUAGE != language:
            binding.LANGUAGE = language

        for context in contents:
            target = context
            manager = IDynamicViewManager(context)
            layout = manager.getLayout()

            if not layout:
                layout, title = manager.getDefaultLayout()

            if ICollageAlias.providedBy(context):
                target = context.get_target()

                # if not set, revert to context
                if target is None:
                    target = context

                # verify that target is accessible
                try:
                    getSecurityManager().validate(self, self, target.getId(),
                                                  target)
                except Unauthorized:
                    continue

            # Filter out translation duplicates:
            # If a non-alias object is translatable, check if its language
            # is set to the currently selected language or to neutral,
            # or if it is the canonical version
            elif isTranslatable(target):
                language = self.request.get('LANGUAGE', '')
                if target.Language() not in (language, ''):
                    # Discard the object, if it is not the canonical version
                    # or a translation is available in the requested language.
                    if not target.isCanonical() or target.getTranslation(
                            language) in contents:
                        continue
                # If the target is a translation, get the layout defined on the canonical
                # object, unless a layout has already been defined on the translation.
                # Fallback to default layout.
                if not target.isCanonical():
                    canmanager = IDynamicViewManager(target.getCanonical())
                    layout = manager.getLayout() or canmanager.getLayout(
                    ) or layout

            # assume that a layout is always available
            view = getMultiAdapter((target, self.request), name=layout)

            # store reference to alias if applicable
            if ICollageAlias.providedBy(context):
                view.__alias__ = context

            view._collage_context = self.getCollageContext(self.context)
            views.append(view)

        # restore interfaces
        directlyProvides(self.request, ifaces)

        return views
Ejemplo n.º 11
0
    def getItems(self, contents=None):
        # needed to circumvent bug :-(
        self.request.debug = False

        # transmute request interfaces
        ifaces = directlyProvidedBy(self.request)
        directlyProvides(self.request, ICollageBrowserLayer)

        views = []

        if not contents:
            contents = self.context.folderlistingFolderContents()

        # make sure the languager passed in via set_language is applied correctly
        plt = getToolByName(self.context, 'portal_languages')
        binding = self.request.get('LANGUAGE_TOOL', None)
        language = self.request.get('set_language', plt.getPreferredLanguage())
        if binding and binding.LANGUAGE != language:
            binding.LANGUAGE = language

        for context in contents:
            target = context
            manager = IDynamicViewManager(context)
            layout = manager.getLayout()

            if not layout:
                layout, title = manager.getDefaultLayout()

            if ICollageAlias.providedBy(context):
                target = context.get_target()

                # if not set, revert to context
                if target is None:
                    target = context

                # verify that target is accessible
                try:
                    getSecurityManager().validate(self, self, target.getId(), target)
                except Unauthorized:
                    continue

            # Filter out translation duplicates:
            # If a non-alias object is translatable, check if its language
            # is set to the currently selected language or to neutral,
            # or if it is the canonical version
            elif isTranslatable(target):
                language = self.request.get('LANGUAGE','')
                if target.Language() not in (language, ''):
                    # Discard the object, if it is not the canonical version
                    # or a translation is available in the requested language.
                    if not target.isCanonical() or target.getTranslation(language) in contents:
                        continue
                # If the target is a translation, get the layout defined on the canonical
                # object, unless a layout has already been defined on the translation.
                # Fallback to default layout.
                if not target.isCanonical():
                    canmanager = IDynamicViewManager(target.getCanonical())
                    layout = manager.getLayout() or canmanager.getLayout() or layout

            # assume that a layout is always available
            view = getMultiAdapter((target, self.request), name=layout)

            # store reference to alias if applicable
            if ICollageAlias.providedBy(context):
                view.__alias__ = context


            view._collage_context = self.getCollageContext(self.context)
            views.append(view)

        # restore interfaces
        directlyProvides(self.request, ifaces)

        return views