本文整理汇总了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方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import get_by_key_name [as 别名]
def get(self):
if self.request.get('userid'):
user_info = flickr.FlickrUserInfo("", self.request.get('userid'), self.request.get('userid'), "")
else:
frob = self.request.get('frob')
try:
user_info = flickr.get_user_info(frob)
except:
user_info = flickr.get_user_info(frob)
user = User.get_by_key_name(user_info.nsid)
session = Session()
if user is None:
user = User(key_name = user_info.nsid,
username = user_info.username,
fullname = user_info.fullname,
token = user_info.token,
status = const.UserRegistred,
last_login = datetime.datetime.now())
task = None
if not user.is_saved() or user.status == const.UserUnRegistred:
task = taskqueue.Task(url="/task/user/update_contacts",
params={'key':user.key(), 'update_favorites':True, 'initial_update': True})
user.status = const.UserRegistred
user.username = user_info.username
user.fullname = user.fullname
user.token = user_info.token
if os.environ.get('SERVER_SOFTWARE') == 'Development/1.0':
user.token = '72157623100491721-4ab7039d8e6b4615'
#user.token = '72157622500427269-7131c791b2204f16'
user.last_login = datetime.datetime.now()
try:
user.put()
except:
user.put()
if task:
task.add("non-blocking")
session["username"] = user.username
if user.fullname:
session["fullname"] = user.fullname
session["nsid"] = user.nsid
session["auth_token"] = user.token
session["difficulty"] = user.difficulty
session["layout"] = user.layout
self.redirect("/dashboard")
示例2: init_facebook
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import get_by_key_name [as 别名]
def init_facebook(self):
"""Sets up the request specific Facebook and User instance"""
facebook = Facebook()
user = None
# initial facebook request comes in as a POST with a signed_request
if u'signed_request' in self.request.POST:
facebook.load_signed_request(self.request.get('signed_request'))
# we reset the method to GET because a request from facebook with a
# signed_request uses POST for security reasons, despite it
# actually being a GET. in webapp causes loss of request.POST data.
self.request.method = u'GET'
self.set_cookie('u', facebook.user_cookie, datetime.timedelta(minutes=1440))
elif 'u' in self.request.cookies:
facebook.load_signed_request(self.request.cookies.get('u'))
# try to load or create a user object
if facebook.user_id:
user = User.get_by_key_name(facebook.user_id)
if user:
user.refresh_data(facebook)
if not user and facebook.access_token:
user = User.create(facebook)
self.facebook = facebook
self.user = user
示例3: post
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import get_by_key_name [as 别名]
def post(self):
userid = users.get_current_user()
user = User.get_by_key_name(userid.nickname())
if user:
user.first_name = self.request.get("first_name")
user.last_name = self.request.get("last_name")
user.put()
logging.info("Updated user %s", userid.nickname())
# TODO(xdecoret) add notice when redirecting
self.redirect("/user")
示例4: get
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import get_by_key_name [as 别名]
def get(self):
values = {}
values.update(self.CommonValues())
# Search for a user, and if none, create one
userid = users.get_current_user()
user = User.get_by_key_name(userid.nickname())
if not user:
user = User(key_name=userid.nickname())
user.userid = userid
user.put()
logging.info("Created user %s", userid.nickname())
values.update(user=user)
self.response.out.write(template.render("templates/user.html", values))
示例5: get
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import get_by_key_name [as 别名]
def get(self):
self.response.headers['Content-Type'] = 'application/json'
username = self.request.get('username')
password = self.request.get('password')
if not password:
user = User.get_by_key_name(username)
password = user.password
else:
password = hashlib.md5(password).hexdigest()
poster = audioscrobbler.AudioScrobblerPost(
username=username,
password=password,
password_is_md5=True)
try:
poster.auth()
# Login ok
self.response.out.write('{"isOk": true}')
except audioscrobbler.AudioScrobblerPostBadAuth:
self.response.out.write('{"isOk": false}')
示例6: current_user
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import get_by_key_name [as 别名]
def current_user(self):
if not hasattr(self, "_current_user"):
self._current_user = None
cookie = facebook.get_user_from_cookie(
self.request.cookies, tba_config.CONFIG['FACEBOOK_APP_ID'], tba_config.CONFIG['FACEBOOK_APP_SECRET'])
if cookie:
# Store a local instance of the user data so we don't need
# a round-trip to Facebook on every request
user = User.get_by_key_name(cookie["uid"])
if not user:
graph = facebook.GraphAPI(cookie["access_token"])
profile = graph.get_object("me")
user = User(key_name=str(profile["id"]),
id=str(profile["id"]),
name=profile["name"],
profile_url=profile["link"],
access_token=cookie["access_token"])
user.put()
elif user.access_token != cookie["access_token"]:
user.access_token = cookie["access_token"]
user.put()
self._current_user = user
return self._current_user