本文整理匯總了Python中voter.models.VoterManager.save_twitter_user_values_from_dict方法的典型用法代碼示例。如果您正苦於以下問題:Python VoterManager.save_twitter_user_values_from_dict方法的具體用法?Python VoterManager.save_twitter_user_values_from_dict怎麽用?Python VoterManager.save_twitter_user_values_from_dict使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類voter.models.VoterManager
的用法示例。
在下文中一共展示了VoterManager.save_twitter_user_values_from_dict方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: social_user
# 需要導入模塊: from voter.models import VoterManager [as 別名]
# 或者: from voter.models.VoterManager import save_twitter_user_values_from_dict [as 別名]
def social_user(backend, uid, details, user=None, *args, **kwargs):
voter_manager = VoterManager()
provider = backend.name
social = backend.strategy.storage.user.get_social_auth(provider, uid)
if backend.name == 'twitter':
# Twitter: Check to see if we have a voter with a matching twitter_id
local_user_matches = user and user.twitter_id == uid
else:
local_user_matches = user and user.email != details.get('email')
switch_user = not local_user_matches
if switch_user:
# Logout the current Django user
logout(backend.strategy.request)
user = None
voter_that_matches_auth = None
voter_found_that_matches_auth = False
if social:
if social.user:
if backend.name == 'twitter':
if social.user.twitter_id == uid:
voter_that_matches_auth = social.user
voter_found_that_matches_auth = True
else:
pass
if not voter_found_that_matches_auth:
# Find the voter account that actually matches this twitter_id
results = voter_manager.retrieve_voter_by_twitter_id(uid)
if results['voter_found']:
voter_that_matches_auth = results['voter']
voter_found_that_matches_auth = True
if voter_found_that_matches_auth:
user = voter_that_matches_auth
else:
# No other account matches this, so we want to save basic information in social.user
if backend.name == 'twitter':
if social and social.user:
twitter_user_dict = {
'id': uid,
'profile_image_url_https': kwargs['response']['profile_image_url_https'],
'screen_name': kwargs['response']['screen_name']
}
results = voter_manager.save_twitter_user_values_from_dict(social.user, twitter_user_dict)
if results['success']:
social.user = results['voter']
user = results['voter']
return {'social': social,
'user': user,
'is_new': user is None,
'switch_user': True,
'new_association': False}