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


Python _user.find_one函数代码示例

本文整理汇总了Python中storymap.connection._user.find_one函数的典型用法代码示例。如果您正苦于以下问题:Python find_one函数的具体用法?Python find_one怎么用?Python find_one使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: _user_get

def _user_get():
    """Enforce authenticated user"""
    uid = session.get('uid')
    if not uid:
        return redirect(url_for('select'))
    user = _user.find_one({'uid': uid})
    if not user:
        session.pop('uid')
        return redirect(url_for('select'))
    return user
开发者ID:TobMcG,项目名称:StoryMapJS,代码行数:10,代码来源:api.py

示例2: check_test_user

def check_test_user():
    if settings.TEST_MODE:
        if not _user.find_one({ 'uid': 'test' }):
            _user.insert({
                'uid': 'test',
                'migrated': 1,
                'storymaps': {},
                'google': { 'name': 'Test User' }
            })
        session['uid'] = 'test'
开发者ID:binary-koan,项目名称:StoryMapJS,代码行数:10,代码来源:api.py

示例3: google_auth_verify

def google_auth_verify():
    """Finalize google authorization"""
    try:
        if 'error' in request.args:
            raise Exception(_format_err(
                'Error getting authorization', request.args.get('error')))

        code = _request_get_required('code')

        flow = OAuth2WebServerFlow(
            settings.GOOGLE_CLIENT_ID,
            settings.GOOGLE_CLIENT_SECRET,
            _GOOGLE_OAUTH_SCOPES,
            redirect_uri='https://'+request.host+url_for('google_auth_verify')
        )
        credentials = flow.step2_exchange(code)
        # ^ this is an oauth2client.client.OAuth2Credentials object

        # Get user info
        userinfo = google.get_userinfo(
            google.get_userinfo_service(credentials))
        if not userinfo:
            raise Exception('Could not get Google user info')

        info = {
            'id': userinfo.get('id'),
            'name': userinfo.get('name'),
            'credentials': credentials.to_json()
        }
        if not info['id']:
            raise Exception('Could not get Google user ID')

        # Upsert user record
        uid = _get_uid('google:'+info['id'])

        user = _user.find_one({'uid': uid})
        if user:
            user['google'] = info
        else:
            user = {
                'uid': uid,
                'migrated': 0,
                'storymaps': {},
                'google': info
            }
        user['uname'] = info['name']
        _user.save(user)

        # Update session
        session['uid'] = uid

        return redirect(url_for('select'))
    except Exception, e:
        traceback.print_exc()
        return jsonify({'error': str(e)})
开发者ID:TobMcG,项目名称:StoryMapJS,代码行数:55,代码来源:api.py

示例4: userinfo

def userinfo():
    import pprint
    
    uid = session.get('uid')
    user = None
    
    if uid:
        user = _user.find_one({'uid': uid})
        if user:
            del user['_id']
            user = pprint.pformat(user, indent=4)            
            
    return render_template('userinfo.html',
        uid=uid, user=user)
开发者ID:dmoses,项目名称:StoryMapJS,代码行数:14,代码来源:api.py

示例5: select

def select():
    try:
        uid = session.get('uid')
        if not uid:
            return render_template('select.html')

        user = _user.find_one({'uid': uid})
        if not user:
            _session_pop('uid')
            return render_template('select.html')
        del user['_id']

        return render_template('select.html', user=user)
    except Exception, e:
        traceback.print_exc()
        return render_template('select.html', error=str(e))
开发者ID:TobMcG,项目名称:StoryMapJS,代码行数:16,代码来源:api.py

示例6: google_auth_verify

def google_auth_verify():
    """Finalize google authorization"""
    try:
        if "error" in request.args:
            raise Exception(_format_err("Error getting authorization", request.args.get("error")))

        code = _request_get_required("code")

        flow = OAuth2WebServerFlow(
            settings.GOOGLE_CLIENT_ID,
            settings.GOOGLE_CLIENT_SECRET,
            _GOOGLE_OAUTH_SCOPES,
            redirect_uri="https://" + request.host + url_for("google_auth_verify"),
        )
        credentials = flow.step2_exchange(code)
        # ^ this is an oauth2client.client.OAuth2Credentials object

        # Get user info
        userinfo = google.get_userinfo(google.get_userinfo_service(credentials))
        if not userinfo:
            raise Exception("Could not get Google user info")

        info = {"id": userinfo.get("id"), "name": userinfo.get("name"), "credentials": credentials.to_json()}
        if not info["id"]:
            raise Exception("Could not get Google user ID")

        # Upsert user record
        uid = _get_uid("google:" + info["id"])

        user = _user.find_one({"uid": uid})
        if user:
            user["google"] = info
        else:
            user = {"uid": uid, "migrated": 0, "storymaps": {}, "google": info}
        user["uname"] = info["name"]
        _user.save(user)

        # Update session
        session["uid"] = uid

        return redirect(url_for("select"))
    except Exception, e:
        traceback.print_exc()
        return jsonify({"error": str(e)})
开发者ID:jorol,项目名称:StoryMapJS,代码行数:44,代码来源:api.py

示例7: userinfo

def userinfo():
    import pprint
    
    uid = session.get('uid')
    user = None
    migrate_data = None
    
    if uid:
        user = _user.find_one({'uid': uid})
        if user:
            if not user['migrated']:
                migrate_data = google.drive_get_migration_diagnostics(user)
 
            del user['_id']
            user = pprint.pformat(user, indent=4) 
            migrate_data = pprint.pformat(migrate_data, indent=4) 
            
            
    return render_template('userinfo.html',
        uid=uid, user=user, migrate_data=migrate_data)
开发者ID:hifans,项目名称:StoryMapJS,代码行数:20,代码来源:api.py

示例8: userinfo

def userinfo():
    import pprint

    uid = session.get("uid")
    user = None
    migrate_data = None

    if uid:
        user = _user.find_one({"uid": uid})
        if user:
            if not user["migrated"]:
                migrate_data = google.drive_get_migration_diagnostics(user)

            del user["_id"]
            try:
                del user["google"]["credentials"]
            except KeyError:
                pass
            user = pprint.pformat(user, indent=4)
            migrate_data = pprint.pformat(migrate_data, indent=4)

    return render_template("userinfo.html", uid=uid, user=user, migrate_data=migrate_data)
开发者ID:jorol,项目名称:StoryMapJS,代码行数:22,代码来源:api.py


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