def success(result): events = result['events_html'] # Catch bad results if (len(events) <= 0): return else: # Set up list of newsfeed events self.pets_newsfeed = [] # Used for collapsing sequential events that are identical prev_type = None; prev_string = None; for event in events: # Extract the data from the event date = event['event_date'] type = event['event_type'] # Get the string for the event strings = pets.newsfeed_strings[type] obj = strings['primary'](event) # Create the array of substitutable sprintf params params = [] switch = {'pet_link' : lambda *a: params.append(format_link(event['pet_id'], event['pet_display_name'])), 'owner_link' : lambda *a: params.append(format_link(event['owner_id'], event['owner_display_name'])), 'target_link' : lambda *a: params.append(format_link(self.pets_pet['user_id'], self.pets_pet['display_name']))} for param in obj['params']: # Emulate switch statement if param in switch: switch[param]() elif param in ['purchase_price', 'setfree_price', 'earned_amount', 'profit_amount']: params.append(format_cash(event[param])) elif param in ['bonus_price', 'bonus_amount']: params.append(format_bonus(event[param])) elif param == 'achievement_name': params.append(pets.achievement_strings[event['achievement_type']]) elif param == 'gender': params.append('himself' if event[param] == 'M' else 'herself') string = obj['string'] % tuple(params) if prev_type == type and prev_string == string: last_event = self.pets_newsfeed[len(self.pets_newsfeed) - 1] last_event['numTimes'] += 1 last_event['time'] = TU.format_event_time(date) else: self.pets_newsfeed.append({'event_type' : type, 'string' : string, 'numTimes' : 1, 'time' : TU.format_event_time(date)}) prev_type = type prev_string = string callback.success() # S3
def success(result): events = result['data'][0] # Catch bad results if (len(events) <= 0): return else: # Set up list of newsfeed events self.elections_newsfeed = [] # Used for collapsing sequential events that are identical prev_type = None; prev_string = None; for event in events: # Extract the data from the event data = event['data'] date = event['date'] type = event['type'] # Get the string for this event strings = elections.newsfeed_strings[type] obj = strings['primary'] # Create the array of substitutable sprintf params params = [] switch = {'project_title' : lambda *a: params.append(data['project']['title']), 'target_name' : lambda *a: params.append('<a href="%s">%s</a>' % (data['target']['elections_link'], data['target']['name'])), 'displayname' : lambda *a: params.append('<a href="%s">%s</a>' % (self.elections_candidate['elections_link'], self.candidate['name'])), 'issue_title' : lambda *a: params.append(data['issue']['title']), 'issue_vote' : lambda *a: params.append(data['issue']['pro'] if data['vote'] else data['issue']['con']), 'party' : lambda *a: params.append(data['party_id'])} for param in obj['params']: # Emulate switch statement if param in switch: switch[param]() if param in ['votes', 'fame', 'funds', 'collaborators', 'party_line']: params.append(data[param]) string = obj['string'] % tuple(params) if prev_type == type and prev_string == string: last_event = self.elections_newsfeed[len(self.elections_newsfeed) - 1] last_event['numTimes'] += 1; last_event['time'] = TU.format_event_time(date) else: self.elections_newsfeed.append({'feed_type' : 'candidate', 'event_type' : type, 'string' : string, 'numTimes' : 1, 'time' : TU.format_event_time(date)}) prev_type = type prev_string = string callback.success() # S3
def toast_update(self, event, *a): def meetme(*a): '''meetme : {'age', 'gender', 'location', 'sender_display_name', 'sender_url', 'sender_thumbnail', 'sender_uid', 'meetme_url', 'isMatch'}''' fire_opts.update(title = _('Meet Me') + _('Match from: %s') if event['isMatch'] else _('Interest from: %s') % event['sender_display_name'], msg = '') if event['isMatch']: fire_opts.update(input = lambda text, opts, *a: self.send_message(text, opts, event)) def message(*a): '''message : {'sender_display_name', 'sender_url', 'sender_uid', 'subject', 'message', 'message_id', 'sender_thumbnail'}''' fire_opts.update(title = _('New Message from: %s') % event['sender_display_name'], msg = strings.strip_html(event['message']).strip(), sticky = True, input = lambda text, opts, *a: self.send_message(text, opts, event)) def friend_request(*a): '''friend_request : {'isNewFriend', 'age', 'gender', 'location', 'sender_display_name', 'sender_url', 'sender_uid', 'sender_thumbnail'}''' fire_opts.update(title = _('%s is now your friend') if event['isNewFriend'] else _('Friend Request from: %s') % event['sender_display_name'], msg = '') if event['isNewFriend']: fire_opts.update(input = lambda text, opts, *a: self.send_message(text, opts, event)) def topics(*a): '''topics : {'topics_type', 'conv_id', 'post_id', 'init_text', 'text', 'sender_displayName', 'sender_url', 'sender_thumbnail', 'sender_uid'}''' pass # TODO implement topics fire_opts = dict(onclick = lambda *a: TU.launchbrowser(event['sender_url']), popupid = 'tagged_toast!%r!%r' % (event['sender_uid'], id(self))) {'meetme' : meetme, 'message' : message, 'friend_request' : friend_request, 'topics' : topics }[event['sub_type']]() if event['sub_type'] != 'topics': # TODO implement topics fire('tagged.toast', **fire_opts)
def elections_project_contribution(self, event, *a): '''project : {'hash', 'total_contributions', 'contributors', 'max_contribution', 'starter_id', 'contributions', 'id', 'starter', 'num_contributors', 'finish_time', 'state', 'catalog_id', 'time_remaining'}''' project = event['project'] state = project['state'] if state == -1: # FAILED msg = _('not able to get fully funded') elif state == 0: # ACTIVE msg = _('contributed') elif state == 1: # COMPLETED msg = _('completed') fire('tagged.elections', title = _('Elections'), msg = _('A project was %s') % msg, # TODO we need the projects catalog to be more specific onclick = lambda *a: TU.launchbrowser('apps/elections.html'))
def extra_header_func(self): return (_('Invite Friends'), TU.weblink('friends.html#tab=contacts&type=0&filterpg=All_0'))
def header_funcs(self): return ((_('Home'), TU.weblink()), (_('Profile'), TU.weblink('profile.html')), (_('Messages'), TU.weblink('messages.html')), (_('People'), TU.weblink('people.html')), (_('Games'), TU.weblink('games.html')))
def openurl_Games(self): TU.launchbrowser('games.html')
def format_cash(amount): return '<span class="cash">%s</span>' % TU.format_currency(amount)
def openurl_People(self): TU.launchbrowser('people.html')
def openurl_Profile(self): TU.launchbrowser('profile.html')
def API_URL(self): return 'http://www' + TU.TAGGED_DOMAIN() + '/api/?'
def onclick(link): if link != '': TU.launchbrowser(link)
def format_bonus(amount): return '<span class="cash bonus">%s</span>' % TU.format_currency(amount)
def openurl_Home(self): TU.launchbrowser('')
def openurl_Messages(self): TU.launchbrowser('messages.html')
def REALTIME_URL(self): return 'http://dpush01.tag-dev.com:8001' if TU.TAGGED_DOMAIN( ) == '.tag-local.com' else 'http://push' + TU.TAGGED_DOMAIN()