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


Python User.get_by_key_name方法代码示例

本文整理汇总了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")
开发者ID:buger,项目名称:flick_faver,代码行数:62,代码来源:main.py

示例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
开发者ID:tghali,项目名称:EEU,代码行数:28,代码来源:base.py

示例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")
开发者ID:Idrissa,项目名称:AlloSanteMob,代码行数:12,代码来源:user.py

示例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))
开发者ID:Idrissa,项目名称:AlloSanteMob,代码行数:15,代码来源:user.py

示例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}')
开发者ID:oceancreatures,项目名称:rhapsody-scrobbler,代码行数:23,代码来源:handlers.py

示例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
开发者ID:dweitz,项目名称:the-blue-alliance,代码行数:25,代码来源:base_controller.py


注:本文中的models.user.User.get_by_key_name方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。