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


Python UserModel.save方法代码示例

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


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

示例1: render

# 需要导入模块: from models.user import UserModel [as 别名]
# 或者: from models.user.UserModel import save [as 别名]
    def render(self):
        if self.debug:
            return render_template('index_debug.html',
                                   lti_dump=g.lti.dump_all())
        if g.lti.is_instructor():
            return render_template('question_list.html')
        else:
            UserModel.save(g.lti.get_user_id(), g.lti.get_user_name())

        return render_template('index_student.html')
开发者ID:klaplong,项目名称:SWE_2013_Groep2,代码行数:12,代码来源:index.py

示例2: connect

# 需要导入模块: from models.user import UserModel [as 别名]
# 或者: from models.user.UserModel import save [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.save方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。