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())
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 linkify_email(self, preloaded_person_data=None): """Linkify any email address recognised in Launchpad. If an email address is recognised as one registered in Launchpad, it is linkified to point to the profile page for that person. Note that someone could theoretically register any old email address in Launchpad and then have it linkified. This may or not may be a concern but is noted here for posterity anyway. """ text = self._stringtoformat seen_addresses = [] matches = re.finditer(re_email_address, text) for match in matches: address = match.group() # Since we globally replace the e-mail in the text, if we have seen # the address before, skip it. if address in seen_addresses: continue person = None # First try to find the person required in the preloaded person # data dictionary. if preloaded_person_data is not None: person = preloaded_person_data.get(address, None) else: # No pre-loaded data -> we need to perform a database lookup. person = getUtility(IPersonSet).getByEmail(address) # Only linkify if person exists and does not want to hide # their email addresses. if person is not None and not person.hide_email_addresses: # Circular dependancies now. Should be resolved by moving the # object image display api. from lp.app.browser.tales import ObjectImageDisplayAPI css_sprite = ObjectImageDisplayAPI(person).sprite_css() seen_addresses.append(address) text = text.replace( address, '<a href="%s" class="%s">%s</a>' % (canonical_url(person), css_sprite, address)) return text
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())