Exemple #1
0
 def getRoot(self):
     """Get the root obj of the wrapped object.
     """
     try:
         return getRoot(self.obj)
     except TypeError:
         tmp = self.obj
         while getattr(tmp, '__parent__', None):
             tmp = tmp.__parent__
         return tmp
     return
Exemple #2
0
 def getObject(self, some_obj=None, arg_request=None):
     """ get object from dashboard item """
     if self.stype == 'oid':
         my_catalog = zapi.getUtility(ICatalog)
         resultList = my_catalog.searchResults(oid_index=self.value)
         if len(resultList) > 0:
             return iter(resultList).next()
         else:
             return None
     elif self.stype == 'path':
         if some_obj is not None and arg_request is not None:
             return traverse(getRoot(some_obj),
                             self.value,
                             request=arg_request)
     raise Exception, "wrong type for getObject@AdmUtilUserDashboardItem"
    def getLanguages(self):
        tool = getUtility(IPortalLanguagesConfiglet)
        if not tool.isVisible:
            return []
        patern = re.compile(r"(.*)_(.*)$")
        site_name = patern.split(getSite().__name__)

        def normalise_site_name(site_name):
            return len(site_name)>1 and site_name[1:] or site_name + ['gb']
        site_name = normalise_site_name(site_name)
        root = getRoot(self.context)
        sites = []
        current_site = getSite()
        for site in [(i,normalise_site_name(patern.split(i[0]))) for i in root.items() if ISite.providedBy(i[1])]:
            setSite(site[0][1])
            if getUtility(IPortalLanguagesConfiglet).isVisible:
                sites.append(site)
        setSite(current_site)

        def link_by_path(path,site):
            if len(path)==0:
                return site
            parent = site
            item = path[0]
            for item in path:
                if item in [i for i in parent.keys()]:
                    parent = parent[item]
                else:
                    break
            return parent

        langs = []
        for site in sites:
            if site[1][0]==site_name[0]:
                setSite(site[0][1])
                langs.append({
                            'code':site[1][1],
                            'link':absoluteURL(link_by_path(getPath(self.context).split('/')[2:],site[0][1]),self.request),
                            'title':re.sub(r'(\/.*)? ?\[.*?\]$','',[i[1].title for i in zojax.language.vocabulary.terms if i[1].value == getUtility(ISiteLanguage).language][0])
                            })
                setSite(current_site)

        return langs
Exemple #4
0
    def __call__(self, layout=None, view=None, *args, **kw):
        if view is None:
            view = self.view
        self.mainview = view
        self.maincontext = view.context

        layoutview = self.view
        if layout is not None:
            self.view = layout

        self.update()

        if self.layout is None:
            return self.render()

        if self.__name__ != self.layout:
            layout = queryLayout(
                view, self.request, view.__parent__, name=self.layout)
            if layout is not None:
                return layout(layout=self, view=view, *args, **kw)
        else:
            context = self.context
            if layoutview.context is not context.__parent__:
                context = context.__parent__
            else:
                context = getattr(context.__parent__, '__parent__', None)

            if context is None:
                context = getRoot(self.context)

            layout = queryLayout(self, self.request, context, name=self.layout)
            if layout is not None:
                return layout(view=view, *args, **kw)

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

        if layout is not None:
            return layout(*args, **kw)

        raise LayoutNotFound(self.layout)
    def update(self):
        self.site = getSite()
        self.siteUrl = absoluteURL(self.site, self.request)
        catalog = queryUtility(ICatalog)
        if catalog is not None:
            ids = queryUtility(IIntIds)
            query = dict(isDraft={'any_of': (False,)},
                         searchContext=getRoot(self.site),
                         isFeatured={'any_of': (True,)},
                         sort_order='reverse', sort_on=self.index)

            if self.contentTypes:
                query['type'] = {'any_of': self.contentTypes,}

            if '__all__' not in self.spaces:
                query['contentSpaces']= {'any_of': self.spaces}

            results = []
            for item in catalog.searchResults(**query)[:self.count]:
                results.append({'item': item,
                                'modified': IDCTimes(item).modified})
            self.items = results
Exemple #6
0
 def available(self):
     """Available checker call"""
     root = zope.proxy.getProxiedObject(getRoot(self.context))
     site = zope.proxy.getProxiedObject(hooks.getSite())
     return site is not root
Exemple #7
0
 def getURLContext(self):
     return getRoot(self.context)
 def tree(self):
     root = getRoot(self.context)
     filter = PreferenceGroupFilter()
     return self.cookieTree(root, filter)
Exemple #9
0
 def testGetRoot(self):
     from zope.traversing.api import getRoot
     self.assertEqual(getRoot(self.item), self.root)
 def testGetRoot(self):
     from zope.traversing.api import getRoot
     self.assertEqual(
         getRoot(self.item),
         self.root
         )
Exemple #11
0
 def __init__(self, context):
     self.context = context
     # If the object isn't located or can't find its root,
     # this raises TypeError. That would cause the adaptation of this
     # interface to fail, but still use any provided default.
     self.root = ztapi.getRoot(self.context)
 def apidocTree(self):
     root = getRoot(self.context)['apidoc']
     return self.cookieTree(root, PreferenceGroupFilter())