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


Python Point.getCurrentByRootKey方法代码示例

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


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

示例1: relevanceVote

# 需要导入模块: from models.point import Point [as 别名]
# 或者: from models.point.Point import getCurrentByRootKey [as 别名]
 def relevanceVote(self):
     resultJSON = json.dumps({'result': False})
     parentRootURLsafe = self.request.get('parentRootURLsafe')
     childRootURLsafe = self.request.get('childRootURLsafe')
     linkType = self.request.get('linkType')
     vote = self.request.get('vote')        
     user = self.current_user
     
     if int(vote) > 100 or int(vote) < 0:
         resultJSON = json.dumps({'result': False, 'error':'Vote value out of range.'})
         
     # logging.info('ABOUT TO CHECK ALL THE DATA 1:%s 2:%s 3:%s 4:%s ' % (parentRootURLsafe,childRootURLsafe,linkType, vote))
     elif parentRootURLsafe and childRootURLsafe and linkType and user:
         result, newRelevance, newVoteCount = user.addRelevanceVote(
             parentRootURLsafe, childRootURLsafe, linkType, int(vote))
         if result:
             # Hacky, parent score retrieval could be pushed into addRelevanceVote
             parentNewScore = None
             parentPoint, parentPointRoot = Point.getCurrentByRootKey(parentRootURLsafe)
             if parentPoint:
                 parentNewScore = parentPoint.pointValue()
             else:
                 parentNewScore = -999
             resultJSON = json.dumps({
                 'result': True, 
                 'newVote': vote,
                 'newRelevance': str(newRelevance) + '%',
                 'newVoteCount': newVoteCount,
                 'parentNewScore': parentNewScore
             })
     self.response.headers["Content-Type"] = 'application/json; charset=utf-8'
     self.response.out.write(resultJSON)       
开发者ID:aaronlifshin,项目名称:whysaurus,代码行数:34,代码来源:vote.py

示例2: post

# 需要导入模块: from models.point import Point [as 别名]
# 或者: from models.point.Point import getCurrentByRootKey [as 别名]
 def post(self, pointURL):
     rootKey = self.request.get('rootKey')
     point, pointRoot = Point.getCurrentByRootKey(rootKey)
     template_values = self.createTemplateValues(point, pointRoot)        
     self.outputTemplateValues(template_values)
开发者ID:aaronlifshin,项目名称:howtosavedemocaracy,代码行数:7,代码来源:viewpoint.py

示例3: createTemplateValues

# 需要导入模块: from models.point import Point [as 别名]
# 或者: from models.point.Point import getCurrentByRootKey [as 别名]
    def createTemplateValues(self, url=None, full=True, rootKey=None):
        newURL = None
        templateValues = {}
        point = None
        pointRoot = None
        
        if url:
            point, pointRoot = yield Point.findCurrent_async(url)
        elif rootKey:
            point, pointRoot = Point.getCurrentByRootKey(rootKey)  
        else:    
            templateValues = {
               'user': self.current_user,
               'message': "URL or Key must be supplied.",
               'currentArea': self.session.get('currentArea'),
               'currentAreaDisplayName': self.session.get('currentAreaDisplayName')
            }            
            
        if not point:
            templateValues = {
               'user': self.current_user,
               'message': "Could not find point. Some points are in private classrooms and you \
               need to be logged in and authorized to view them.",
               'currentArea': self.session.get('currentArea'),
               'currentAreaDisplayName': self.session.get('currentAreaDisplayName')               
            }
        else:   # we have a point!
            voteValue = 0
            ribbonValue = False
            addedToRecentlyViewed = False                        
            user = self.current_user    
            
            # supportingPoints, counterPoints = point.getAllLinkedPoints(user)
          
            # We need to get the recently viewed points here
            # Because the user can add them as counter/supporting points
            if user:                
                vote, relevanceVotes, recentlyViewed, sources, supportingPoints, counterPoints = yield \
                    user.getVote_async(point.key.parent()), \
                    user.getRelevanceVotes_async(point), \
                    user.getRecentlyViewed_async( \
                        excludeList=[point.key.parent()] + \
                        point.getLinkedPointsRootKeys("supporting") + \
                        point.getLinkedPointsRootKeys("counter")), \
                    point.getSources_async(), \
                    point.getLinkedPoints_async("supporting", user), \
                    point.getLinkedPoints_async("counter", user)
                point.addRelevanceVotes(relevanceVotes, supportingPoints, counterPoints)

                addedToRecentlyViewed = user.updateRecentlyViewed(point.key.parent())
            else:
                sources, supportingPoints, counterPoints = yield point.getSources_async(), \
                    point.getLinkedPoints_async("supporting", None), \
                    point.getLinkedPoints_async("counter", None)
                recentlyViewed = None
            
            # For now add to a point's view count if user is not logged in or if view point is added to the recently viewed list
            if addedToRecentlyViewed or not user:
                viewCountFuture = pointRoot.addViewCount()
        
            if user:
                voteValue = vote.value if vote else 0
                ribbonValue = vote.ribbon if vote else False
                
            # viewCountFuture.get_result()
            templateValues = {
                'point': point,
                'pointRoot': pointRoot,
                'recentlyViewedPoints': recentlyViewed,
                'supportingPoints': supportingPoints,
                'counterPoints': counterPoints,
                'supportedPoints':pointRoot.getBacklinkPoints("supporting"),
                'counteredPoints':pointRoot.getBacklinkPoints("counter"),
                'sources': sources,
                'user': user,
                'voteValue': voteValue,
                'ribbonValue': ribbonValue,
                'currentArea':self.session.get('currentArea'),
                'currentAreaDisplayName':self.session.get('currentAreaDisplayName')
            }
            
            if full:
                if user:
                    user.getActiveNotifications()
                templateValues['notifications'] =  user.notifications if user else None,
                templateValues['comments'] = pointRoot.getComments()
                                
        raise ndb.Return(templateValues)          
开发者ID:,项目名称:,代码行数:90,代码来源:


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