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


Python User.get_by_id方法代码示例

本文整理汇总了Python中application.models.User.get_by_id方法的典型用法代码示例。如果您正苦于以下问题:Python User.get_by_id方法的具体用法?Python User.get_by_id怎么用?Python User.get_by_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在application.models.User的用法示例。


在下文中一共展示了User.get_by_id方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: facebook_authorized

# 需要导入模块: from application.models import User [as 别名]
# 或者: from application.models.User import get_by_id [as 别名]
def facebook_authorized(resp):
    next_url = request.args.get('next') or url_for('index')
    if resp is None or 'access_token' not in resp:
        return redirect(next_url)

    session['logged_in'] = True
    session['facebook_token'] = (resp['access_token'], '')

    # Make use of the connection to retrieves the user's info
    profile = facebook.get('/me').data
    profile_id = profile['id'].decode('utf-8')
    user_entry = ndb.Key('User', profile_id).get()

    if not user_entry:
        friends = facebook.get('/me/friends').data
        add_user(profile, friends)

    # Add new token to the user entry
    user = User.get_by_id(profile_id)
    user.token = resp['access_token']
    user.put()

    session['profile_id'] = profile['id'].decode('utf-8')

    return redirect('/#/friends')
开发者ID:Zack--,项目名称:code-snippets,代码行数:27,代码来源:facebook_login.py

示例2: test_friends_updated

# 需要导入模块: from application.models import User [as 别名]
# 或者: from application.models.User import get_by_id [as 别名]
    def test_friends_updated(self, mocked_graph):

        mocked_graph.return_value.get_object.return_value = {'id': '42'}
        mocked_graph.return_value.get_connections.return_value = {'data': []}

        user = User(id='42', name='Foo Bar', token='101010')
        user.put()
        User(id='43', name='Knuth Donald', token='101010').put()
        update_friendlists(user)
        knuth = User.get_by_id('43')
        self.assertEqual(len(knuth.friends), 0)

        mocked_graph.return_value.get_connections.return_value = {'data': [{
            'id': '43', 'name': 'Knuth Donald'
        }]}
        update_friendlists(user)
        knuth = User.get_by_id('43')
        self.assertEqual(len(knuth.friends), 1)
        self.assertEqual(knuth.friends[0], user.key)
开发者ID:Zack--,项目名称:code-snippets,代码行数:21,代码来源:tests.py

示例3: get

# 需要导入模块: from application.models import User [as 别名]
# 或者: from application.models.User import get_by_id [as 别名]
    def get(self):
        profile_id = request.args.get("profile_id")
        if not profile_id and not session.get("profile_id"):
            return Response("No profile specified. Please specify profile_id", status=400)

        profile_id = profile_id or session.get("profile_id")
        user = User.get_by_id(profile_id)
        if not user:
            return Response("No profile '{}' found. Please specify profile_id".format(profile_id), status=400)

        data = {"friends": [{"name": f.name} for f in ndb.get_multi(user.friends)]}
        data["count"] = len(data["friends"])

        return Response(json.dumps(data), status=200)
开发者ID:Zack--,项目名称:code-snippets,代码行数:16,代码来源:friends.py

示例4: post

# 需要导入模块: from application.models import User [as 别名]
# 或者: from application.models.User import get_by_id [as 别名]
    def post(self):
        data = request.get_json(silent=True, force=True)

        if not data:
            return Response(status=400)

        # Only one permission is hooked
        entry = data["entry"][0]

        profile_id = entry["uid"]
        new_friend = User.get_by_id(profile_id)

        if entry["changed_fields"][0] == "user_friends":
            # Add current user to his friends friend lists
            update_friendlists(new_friend)

        return Response(status=200)
开发者ID:Zack--,项目名称:code-snippets,代码行数:19,代码来源:friends.py


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