当前位置: 首页>>代码示例>>Python>>正文


Python VoterManager.save_twitter_user_values_from_dict方法代码示例

本文整理汇总了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}
开发者ID:eternal44,项目名称:WeVoteServer,代码行数:58,代码来源:utils.py


注:本文中的voter.models.VoterManager.save_twitter_user_values_from_dict方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。