本文整理匯總了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')
示例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