當前位置: 首頁>>代碼示例>>Python>>正文


Python UserModel.get方法代碼示例

本文整理匯總了Python中models.user.UserModel.get方法的典型用法代碼示例。如果您正苦於以下問題:Python UserModel.get方法的具體用法?Python UserModel.get怎麽用?Python UserModel.get使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在models.user.UserModel的用法示例。


在下文中一共展示了UserModel.get方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: get_user

# 需要導入模塊: from models.user import UserModel [as 別名]
# 或者: from models.user.UserModel import get [as 別名]
def get_user(gplus_id):
  try:
    user = UserModel.get(gplus_id)
    response = make_response("user: " + json.dumps(user.to_json(), indent=2), 200)
    response.headers['Content-Type'] = 'application/json'
    return response
  except UserModel.DoesNotExist:
    app.logger.debug('User does not exist')
    return "User Not Found: {0}".format(gplus_id)
開發者ID:imouton,項目名稱:pourag,代碼行數:11,代碼來源:pourag.py

示例2: get_friends

# 需要導入模塊: from models.user import UserModel [as 別名]
# 或者: from models.user.UserModel import get [as 別名]
def get_friends(gplus_id):
  try:
    friends = UserModel.get(gplus_id).friends()
    app.logger.debug("found {0} friends".format(len(friends)))
    friends_json = []
    for friend in friends:
      friends_json.append(friend.to_json())
    response = make_response(json.dumps(friends_json, indent=2), 200)
    response.headers['Content-Type'] = 'application/json'
    return response
  except UserModel.DoesNotExist:
    app.logger.debug('User does not exist')
    return "User Not Found: {0}".format(gplus_id)
開發者ID:imouton,項目名稱:pourag,代碼行數:15,代碼來源:pourag.py

示例3: connect

# 需要導入模塊: from models.user import UserModel [as 別名]
# 或者: from models.user.UserModel import get [as 別名]
def connect():
  code = request.data
  app.logger.debug("connect - code: {0}".format(code))
  try:
    # Upgrade the authorization code into a credentials object
    oauth_flow = flow_from_clientsecrets('client_secrets.json', scope='')
    oauth_flow.redirect_uri = 'postmessage'
    credentials = oauth_flow.step2_exchange(code)
    app.logger.debug("credentials: {0}".format(credentials.to_json()))

     # Store the access token in the session for later use.
    session['credentials'] = pickle.dumps(credentials)
    gplus_id = credentials.id_token['sub']
    http = credentials.authorize(httplib2.Http())
    try:  # load the existing user
      user = UserModel.get(gplus_id)
      app.logger.debug("user found: {0}".format(gplus_id))
    except UserModel.DoesNotExist:  # create a new record for this user
      google_request = SERVICE.people().get(userId='me')
      profile = google_request.execute(http=http)
      #app.logger.debug('profile: %s' % profile)
      user = UserModel(gplus_id)
      user.populate_from_profile(profile)
      app.logger.debug("user added: {0}".format(gplus_id))

    user.last_login_datetime = datetime.datetime.now()
    user.save()

    # fetch visible connections, store new connections to the db
    # NOTE: we do not purge connections that are no longer valid...yet
    google_request = SERVICE.people().list(userId='me', collection='visible')
    for profile in google_request.execute(http=http).get('items'):
      connection = user.update_connection(profile)
      #app.logger.debug("Created connection: {0}".format(connection.to_json()))

  except FlowExchangeError:
    app.logger.warn('connect - FlowExchangeError')
    session.pop('credentials', None)
    response = make_response(json.dumps('Failed to upgrade the authorization code.'), 401)
    response.headers['Content-Type'] = 'application/json'
    return response

  response = make_response(json.dumps('Successfully connected user.'), 200)
  response.headers['Content-Type'] = 'application/json'
  return response
開發者ID:imouton,項目名稱:pourag,代碼行數:47,代碼來源:pourag.py


注:本文中的models.user.UserModel.get方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。