本文整理汇总了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
示例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'
示例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)})
示例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)
示例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))
示例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)})
示例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)
示例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)