本文整理汇总了Python中models.UserInfo.key方法的典型用法代码示例。如果您正苦于以下问题:Python UserInfo.key方法的具体用法?Python UserInfo.key怎么用?Python UserInfo.key使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.UserInfo
的用法示例。
在下文中一共展示了UserInfo.key方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get
# 需要导入模块: from models import UserInfo [as 别名]
# 或者: from models.UserInfo import key [as 别名]
def get(self):
user = users.get_current_user()
if user:
auth_token = self.request.get("oauth_token")
if auth_token:
credentials = constants.get_client().get_credentials(auth_token)
old_userinfos = UserInfo.all().filter('user =', user).fetch(500)
db.delete(old_userinfos)
userinfo = UserInfo(user = user, token = credentials['token'], secret = credentials['secret'], is_ready=False, is_authorized=True, last_checkin=0, last_updated=datetime.now(), color_scheme='fire', level_max=int(constants.level_const), checkin_count=0, venue_count=0)
fetch_foursquare_data.update_user_info(userinfo)
fetch_foursquare_data.fetch_and_store_checkins(userinfo, limit=10)
taskqueue.add(url='/fetch_foursquare_data/all_for_user/%s' % userinfo.key())#, queue_name='initial-checkin-fetching')
self.redirect("/")
else:
self.redirect(constants.get_client().get_authorization_url())
else:
self.redirect(users.create_login_url(self.request.uri))
示例2: get
# 需要导入模块: from models import UserInfo [as 别名]
# 或者: from models.UserInfo import key [as 别名]
def get(self):
user = users.get_current_user()
if user:
oauth_token = self.request.get("oauth_token")
def get_new_fs_and_credentials():
oauth_token, oauth_secret = constants.get_oauth_strings()
credentials = foursquare.OAuthCredentials(oauth_token, oauth_secret)
fs = foursquare.Foursquare(credentials)
return fs, credentials
if oauth_token:
old_userinfos = UserInfo.all().filter('user =', user).fetch(500)
db.delete(old_userinfos)
fs, credentials = get_new_fs_and_credentials()
apptoken = AppToken.all().filter('token =', oauth_token).get()
try:
user_token = fs.access_token(oauth.OAuthToken(apptoken.token, apptoken.secret))
credentials.set_access_token(user_token)
userinfo = UserInfo(user = user, token = credentials.access_token.key, secret = credentials.access_token.secret, is_ready=False, is_authorized=True, last_checkin=0, last_updated=datetime.now(), color_scheme='fire', level_max=int(constants.level_const), checkin_count=0, venue_count=0)
except DownloadError, err:
if str(err).find('ApplicationError: 5') >= 0:
pass # if something bad happens on OAuth, then it currently just redirects to the signup page
#TODO find a better way to handle this case, but it's not clear there is a simple way to do it without messing up a bunch of code
else:
raise err
try:
fetch_foursquare_data.update_user_info(userinfo)
fetch_foursquare_data.fetch_and_store_checkins(userinfo, limit=10)
taskqueue.add(url='/fetch_foursquare_data/all_for_user/%s' % userinfo.key())
except foursquare.FoursquareRemoteException, err:
if str(err).find('403 Forbidden') >= 0:
pass # if a user tries to sign up while my app is blocked, then it currently just redirects to the signup page
#TODO find a better way to handle this case, but it's not clear there is a simple way to do it without messing up a bunch of code
else:
raise err
except DownloadError:
pass #TODO make this better, but I'd rather throw the user back to the main page to try again than show the user an error.