Esempio n. 1
0
 def traverse(self, name, ignored):
     # The context is important here, since it becomes the parent of the
     # resource, which is needed to generate the absolute URL.
     res = namespace.getResource(self.context, name, self.request)
     if isinstance(res, InterfaceClass):
         raise Forbidden('Access to traverser is forbidden.')
     return res
Esempio n. 2
0
 def traverse(self, name, ignored):
     # The context is important here, since it becomes the parent of the
     # resource, which is needed to generate the absolute URL.
     res = namespace.getResource(self.context, name, self.request)
     if isinstance(res, InterfaceClass):
         raise Forbidden('Access to traverser is forbidden.')
     return res
Esempio n. 3
0
    def __call__(self):
        # The context is important here, since it becomes the parent of the
        # icon, which is needed to generate the absolute URL.
        resource = getResource(self.context, self.rname, self.request)
        src = resource()

        return ('<img src="%s" alt="%s" width="%s" height="%s" border="0" />' %
                (src, self.alt, self.width, self.height))
Esempio n. 4
0
 def icon(self):
     """Returns a additional named icon for the given context."""
     icon = zope.component.queryMultiAdapter((self.context, self.request), 
         name=self.iconName)
     if icon is not None:
         resource = getResource(icon.context, icon.rname, self.request)
         src = resource()
         return ('<img src="%s" alt="icon" width="%s" height="%s" ' 
                 'border="0" />' % (src, icon.width, icon.height))
     return u''
Esempio n. 5
0
    def publishTraverse(self, request, name):
        content = None

        auth = getUtility(IAuthentication)
        try:
            principal = auth.getPrincipal(name)
            prefs = IPersonalProfile(principal)
            if prefs.profileImage:
                return LocationProxy(prefs.profileImage, self, name)
        except PrincipalLookupError:
            raise NotFound(self, name, request)

        return getResource(getSite(), 'profileEmptyImage.png', request)
Esempio n. 6
0
 def getToggleIcon(self, item, state):
     """Returns a toggle icon including settings for json url."""
     if state == STATE_COLLAPSED:
         iconName = self.collapsedIconName
     elif state == STATE_EXPANDED:
         iconName = self.expandedIconNamen
     else:
         iconName = self.staticIconName
     icon = zope.component.getMultiAdapter((item, self.request), 
         name=iconName)
     resource = getResource(icon.context, icon.rname, self.request)
     src = resource()
     longDescURL = absoluteURL(item, self.request)
     return ('<img src="%s" alt="toggle icon" width="%s" height="%s" ' 
             'border="0" longDesc="%s" />' % (src, icon.width, 
                icon.height, longDescURL))
Esempio n. 7
0
    def publishTraverse(self, request, name):
        content = None

        try:
            id = int(name)
            content = getUtility(IIntIds).queryObject(id)
        except:
            pass

        if IAvatar.providedBy(content):
            return LocationProxy(content, self, name)

        auth = getUtility(IAuthentication)
        try:
            principal = auth.getPrincipal(name)
            prefs = IPersonalProfile(principal)
            if prefs.avatarImage:
                return LocationProxy(prefs.avatarImage, self, name)
        except PrincipalLookupError:
            if name != '0':
                raise NotFound(self, name, request)

        return getResource(getSite(), 'avatarEmptyImage.png', request)
Esempio n. 8
0
 def test_getResource_not_found(self):
     with self.assertRaises(LocationError):
         namespace.getResource(None, '', None)
Esempio n. 9
0
 def url(self):
     resource = getResource(self.context, self.rname, self.request)
     src = resource()
     return src