Beispiel #1
0
    def createTemplateValues(self, url):
        templateValues = {}
        point = None
        pointRoot = None

        if url:
            point, pointRoot = yield Point.findCurrent_async(url)
            if point.url != url:
                self.redirect(str(point.url))
        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!
            user = self.current_user

            if user:
                user.updateRecentlyViewed(point.key.parent())
                user.getActiveNotifications()
            templateValues = {
                'user': user,
                'currentArea':self.session.get('currentArea'),
                'currentAreaDisplayName':self.session.get('currentAreaDisplayName'),
                'notifications': user.notifications if user else None
            }

        self.add_react_json(templateValues)
        raise ndb.Return(templateValues)
Beispiel #2
0
    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)          
Beispiel #3
0
    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)