def update_twitter_account(sender, user, response, details, **kwargs): ident = response['id'] logging.getLogger(__name__).debug('Making twitter account with ident %r', ident) account, created = Account.objects.get_or_create(service='twitter.com', ident=ident) new_connection = True if not account.user or account.user.pk != user.pk else False account.user = user screen_name = details['username'] account.display_name = details.get('fullname', screen_name) account.permalink_url = 'http://twitter.com/%s' % screen_name account.avatar_url = response.get('profile_image_url', '') token = oauth.Token.from_string(response['access_token']) account.authinfo = ':'.join((token.key, token.secret)) # Reset any error it may have had. account.error = False account.save() if new_connection: from friendstream.tasks import poll_account poll_account.delay(account.pk) return True
def home(request): accounts = dict((acc.service.split('.')[0], acc) for acc in request.user.accounts.all()) had_stale_accounts = False for acc in accounts.values(): if acc.stale: had_stale_accounts = True log.debug("Reviving %s's stale %s account (they logged in)", request.user.username, acc.service) acc.stale = False acc.save() poll_account.delay(acc.pk) return render_to_response('home.html', {'accounts': accounts, 'had_stale_accounts': had_stale_accounts}, context_instance=RequestContext(request))
def update_facebook_account(sender, user, response, details, **kwargs): ident = response['id'] logging.getLogger(__name__).debug('Making facebook account with ident %r', ident) account, created = Account.objects.get_or_create(service='facebook.com', ident=ident) new_connection = True if not account.user or account.user.pk != user.pk else False account.user = user account.display_name = details['fullname'] account.permalink_url = response.get('link', '') account.avatar_url = '' account.authinfo = response['access_token'] # Reset any error it may have had. account.error = False account.save() if new_connection: from friendstream.tasks import poll_account poll_account.delay(account.pk) return True