本文整理汇总了Python中models.User.User.get_by_key_name方法的典型用法代码示例。如果您正苦于以下问题:Python User.get_by_key_name方法的具体用法?Python User.get_by_key_name怎么用?Python User.get_by_key_name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.User.User
的用法示例。
在下文中一共展示了User.get_by_key_name方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post
# 需要导入模块: from models.User import User [as 别名]
# 或者: from models.User.User import get_by_key_name [as 别名]
def post(self):
session = is_logged_in(self)
if not session:
return
req = self.request
errors = {}
dn = validate_string(req, errors, 'dname', 'display name', 100)
email = validate_string(req, errors, 'email', 'email', 100)
if len(errors):
return self.redirect_to_self(errors)
uid = session['my_id']
user = User.get_by_key_name(uid)
if user.display_name!=dn or user.email!=email:
str_update = "dn=%s email=%s ==> dn=%s email=%s" % (user.display_name, user.email, dn, email)
user.display_name = dn
user.email = email
try:
user.put()
except Exception, e:
logging.info("Unable to update user profile: " + str_update)
return self.redirect_to_self({'err':'Unable to update your profile. Please try again later'})
# profile has been updated
session['my_dname'] = dn
session['my_email'] = email
logging.info("Updated user profile: " + str_update)
memcache.delete('u+c%s' % uid) # clear saved user_info
self.redirect('/profile/update?info=Your%20profile%20has%20been%20updated.')
示例2: get
# 需要导入模块: from models.User import User [as 别名]
# 或者: from models.User.User import get_by_key_name [as 别名]
def get(self):
session = is_logged_in(self)
if not session:
return self.redirect(REDIR_URL)
feed_key_name = self.request.get('f')
if not feed_key_name:
return self.redirect('/tracker')
# remove the feed from this user's record
user = User.get_by_key_name(session['my_id'])
n = len(user.feeds)
for i in xrange(len(user.feeds)):
if user.feeds[i] == feed_key_name:
user.feed_names = user.feed_names[:i-1] + user.feed_names[i+1:]
user.feeds = user.feeds[:i-1] + user.feeds[i+1:]
break
user.put()
if n > len(user.feeds):
self.redirect('/tracker?info=Success', 30*60)
# clear the memcache entry for this users' feeds
mckey = "user-feeds:%s" % session['my_id']
memcache.delete(mckey)
else:
self.redirect('/tracker?info=The%20feed%20you%20asked%20to%20stop%20tracking%20was%20not%20being%20tracked.')
示例3: post
# 需要导入模块: from models.User import User [as 别名]
# 或者: from models.User.User import get_by_key_name [as 别名]
def post(self):
session = is_logged_in(self)
if not session:
return self.redirect(REDIR_URL)
req = self.request
errors = {}
new_name = validate_string(req, errors, 'new_name', 'new search name', MAX_FEED_NAME_LEN)
if not new_name:
new_name = ''
if len(errors):
return self.redirect_to_self(GET_PARAMS, errors)
# update the search name
user = User.get_by_key_name(session['my_id'])
if not user:
logging.error('Unable to retrieve user record for a logged in user: %s' % session['my_id'])
return self.redirect('/?err=The service is temporarily unavailable - please try again later.')
feed_key = self.request.get('f')
if feed_key not in user.feeds:
return self.redirect("/tracker&err=You%20can't%20rename%20a%20search%20you%20aren't%20tracking.")
for i in xrange(len(user.feeds)):
if user.feeds[i] == feed_key:
user.feed_names[i] = new_name
break
try:
user.put()
except:
logging.error('Unable to update user record for logged in user: %s' % session['my_id'])
return self.redirect('/tracker?err=The service is temporarily unavailable - please try again later.')
# invalidate the memcache entry for this users' feeds if it exists
mckey = "user-feeds:%s" % session['my_id']
feed_infos = memcache.delete(mckey)
# redirect the user to the feed page
self.redirect('/view?t=newest&f=%s' % urllib.quote(feed_key))