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


Python User.current_user方法代码示例

本文整理汇总了Python中parse_rest.user.User.current_user方法的典型用法代码示例。如果您正苦于以下问题:Python User.current_user方法的具体用法?Python User.current_user怎么用?Python User.current_user使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在parse_rest.user.User的用法示例。


在下文中一共展示了User.current_user方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: PUT

# 需要导入模块: from parse_rest.user import User [as 别名]
# 或者: from parse_rest.user.User import current_user [as 别名]
 def PUT(self, request, post_id):
     story = models.story.Story.active_story()
     if not story:
         return ("", 400)
     elif not story.accepting_snippets():
         return ("", 429)
         
     post = models.post.Post.get(post_id)
     if not post:
         return ("", 404)
         
     voted_users = [user['objectId'] for user in post.voted_users]
     if User.current_user().objectId not in voted_users:
         post.voted_users.append(User.current_user())
     
     post.save()
     
     refresh = False
     if len(post.voted_users) >= models.post.Post.max_vote_count():
         story.accept_post(post)
         story.save()
         
         refresh = True
     
     return json.dumps({
         'votes': len(post.voted_users),
         'refresh': refresh
     })
开发者ID:TheAppCookbook,项目名称:snipppit,代码行数:30,代码来源:post.py

示例2: GET

# 需要导入模块: from parse_rest.user import User [as 别名]
# 或者: from parse_rest.user.User import current_user [as 别名]
 def GET(self, request, story_id):        
     story = models.story.Story.get(story_id)
     if not story:
         story = models.story.Story.active_story()
         
     accepted_posts = sorted([
         models.post.Post.get(post['objectId'])
         for post in story.accepted_posts
     ], cmp=lambda x, y: 1 if x.createdAt > y.createdAt else -1)
     
     snippets = sorted([
         models.post.Post.get(post['objectId'])
         for post in story.snippets
     ], cmp=models.post.comparePosts)
     
     initials = ":)"
     if self.session(request):
         with SessionToken(self.session(request)):
             user = User.current_user()
             initials = user.first_name[0] + user.last_name[0]
     
     return flask.render_template(
         "story.html",
         story=story,
         accepted_posts=accepted_posts,
         snippets=snippets,
         
         initials = initials,
         session = self.session(request),
         
         max_vote_count=models.post.Post.max_vote_count(),
         user_voted_story=story.user_voted(self.session(request)),
         
         text_length=models.post.Post.text_length
     )
开发者ID:TheAppCookbook,项目名称:snipppit,代码行数:37,代码来源:story.py

示例3: user_calleft

# 需要导入模块: from parse_rest.user import User [as 别名]
# 或者: from parse_rest.user.User import current_user [as 别名]
def user_calleft(token):
    if request.method == 'GET':
        session_token  = token
        with SessionToken(session_token):
            me = User.current_user()
            me.calleft = user_calories(token) - me.feed['calories']
            me.save()
            return me.calleft
开发者ID:CapsLockHacks,项目名称:hackNSIT-backend,代码行数:10,代码来源:api.py

示例4: user_calories

# 需要导入模块: from parse_rest.user import User [as 别名]
# 或者: from parse_rest.user.User import current_user [as 别名]
def user_calories(token):
    if request.method == 'GET':
        session_token  = token
        with SessionToken(session_token):
            me = User.current_user()
            me.calories = str(float(me.weight) * 33 )
            me.save()
            return me.calories
开发者ID:CapsLockHacks,项目名称:hackNSIT-backend,代码行数:10,代码来源:api.py

示例5: user_voted

# 需要导入模块: from parse_rest.user import User [as 别名]
# 或者: from parse_rest.user.User import current_user [as 别名]
 def user_voted(self, session):
     with SessionToken(session):
         for snippet in self.snippets:
             post = Post.get(snippet['objectId'])
             user_voted = bool([
                 user for user in post.voted_users
                 if user['objectId'] == User.current_user().objectId
             ])
             
             if user_voted:
                 return True
         return False
开发者ID:TheAppCookbook,项目名称:snipppit,代码行数:14,代码来源:story.py

示例6: DELETE

# 需要导入模块: from parse_rest.user import User [as 别名]
# 或者: from parse_rest.user.User import current_user [as 别名]
 def DELETE(self, request, post_id):
     story = models.story.Story.active_story()
     if not story:
         return ("", 400)
     elif not story.accepting_snippets():
         return ("", 429)
         
     post = models.post.Post.get(post_id)
     if not post:
         return ("", 404)
         
     voted_users = [user['objectId'] for user in post.voted_users]
     if User.current_user().objectId in voted_users:
         post.voted_users = [
             user for user in post.voted_users
             if user['objectId'] != User.current_user().objectId
         ]
     
     post.save()
     return json.dumps({
         'votes': len(post.voted_users)
     })
开发者ID:TheAppCookbook,项目名称:snipppit,代码行数:24,代码来源:post.py

示例7: testCanGetCurrentUser

# 需要导入模块: from parse_rest.user import User [as 别名]
# 或者: from parse_rest.user.User import current_user [as 别名]
    def testCanGetCurrentUser(self):
        user = User.signup(self.username, self.password)
        self.assertIsNotNone(user.sessionToken)

        register(
            getattr(settings_local, 'APPLICATION_ID'),
            getattr(settings_local, 'REST_API_KEY'),
            session_token=user.sessionToken
        )

        current_user = User.current_user()
        self.assertIsNotNone(current_user)
        self.assertEqual(current_user.sessionToken, user.sessionToken)
        self.assertEqual(current_user.username, user.username)
开发者ID:avinsrid,项目名称:ParsePy,代码行数:16,代码来源:tests.py

示例8: user_feed

# 需要导入模块: from parse_rest.user import User [as 别名]
# 或者: from parse_rest.user.User import current_user [as 别名]
def user_feed(token):
    if request.method == 'GET':
        session_token  = token
        with SessionToken(session_token):
            me = User.current_user()
            me.calconsumed = 0
            print(me.feed)

            for i in me.feed:
                j = json.loads(i)
                #print(j)
                me.calconsumed = str(int(j['calories']) + int(me.calconsumed))
            me.save()
            return me.calconsumed
开发者ID:CapsLockHacks,项目名称:hackNSIT-backend,代码行数:16,代码来源:api.py

示例9: POST

# 需要导入模块: from parse_rest.user import User [as 别名]
# 或者: from parse_rest.user.User import current_user [as 别名]
 def POST(self, request):
     story = models.story.Story.active_story()
     if not story:
         return ("Cannot find active story", 400)
         
     post = models.post.Post(
         text=request.values.get("text"),
         author=User.current_user(),
         voted_users=[],
         archived=False
     )
     
     if not post or not post.valid():
         return ("Post invalid " + str(post), 400)
         
     post.save()
     
     story.snippets.append(post)
     story.save()
     
     return flask.redirect('/')
开发者ID:TheAppCookbook,项目名称:snipppit,代码行数:23,代码来源:post.py

示例10: user_voted

# 需要导入模块: from parse_rest.user import User [as 别名]
# 或者: from parse_rest.user.User import current_user [as 别名]
 def user_voted(self, session):
     with SessionToken(session):        
         return bool([
             user for user in self.voted_users
             if user['objectId'] == User.current_user().objectId
         ])
开发者ID:TheAppCookbook,项目名称:snipppit,代码行数:8,代码来源:post.py

示例11: GetCurrentUser

# 需要导入模块: from parse_rest.user import User [as 别名]
# 或者: from parse_rest.user.User import current_user [as 别名]
def GetCurrentUser():
	token = session.get('session_token')
	settings_local.initParse(token)
	me = User.current_user()
	return me
开发者ID:jaygagnani,项目名称:Punchit.io_website_master,代码行数:7,代码来源:hello.py


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