def getPageLinkImage(instance, user, target): assert isinstance(user, User) imageHtml = Display.getImage(user.profile_image_url, user.name, None, className='twitter-profile-image') return Display.getLink(UserInformationPage.link_info.getPageLink( instance, user.id), imageHtml, target=target)
def getPageLinkImage(instance, user, target): assert isinstance(user, User) imageHtml = Display.getImage(user.profile_image_url, user.name, None, className='twitter-profile-image') return Display.getLink(UserInformationPage.link_info.getPageLink(instance,user.id), imageHtml, target=target)
def pushSocketDisplayChange(self, controls, updatedItem, oldCachedValue, isInitialPush, signaler, signalerKey): divControl = controls['UserWsg_div'] followerMapControl = controls['UserWsg_follower_map'] assert isinstance(divControl, DivControl) assert isinstance(followerMapControl, MapControl) instance = signalerKey[0] user = signalerKey[1] queueProgressBarId = 'follower-enrichment-queue-progress-bar' userProgressBarId = 'follower-enrichment-user-progress-bar' userIdProgressBarId = 'follower-enrichment-userId-progress-bar' descriptionId = 'follower-enrichment-progress-description' assert isinstance(updatedItem, User) # Utility functions for updating main page. def getHeaderCell(text, headerWidth=2): return divControl.getCell(text, 'span%d vertical-header' % headerWidth, ['b']) def getContentsCell(text, contentsWidth=10): return divControl.getCell(text,'span%d vertical-content' % contentsWidth, []) hashKeyTracker = [1] def updateRow(header, contents, theKey=hashKeyTracker): if contents is None: contents = '-' isHeader = header is not None if isHeader: headerWidth = 2 contentsWidth = 10 else: headerWidth = 0 contentsWidth = 12 text = [getContentsCell(contents, contentsWidth)] if isHeader: text = [getHeaderCell(header, headerWidth)] + text divControl.updateRow(theKey[0], text, rowIndex = -1, rowClass = 'row-fluid vertical-row') if theKey is not None: theKey[0] += 1 numberOfFollowers = updatedItem.num_followers # Does what it says on the tin. def updateFollowerInformationEnrichedStatus(): if (not updatedItem.is_followers_loaded) and updatedItem.queued_for_follower_enrichment: progressBarHtml = '<div class="progress progress-striped active">'\ '<div class="bar bar-danger" id="%s" style="width: %.2f%%"></div>'\ '<div class="bar bar-warning" id="%s" style="width: %.2f%%"></div>'\ '<div class="bar bar-success" id="%s" style="width: %.2f%%"></div></div>' % (queueProgressBarId, updatedItem.follower_enrichment_progress.queue_progress, userProgressBarId ,updatedItem.follower_enrichment_progress.user_progress, userIdProgressBarId, updatedItem.follower_enrichment_progress.user_id_progress) followerInformationEnrichedValue = '<br><br><div class="text-info" id="%s">%s</div>%s' % (descriptionId, formatDescriptionWithUserLink(updatedItem.follower_enrichment_progress.enrichment_progress_description, updatedItem.follower_enrichment_progress.queue_waiting_for_user), progressBarHtml) returnVal = 1 elif (not updatedItem.is_followers_loaded) and updatedItem.last_follower_enrichment_error: followerInformationEnrichedValue = ' - failed to enrich followers with reason: %s' % updatedItem.last_follower_enrichment_error returnVal = 2 elif (not updatedItem.is_followers_loaded) and (not updatedItem.queued_for_follower_enrichment) and updatedItem.is_geocoded: linkToFollow = UserFollowerEnrichPage.link_info.getPageLink(instance, user) link = '<br><br>%s<br>' % Display.getLink('#','Get Followers','_self','$(this).addClass(\'disabled\'); getPage(\'%s\', null, null, null); return false;' % linkToFollow, htmlClass='btn btn-success get-followers-button') followerInformationEnrichedValue = link returnVal = 4 elif not updatedItem.is_geocoded: followerInformationEnrichedValue = ' - not geocoded so cannot enrich followers' returnVal = 3 else: followerInformationEnrichedValue = '' returnVal = 0 if divControl.last_follower_information_enrich_draw != returnVal or returnVal == 2: displayValue = '%d followers%s' % (numberOfFollowers, followerInformationEnrichedValue) updateRow('Follower Information', displayValue, [1000]) divControl.last_follower_information_enrich_draw = returnVal return returnVal # Generates the progress bar description. def formatDescriptionWithUserLink(description, user): if user is not None: link = Display.getLink(UserInformationPage.link_info.getPageLink(user.instance_key, user.id), unicode(user.name), target='_self') return description % link else: return description # Handles progress bar changes, updating the enrichment value if necessary in order # to initialize the progress bar. def handleProgressBarChanges(progress, mergeResult): assert isinstance(progress, UserFollowerEnrichmentProgress) if isInitialPush: mergeResult = 1,1,1 # update all progress bars. if mergeResult is None: return difQueueProgress, difUserIdProgress, difUserProgress = mergeResult if difQueueProgress == 0 and difUserIdProgress == 0 and difUserProgress == 0: return # Not initialized yet or enrichment complete. if divControl.last_follower_information_enrich_draw != 1: return def doProgressBarChange(progressBarId, percentage): divControl.executeJavascript('document.getElementById("%s").style.width="%.2f%%";' % (progressBarId, percentage)) def setDescription(description): divControl.executeJavascript('document.getElementById("%s").innerHTML=\'%s\';' % (descriptionId, description)) if difUserProgress > 0: doProgressBarChange(userProgressBarId, progress.user_progress) if difUserIdProgress > 0: doProgressBarChange(userIdProgressBarId, progress.user_id_progress) if difQueueProgress > 0: doProgressBarChange(queueProgressBarId, progress.queue_progress) description = formatDescriptionWithUserLink(progress.enrichment_progress_description, progress.queue_waiting_for_user) setDescription(description) # Populate contents of page. updateRow('Timestamp', updatedItem.date_time) updateRow('User name', updatedItem.name) updateRow('Profile Image', Display.getImage(updatedItem.profile_image_url, updatedItem.name, className = 'twitter-profile-image')) updateRow('Description', updatedItem.description) updateRow('Location', updatedItem.location_text) if updatedItem.has_twitter_place: place = updatedItem.twitter_place assert isinstance(place, Place) placeCountry = '%s/%s' % (place.country, place.country_code) placeName = place.full_name placeNameContents = 'Place: %s' % placeName if placeCountry is not None: placeNameContents += ' / Country: %s' % placeCountry else: placeNameContents = '-' updateRow('Twitter Place', placeNameContents) geocoded_location = None if updatedItem.is_geocoded: raw_location = updatedItem.location_geocode assert isinstance(raw_location, GeocodeResultAbstract) geocoded_location = Display.getLink(LocationsPage.link_info.getPageLink(instance, updatedItem.location_geocode.place_id, updatedItem.location_geocode.provider_id), updatedItem.location_geocode.display_name_short, target='_self') if raw_location.has_country: countryGeocode = raw_location.country assert isinstance(countryGeocode, GeocodeResultGNS) countryHtml = Display.getLink(LocationsPage.link_info.getPageLink(instance, countryGeocode.place_id, countryGeocode.provider_id), countryGeocode.display_name, target='_self') geocoded_location = '%s / %s' % (geocoded_location, countryHtml) if raw_location.has_continent: continentGeocode = raw_location.continent assert isinstance(continentGeocode, GeocodeResultGNS) continentHtml = Display.getLink(LocationsPage.link_info.getPageLink(instance, continentGeocode.place_id, continentGeocode.provider_id), continentGeocode.display_name, target='_self') geocoded_location = '%s / %s' % (geocoded_location, continentHtml) updateRow('Geocoded Location', geocoded_location) #geocodedFrom = updatedItem.geocoded_from #if geocodedFrom is None: # geocodedFrom = '-' #updateRow('Geocoded From', geocodedFrom) divControl.executeJavascript('setPageTitle("%s");' % updatedItem.name) updateFollowerInformationEnrichedStatus() handleProgressBarChanges(updatedItem.follower_enrichment_progress, updatedItem.merge_result) if updatedItem.is_followers_loaded and not updatedItem.queued_for_follower_enrichment: # Don't update enriched follower information needlessly (say only timestamp changes). # If we update the map it resets it which is a problem. if not divControl.pushed_enriched_follower_information: divControl.pushed_enriched_follower_information = True updateRow(None, divControl.getContainerHtml('', 'span12', 'followers-list')) divControl.executeJavascript('setupFollowersList();') sortedResults = [] analyser = updatedItem.analysers[UserAnalysisFollowersGeocoded.analysis_name_static()] assert isinstance(analyser, UserAnalysisFollowersGeocoded) updateRow(None, getFollowersInfoDiv(divControl, analyser, 6, 6, [], ['b'])) divControl.executeJavascript('applyScrollbars();') divControl.executeJavascript('setupFollowerLocationMap();') for location, numFollowers in analyser.num_geocoded_followers_by_location.iteritems(): assert isinstance(location,GeocodeResultAbstract) percentage = float(numFollowers) / analyser.num_geocoded_followers * 100 popupText = location.display_name followerMapControl.addMarker(location.coordinate, popupText=popupText, properties={'percentage' : percentage})