Beispiel #1
0
 def jsonGranteeData(self, grant_permissions):
     """See `ISharingService`."""
     result = []
     request = get_current_web_service_request()
     browser_request = IWebBrowserOriginatingRequest(request)
     # We need to precache icon and validity information for the batch.
     grantee_ids = [grantee[0].id for grantee in grant_permissions]
     list(getUtility(IPersonSet).getPrecachedPersonsFromIDs(
         grantee_ids, need_icon=True, need_validity=True))
     for (grantee, permissions, shared_artifact_types) in grant_permissions:
         some_things_shared = len(shared_artifact_types) > 0
         grantee_permissions = {}
         for (policy, permission) in permissions.iteritems():
             grantee_permissions[policy.type.name] = permission.name
         shared_artifact_type_names = [
             info_type.name for info_type in shared_artifact_types]
         display_api = ObjectImageDisplayAPI(grantee)
         icon_url = display_api.custom_icon_url()
         sprite_css = display_api.sprite_css()
         result.append({
             'name': grantee.name,
             'icon_url': icon_url,
             'sprite_css': sprite_css,
             'display_name': grantee.displayname,
             'self_link': absoluteURL(grantee, request),
             'web_link': absoluteURL(grantee, browser_request),
             'permissions': grantee_permissions,
             'shared_artifact_types': shared_artifact_type_names,
             'shared_items_exist': some_things_shared})
     return result
 def test_custom_icon_url_context_has_an_icon(self):
     # When the context has a custom icon, the URL is for the
     # LibraryFileAlias.
     icon = self.factory.makeLibraryFileAlias(
         filename='smurf.png', content_type='image/png')
     product = self.factory.makeProduct(icon=icon)
     display_api = ObjectImageDisplayAPI(product)
     self.assertEqual(icon.getURL(), display_api.custom_icon_url())
Beispiel #3
0
 def getPickerEntries(self, term_values, context_object, **kwarg):
     """See `IPickerEntrySource`"""
     entries = []
     for term_value in term_values:
         extra = PickerEntry()
         if hasattr(term_value, 'summary'):
             extra.description = term_value.summary
         display_api = ObjectImageDisplayAPI(term_value)
         image_url = display_api.custom_icon_url() or None
         css = display_api.sprite_css() or 'sprite bullet'
         if image_url is not None:
             extra.image = image_url
         else:
             extra.css = css
         entries.append(extra)
     return entries
 def test_custom_icon_url_context_has_no_icon(self):
     # When the context has not set the custom icon, the URL is None.
     product = self.factory.makeProduct()
     display_api = ObjectImageDisplayAPI(product)
     self.assertEqual(None, display_api.custom_icon_url())
 def test_custom_icon_url_context_is_None(self):
     # When the context is None, the URL is an empty string.
     display_api = ObjectImageDisplayAPI(None)
     self.assertEqual('', display_api.custom_icon_url())