Пример #1
0
 def get(self):
     user = self.current_user
     linkType = 'supporting'
     p1, pRoot1 = Point.getCurrentByUrl('CCC')
     p2, pRoot2 = Point.getCurrentByUrl('bbb')
     
     #result, newRelevance, newVoteCount = \        
     #    user.addRelevanceVote(pRoot1.key.urlsafe(), pRoot2.key.urlsafe(), linkType, 50) 
     """newRelVote = RelevanceVote(
         parent=user.key,
         parentPointRootKey = pRoot1.key,
         childPointRootKey = pRoot2.key,
         value = 50,
         linkType=linkType)
     newRelVote.put()"""
         
     # GET THE VOTE BACK
     q = RelevanceVote.query(RelevanceVote.parentPointRootKey == pRoot1.key,
        RelevanceVote.childPointRootKey == pRoot2.key, 
        RelevanceVote.linkType == linkType)
     votes = q.fetch(20)       
     message = ""
     message = 'Got %d votes on retrieval.' % len(votes) 
     template_values = {
         'user': user,
         'message': message,            
         'currentArea':self.session.get('currentArea'),
         'currentAreaDisplayName':self.session.get('currentAreaDisplayName')    
     }
     self.response.out.write(self.template_render('message.html', template_values))        
Пример #2
0
    def mutate(self, info, url, parentURL, linkType):
        supportingPoint, supportingPointRoot = PointModel.getCurrentByUrl(url)
        oldPoint, oldPointRoot = PointModel.getCurrentByUrl(parentURL)
        user = info.context.current_user
        if user:
            # NOTE: ported this over from handlers/linkpoint.py, don't totally understand it all
            # This code is if the vote existed before and the point was unlinked, and now
            # it is being re-linked
            voteCount, rating, myVote = RelevanceVoteModel.getExistingVoteNumbers(
                oldPointRoot.key, supportingPointRoot.key, linkType, user)
            supportingPoint._relevanceVote = myVote
            newLink = [{
                'pointRoot': supportingPointRoot,
                'pointCurrentVersion': supportingPoint,
                'linkType': linkType,
                'voteCount': voteCount,
                'fRating': rating
            }]
            newVersion = oldPoint.update(pointsToLink=newLink, user=user)
            user.addRelevanceVote(oldPointRoot.key.urlsafe(),
                                  supportingPointRoot.key.urlsafe(), linkType,
                                  100)

            # get my vote for this point, to render it in the linkPoint template
            supportingPoint.addVote(user)

            # these two are in service of the SubPointConnection logic - we should find a way to DRY this up
            supportingPoint.parent = newVersion
            supportingPoint.link_type = linkType

            return LinkPoint(parent=newVersion, point=supportingPoint)
        else:
            raise Exception("User not logged in.")
Пример #3
0
    def post(self):
        resultJSON = json.dumps({'result': False})
        supportingPoint, supportingPointRoot = Point.getCurrentByUrl(self.request.get('supportingPointURL'))
        oldPoint, oldPointRoot = Point.getCurrentByUrl(self.request.get('parentPointURL'))
        user = self.current_user
        linkType = self.request.get('linkType')

        if user:
            try:
                newLink = [{'pointRoot':supportingPointRoot,
                            'pointCurrentVersion':supportingPoint,
                            'linkType':self.request.get('linkType')}
                            ]
                oldPoint.update(
                    pointsToLink=newLink,
                    user=user
                )
            except WhysaurusException as e:
                resultJSON = json.dumps({'result': False, 'error': str(e)})
            else:
                path = os.path.join(constants.ROOT, 'templates/pointBox.html')
                newLinkPointHTML = json.dumps(template.render(path, {'point': supportingPoint}))
                resultJSON = json.dumps({'result': True,
                                         'numLinkPoints': supportingPoint.linkCount(linkType),
                                         'newLinkPoint':newLinkPointHTML})
        else:
            resultJSON = json.dumps({'result': 'ACCESS DENIED!'})
        self.response.headers.add_header('content-type', 'application/json', charset='utf-8')
        self.response.out.write(resultJSON)
Пример #4
0
    def post(self):
        jsonOutput = {'result': False}
        user = self.current_user
        linkType = self.request.get('linkType')
        sourcesURLs=json.loads(self.request.get('sourcesURLs'))
        sourcesNames=json.loads(self.request.get('sourcesNames'))
        parentNewScore = None
        
        if user:   
            try:       
                parentPointURL = self.request.get('pointUrl')
                oldPoint, oldPointRoot = Point.getCurrentByUrl(parentPointURL)
                if oldPointRoot:
                    newPoint, newLinkPoint = Point.addSupportingPoint(
                        oldPointRoot=oldPointRoot,
                        title=self.request.get('title'),
                        content=self.request.get('content'),
                        summaryText=self.request.get('plainText'),
                        user=user,
                        # backlink=oldPoint.key.parent(),
                        linkType = linkType,
                        imageURL=self.request.get('imageURL'),
                        imageAuthor=self.request.get('imageAuthor'),
                        imageDescription=self.request.get('imageDescription'),
                        sourcesURLs=sourcesURLs,
                        sourcesNames=sourcesNames            
                    )

                    # TODO: Gene: Probably have a more efficient retrieval here no?
                    oldPoint, oldPointRoot = Point.getCurrentByUrl(parentPointURL)
                    if oldPoint:
                        parentNewScore = oldPoint.pointValue()
                else:
                    raise WhysaurusException('Point with URL %s not found' % parentPointURL)
            except WhysaurusException as e:
                jsonOutput = {
                    'result': False,
                    'errMessage': str(e)
                }
            else:
                ReportEvent.queueEventRecord(user.key.urlsafe(), newLinkPoint.key.urlsafe(), newPoint.key.urlsafe(), "Create Point")           
                newLinkPointHTML = self.template_render('linkPoint.html', {
                    'point': newLinkPoint,
                    'linkType': linkType
                })
                jsonOutput = {
                    'result': True,
                    'version': newPoint.version,
                    'author': newPoint.authorName,
                    'dateEdited': newPoint.PSTdateEdited.strftime('%b. %d, %Y, %I:%M %p'),
                    'numLinkPoints': newPoint.linkCount(linkType),
                    'newLinkPoint': newLinkPointHTML,
                    'authorURL': self.current_user.url,
                    'parentNewScore': parentNewScore
                }
            self.response.headers["Content-Type"] = 'application/json; charset=utf-8'      
            self.response.out.write(json.dumps(jsonOutput))
        else:
            self.response.out.write('Need to be logged in')
Пример #5
0
    def post(self):
        self.response.headers["Content-Type"] = "application/json; charset=utf-8"
        resultJSON = json.dumps({"result": False})
        supportingPoint, supportingPointRoot = Point.getCurrentByUrl(self.request.get("supportingPointURL"))
        oldPoint, oldPointRoot = Point.getCurrentByUrl(self.request.get("parentPointURL"))
        user = self.current_user
        linkType = self.request.get("linkType")

        if user:
            try:
                # This code is if the vote existed before and the point was unlinked, and now
                # it is being re-linked
                voteCount, rating, myVote = RelevanceVote.getExistingVoteNumbers(
                    oldPointRoot.key, supportingPointRoot.key, linkType, user
                )
                supportingPoint._relevanceVote = myVote
                linkType = self.request.get("linkType")
                newLink = [
                    {
                        "pointRoot": supportingPointRoot,
                        "pointCurrentVersion": supportingPoint,
                        "linkType": linkType,
                        "voteCount": voteCount,
                        "fRating": rating,
                    }
                ]
                newVersion = oldPoint.update(pointsToLink=newLink, user=user)
                user.addRelevanceVote(oldPointRoot.key.urlsafe(), supportingPointRoot.key.urlsafe(), linkType, 100)

                # get my vote for this point, to render it in the linkPoint template
                supportingPoint.addVote(user)
            except WhysaurusException as e:
                resultJSON = json.dumps({"result": False, "error": e.message})
            else:
                if newVersion:
                    newLinkPointHTML = self.template_render(
                        "linkPoint.html", {"point": supportingPoint, "linkType": linkType}
                    )
                    resultJSON = json.dumps(
                        {
                            "result": True,
                            "numLinkPoints": newVersion.linkCount(linkType),
                            "newLinkPoint": newLinkPointHTML,
                            "authorURL": self.current_user.url,
                            "author": newVersion.authorName,
                            "dateEdited": newVersion.PSTdateEdited.strftime("%b. %d, %Y, %I:%M %p"),
                        }
                    )
                else:
                    json.dumps({"result": False, "error": "There was a problem updating the point."})
        else:
            resultJSON = json.dumps({"result": "User not logged in. ACCESS DENIED!"})
        self.response.out.write(resultJSON)
Пример #6
0
    def post(self):
        self.response.headers["Content-Type"] = 'application/json; charset=utf-8'        
        resultJSON = json.dumps({'result': False})
        supportingPoint, supportingPointRoot = Point.getCurrentByUrl(self.request.get('supportingPointURL'))
        oldPoint, oldPointRoot = Point.getCurrentByUrl(self.request.get('parentPointURL'))
        user = self.current_user
        linkType = self.request.get('linkType')

        if user:
            try:     
                # This code is if the vote existed before and the point was unlinked, and now 
                # it is being re-linked                           
                voteCount, rating, myVote = RelevanceVote.getExistingVoteNumbers(
                    oldPointRoot.key, supportingPointRoot.key, linkType, user)
                supportingPoint._relevanceVote = myVote
                linkType = self.request.get('linkType')
                newLink = [{'pointRoot':supportingPointRoot,
                            'pointCurrentVersion':supportingPoint,
                            'linkType':linkType,
                            'voteCount': voteCount,
                            'fRating':rating }
                            ]
                newVersion = oldPoint.update(
                    pointsToLink=newLink,
                    user=user
                )
                user.addRelevanceVote(
                  oldPointRoot.key.urlsafe(), 
                  supportingPointRoot.key.urlsafe(), linkType, 100)   

                # get my vote for this point, to render it in the linkPoint template
                supportingPoint.addVote(user)
            except WhysaurusException as e:
                resultJSON = json.dumps({'result': False, 'error': e.message})
            else:
                if newVersion:
                    newLinkPointHTML = self.template_render('linkPoint.html', {
                        'point': supportingPoint, 
                        'linkType': linkType
                    })
                    resultJSON = json.dumps({
                        'result': True,
                        'numLinkPoints': newVersion.linkCount(linkType),
                        'newLinkPoint':newLinkPointHTML,
                        'authorURL': self.current_user.url,
                        'author': newVersion.authorName, 
                        'dateEdited': newVersion.PSTdateEdited.strftime('%b. %d, %Y, %I:%M %p'),                                                      
                    })
                else:
                    json.dumps({'result': False, 'error': 'There was a problem updating the point.'})
        else:
            resultJSON = json.dumps({'result': 'User not logged in. ACCESS DENIED!'})
        self.response.out.write(resultJSON)
Пример #7
0
    def getPointCreator(self):
        result = {'result': False}
        point, pointRoot = Point.getCurrentByUrl(self.request.get('pointURL'))
        versionsOfThisPoint = Point.query(ancestor=pointRoot.key).order(
            Point.version)
        firstVersion = versionsOfThisPoint.get()

        authors = []
        """code for listing number of contributors"""
        """
        for point in versionsOfThisPoint:
            thisAuthor = {"authorName": point.authorName, "authorURL": point.authorURL }
            if thisAuthor not in authors:
                authors.append(thisAuthor)
        """

        resultJSON = json.dumps({
            'result': True,
            'creatorName': firstVersion.authorName,
            'creatorURL': firstVersion.authorURL,
            'numAuthors': len(authors)
        })
        self.response.headers[
            "Content-Type"] = 'application/json; charset=utf-8'
        self.response.out.write(resultJSON)
Пример #8
0
    def checkDBPoint(self, pointURL):
        point, pointRoot = Point.getCurrentByUrl(pointURL)

        if point:
            isError1, messages1 = self.checkPointNew(point)

        if pointRoot:
            isError2, messages2 = self.checkRoot(pointRoot)

        if not isError1 and not isError2:
            message = 'No errors were found.'
        else:
            messages = []
            if messages1:
                messages += messages1
            if messages2:
                messages += messages2
            if messages == []:
                messages = ['Errors generated, but no messages generated.']

        template_values = {
            'messages': messages,
            'user': self.current_user,
            'currentArea': self.session.get('currentArea')
        }
        self.response.out.write(
            self.template_render('message.html', template_values))
Пример #9
0
 def getPointCreator(self):
     result = {'result': False}
     point, pointRoot = Point.getCurrentByUrl(self.request.get('pointURL'))
     versionsOfThisPoint = Point.query(ancestor=pointRoot.key).order(Point.version)
     firstVersion = versionsOfThisPoint.get()
     
     authors = []
     """code for listing number of contributors"""
     """
     for point in versionsOfThisPoint:
         thisAuthor = {"authorName": point.authorName, "authorURL": point.authorURL }
         if thisAuthor not in authors:
             authors.append(thisAuthor)
     """                
     
     resultJSON = json.dumps({
                 'result': True, 
                 'creatorName' : firstVersion.authorName,
                 'creatorURL'  : firstVersion.authorURL,
                 'numAuthors'  : len(authors)
             })
     self.response.headers["Content-Type"] = 'application/json; charset=utf-8'
     self.response.out.write(resultJSON) 
     
     
     
     
     
Пример #10
0
 def checkDBPointRoot(pointRoot):
     logging.info('Checking %s ' % pointRoot.url)
     point, pr = Point.getCurrentByUrl(pointRoot.url)
     isError1 = False
     isError2 = False
     messages1 = []
     messages2 = []
     
     dbc = DBIntegrityCheck()
     if point:
         isError1, messages1 = dbc.checkPoint(point)
         
     if pointRoot:
         isError2, messages2 = dbc.checkRoot(pointRoot)
     
     if not isError1 and not isError2:
         message = 'No errors were found in %s.' % pointRoot.url
         logging.info(message)                      
         
     else:
         message = []
         if messages1:
             message = message + messages1
         if messages2:
             message = message + messages2
         if message == []:
             message = ['Errors generated, but no messages generated.']
         if isError1:
             logging.info(messages1)
         if isError2:
             logging.info(messages2)  
         for m in message:
             logging.info(message)                      
     
     return message
Пример #11
0
    def checkDBPointRoot(pointRoot):
        logging.info('Checking %s ' % pointRoot.url)
        point, pr = Point.getCurrentByUrl(pointRoot.url)
        isError1 = False
        isError2 = False
        messages1 = []
        messages2 = []

        dbc = DBIntegrityCheck()
        if point:
            isError1, messages1 = dbc.checkPoint(point)

        if pointRoot:
            isError2, messages2 = dbc.checkRoot(pointRoot)

        if not isError1 and not isError2:
            message = 'No errors were found in %s.' % pointRoot.url
            logging.info(message)

        else:
            message = []
            if messages1:
                message = message + messages1
            if messages2:
                message = message + messages2
            if message == []:
                message = ['Errors generated, but no messages generated.']
            if isError1:
                logging.info(messages1)
            if isError2:
                logging.info(messages2)
            for m in message:
                logging.info(message)

        return message
Пример #12
0
 def checkDBPoint(self, pointURL):
     point, pointRoot = Point.getCurrentByUrl(pointURL)
     
     if point:
         isError1, messages1 = self.checkPointNew(point)
         
     if pointRoot:
         isError2, messages2 = self.checkRoot(pointRoot)
     
     if not isError1 and not isError2:
         message = 'No errors were found.'
     else:
         messages = []
         if messages1:
             messages += messages1
         if messages2:
             messages += messages2
         if messages == []:
             messages = ['Errors generated, but no messages generated.']
         
     template_values = {
         'messages': messages,            
         'user': self.current_user,
         'currentArea':self.session.get('currentArea')
     }
     self.response.out.write(self.template_render('message.html', template_values))        
Пример #13
0
    def mutate(self, info, linkType, url, parentRootURLsafe, rootURLsafe,
               vote):
        user = info.context.current_user
        point, pointRoot = PointModel.getCurrentByUrl(url)
        if point:
            if user:
                pp, ppr = PointModel.getCurrentByRootKey(parentRootURLsafe)

                result, newRelevance, newVoteCount = user.addRelevanceVote(
                    parentRootURLsafe, rootURLsafe, linkType, vote)
                if result:
                    return RelevanceVote(
                        point=point,
                        parentPoint=pp,
                        link=Link(type=linkType,
                                  relevance=newRelevance,
                                  sortScore=LinkModel.calcSortScore(
                                      newRelevance, point.pointValueCached),
                                  relevanceVote=vote,
                                  voteCount=newVoteCount,
                                  parentURLsafe=parentRootURLsafe,
                                  childURLsafe=rootURLsafe))
                else:
                    raise Exception(str('vote failed: ' + str(vote)))
            else:
                raise Exception(str('user not defined ' + str(user)))
        else:
            raise Exception(str('point not defined ' + str(point)))
Пример #14
0
    def post(self):

        resultJSON = json.dumps({'result': False})
        
        if self.current_user:
            if self.current_user.isLimited:
              resultJSON = json.dumps({'result': False, 'error': 'This account cannot unlink points.'})              
            elif self.request.get('mainPointURL'):
                mainPoint, pointRoot = Point.getCurrentByUrl(self.request.get('mainPointURL'))
                if self.request.get('supportingPointURL'):
                    supportingPointURL = self.request.get('supportingPointURL')
                    newVersion = mainPoint.unlink(self.request.get('supportingPointURL'), 
                                                  self.request.get('linkType'), 
                                                  self.current_user)
                    if newVersion:
                        resultJSON = json.dumps({
                            'result': True, 
                            'pointURL': supportingPointURL,
                            'authorURL': self.current_user.url,
                            'author': newVersion.authorName, 
                            'dateEdited': newVersion.PSTdateEdited.strftime('%b. %d, %Y, %I:%M %p'),
                        })
            else:
               resultJSON = json.dumps({'result': False, 'error': 'URL of main point was not supplied.'})                
        else:
            resultJSON = json.dumps({'result': False, 'error': 'You appear not to be logged in.'})
            
        self.response.headers["Content-Type"] = 'application/json; charset=utf-8'
        self.response.out.write(resultJSON)
Пример #15
0
 def mutate(self, info, url):
     user = info.context.current_user
     point, point_root = PointModel.getCurrentByUrl(url)
     result, msg = point_root.delete(user)
     if result:
         return Delete(url=url)
     else:
         raise Exception(str('delete failed: ' + msg))
Пример #16
0
 def mutate(self, info, parentURL, url, linkType):
     user = info.context.current_user
     point, point_root = PointModel.getCurrentByUrl(parentURL)
     new_version = point.unlink(url, linkType, user)
     if new_version:
         return Unlink(parentURL=parentURL, url=url)
     else:
         raise Exception(str('unlink failed:'))
Пример #17
0
 def post(self):
     resultJSON = json.dumps({'result': False})
     point, pointRoot = Point.getCurrentByUrl(self.request.get('pointURL'))
     user = self.current_user
     if point and user:
         if user.addVote(point, int(self.request.get('vote'))):
             resultJSON = json.dumps({'result': True, 'newVote': self.request.get('vote')})
     self.response.headers.add_header('content-type', 'application/json', charset='utf-8')
     self.response.out.write(resultJSON)
    def post(self):
        jsonOutput = {'result': False}
        oldPoint, oldPointRoot = Point.getCurrentByUrl(
            self.request.get('pointUrl'))
        user = self.current_user
        linkType = self.request.get('linkType')
        nodeType = self.request.get('nodeType') if \
            self.request.get('nodeType') else 'Point'

        sourcesURLs=json.loads(self.request.get('sourcesURLs'))
        sourcesNames=json.loads(self.request.get('sourcesNames'))
        if user:
            newLinkPoint, newLinkPointRoot = Point.create(
                title=self.request.get('title'),
                nodetype=nodeType,
                content=self.request.get('content'),
                summaryText=self.request.get('plainText'),
                user=user,
                backlink=oldPoint.key.parent(),
                linktype = linkType,
                imageURL=self.request.get('imageURL'),
                imageAuthor=self.request.get('imageAuthor'),
                imageDescription=self.request.get('imageDescription'),
                sourceURLs=sourcesURLs,
                sourceNames=sourcesNames)
            try:
                logging.info('Adding newLink: ' + linkType)
                newLinks = [{'pointRoot':newLinkPointRoot,
                            'pointCurrentVersion':newLinkPoint,
                            'linkType':linkType},
                            ]
                newPoint = oldPoint.update(
                    pointsToLink=newLinks,                 
                    user=user
                )
            except WhysaurusException as e:
                jsonOutput = {
                    'result': False,
                    'err': str(e)
                }
            else:
                path = os.path.join(constants.ROOT, 'templates/pointBox.html')
                newLinkPointHTML = json.dumps(template.render(path, {'point': newLinkPoint}))
                jsonOutput = {
                    'result': True,
                    'version': newPoint.version,
                    'author': newPoint.authorName,
                    'dateEdited': newPoint.dateEdited.strftime("%Y-%m-%d %H: %M: %S %p"),
                    'numLinkPoints': newPoint.linkCount(linkType),
                    'newLinkPoint':newLinkPointHTML
                }
            resultJSON = json.dumps(jsonOutput)
            self.response.headers.add_header('content-type', 'application/json', charset='utf-8')
            self.response.out.write(resultJSON)
        else:
            self.response.out.write('Need to be logged in')
Пример #19
0
 def mutate(self, info, point_data):
     point, pointRoot = PointModel.getCurrentByUrl(point_data.url)
     newPointVersion = point.update(
         user=info.context.current_user,
         newTitle=(point_data.title or point.title),
         imageURL=point_data.imageURL or point.imageURL,
         imageDescription=point_data.imageDescription
         or point.imageDescription,
     )
     return EditPoint(point=newPointVersion)
Пример #20
0
 def mutate(self, info, url, vote, parentURL=None):
     user = info.context.current_user
     point, pointRoot = PointModel.getCurrentByUrl(url)
     if point:
         if user:
             voteResult = user.addVote(point, vote)
             if voteResult:
                 point.updateBacklinkedSorts(pointRoot)
                 if parentURL:
                     pp, ppr = PointModel.getCurrentByUrl(parentURL)
                     return Vote(point=point, parentPoint=pp)
                 else:
                     return Vote(point=point, parentPoint=None)
             else:
                 raise Exception(str('vote failed: ' + str(vote)))
         else:
             raise Exception(str('user not defined ' + str(user)))
     else:
         raise Exception(str('point not defined ' + str(point)))
Пример #21
0
 def post(self):
     resultJSON = json.dumps({'result': False})
     point, pointRoot = Point.getCurrentByUrl(self.request.get('pointURL'))
     user = self.current_user
     newRibbonValue = self.request.get('ribbon') == 'true'
     if point and user:
         if user.setRibbon(point, newRibbonValue):
             resultJSON = json.dumps({'result': True, 'ribbonTotal': point.ribbonTotal})
     self.response.headers.add_header('content-type', 'application/json', charset='utf-8')
     self.response.out.write(resultJSON)
Пример #22
0
    def post(self):
        user = self.current_user
        if user:

            resultJSON = json.dumps({"result": False})
            oldPoint, oldPointRoot = Point.getCurrentByUrl(self.request.get("urlToEdit"))
            sourcesURLs = json.loads(self.request.get("sourcesURLs")) if self.request.get("sourcesURLs") else None
            sourcesNames = json.loads(self.request.get("sourcesNames")) if self.request.get("sourcesNames") else None
            sourcesToRemove = (
                json.loads(self.request.get("sourcesToRemove")) if self.request.get("sourcesToRemove") else None
            )
            if oldPoint == None:
                resultJSON = json.dumps(
                    {"result": False, "error": "Unable to edit point. Please refresh the page and try again."}
                )
            elif user.isLimited:
                resultJSON = json.dumps({"result": False, "error": "This account cannot edit points."})
            else:
                sources = Source.constructFromArrays(sourcesURLs, sourcesNames, oldPoint.key)
                newVersion = oldPoint.update(
                    newTitle=self.request.get("title"),
                    newContent=self.request.get("content"),
                    newSummaryText=self.request.get("plainText"),
                    user=self.current_user,
                    imageURL=self.request.get("imageURL"),
                    imageAuthor=self.request.get("imageAuthor"),
                    imageDescription=self.request.get("imageDescription"),
                    sourcesToAdd=sources,
                    sourceKeysToRemove=sourcesToRemove,
                )
                if newVersion:
                    sources = newVersion.getSources()
                    sourcesHTML = self.template_render("sources.html", {"sources": sources})

                    resultJSON = json.dumps(
                        {
                            "result": True,
                            "version": newVersion.version,
                            "author": newVersion.authorName,
                            "authorURL": self.current_user.url,
                            "dateEdited": newVersion.PSTdateEdited.strftime("%b. %d, %Y, %I:%M %p"),
                            "pointURL": newVersion.url,
                            "imageURL": newVersion.imageURL,
                            "imageAuthor": newVersion.imageAuthor,
                            "imageDescription": newVersion.imageDescription,
                            "sourcesHTML": sourcesHTML,
                        }
                    )
                    ReportEvent.queueEventRecord(user.key.urlsafe(), newVersion.key.urlsafe(), None, "Edit Point")
                else:
                    # This is the only way newVersion will fail
                    resultJSON = json.dumps({"result": False, "error": "You appear not to be logged in."})

        self.response.headers["Content-Type"] = "application/json; charset=utf-8"
        self.response.out.write(resultJSON)
Пример #23
0
 def post(self):
     resultJSON = json.dumps({'result': False})
     point, pointRoot = Point.getCurrentByUrl(self.request.get('pointURL'))
     parentPointURL = self.request.get('parentPointURL')
     parentPoint = None
     if parentPointURL:
         parentPoint, parentPointRoot = Point.getCurrentByUrl(parentPointURL)
     user = self.current_user
     if point and user:
         if user.addVote(point, int(self.request.get('vote'))):
             point.updateBacklinkedSorts(pointRoot)
             parentNewScore = None
             if parentPoint:
                 parentNewScore = parentPoint.pointValue()
             resultJSON = json.dumps({'result': True,
                                      'newVote': self.request.get('vote'),
                                      'newScore': point.pointValue(),
                                      'parentNewScore': parentNewScore})
     self.response.headers["Content-Type"] = 'application/json; charset=utf-8'
     self.response.out.write(resultJSON)
Пример #24
0
 def post(self):
     resultJSON = json.dumps({'result': False})
     point, pointRoot = Point.getCurrentByUrl(self.request.get('pointURL'))
     parentPointURL = self.request.get('parentPointURL')
     parentPoint = None
     if parentPointURL:
         parentPoint, parentPointRoot = Point.getCurrentByUrl(parentPointURL)
     user = self.current_user
     if point and user:
         if user.addVote(point, int(self.request.get('vote'))):
             point.updateBacklinkedSorts(pointRoot)
             parentNewScore = None
             if parentPoint:
                 parentNewScore = parentPoint.pointValue()
             resultJSON = json.dumps({'result': True,
                                      'newVote': self.request.get('vote'),
                                      'newScore': point.pointValue(),
                                      'parentNewScore': parentNewScore})
     self.response.headers["Content-Type"] = 'application/json; charset=utf-8'
     self.response.out.write(resultJSON)
Пример #25
0
    def post(self):
        user = self.current_user
        if user:      

            resultJSON = json.dumps({'result': False})
            oldPoint, oldPointRoot = Point.getCurrentByUrl(self.request.get('urlToEdit'))
            sourcesURLs=json.loads(self.request.get('sourcesURLs')) \
                if self.request.get('sourcesURLs') else None
            sourcesNames=json.loads(self.request.get('sourcesNames')) \
                if self.request.get('sourcesNames') else None
            sourcesToRemove=json.loads(self.request.get('sourcesToRemove')) \
                if self.request.get('sourcesToRemove') else None    
            if oldPoint == None:
                resultJSON = json.dumps({'result': False, 
                    'error': 'Unable to edit point. Please refresh the page and try again.'})
            elif user.isLimited:
                resultJSON = json.dumps({'result': False, 'error': 'This account cannot edit points.'})
            else:
                sources = Source.constructFromArrays(sourcesURLs, sourcesNames, oldPoint.key)
                newVersion = oldPoint.update(
                    newTitle=self.request.get('title'),
                    newContent=self.request.get('content'),
                    newSummaryText=self.request.get('plainText'),
                    user=self.current_user,
                    imageURL=self.request.get('imageURL'),
                    imageAuthor=self.request.get('imageAuthor'),
                    imageDescription=self.request.get('imageDescription'),
                    sourcesToAdd=sources,
                    sourceKeysToRemove= sourcesToRemove            
                )
                if newVersion:
                    sources = newVersion.getSources()   
                    sourcesHTML = self.template_render('sources.html', {'sources':sources})
            
                    resultJSON = json.dumps({
                        'result': True,
                        'version': newVersion.version,
                        'author': newVersion.authorName,
                        'authorURL': self.current_user.url,
                        'dateEdited': newVersion.PSTdateEdited.strftime('%b. %d, %Y, %I:%M %p'),
                        'pointURL':newVersion.url,
                        'imageURL': newVersion.imageURL,
                        'imageAuthor': newVersion.imageAuthor,
                        'imageDescription': newVersion.imageDescription,
                        'sourcesHTML': sourcesHTML
                    })
                    ReportEvent.queueEventRecord(user.key.urlsafe(), newVersion.key.urlsafe(), None, "Edit Point")
                else:
                    # This is the only way newVersion will fail
                    resultJSON = json.dumps({'result': False, 'error': 'You appear not to be logged in.'})
                
        self.response.headers["Content-Type"] = 'application/json; charset=utf-8'
        self.response.out.write(resultJSON)        
Пример #26
0
 def post(self):
     jsonOutput = {'result': False}
     user = self.current_user
     linkType = self.request.get('linkType')
     sourcesURLs=json.loads(self.request.get('sourcesURLs'))
     sourcesNames=json.loads(self.request.get('sourcesNames'))
     
     if user:   
         try:       
             parentPointURL = self.request.get('pointUrl')
             oldPoint, oldPointRoot = Point.getCurrentByUrl(parentPointURL)
             if oldPointRoot:
                 newPoint, newLinkPoint = Point.addSupportingPoint(
                     oldPointRoot=oldPointRoot,
                     title=self.request.get('title'),
                     content=self.request.get('content'),
                     summaryText=self.request.get('plainText'),
                     user=user,
                     # backlink=oldPoint.key.parent(),
                     linkType = linkType,
                     imageURL=self.request.get('imageURL'),
                     imageAuthor=self.request.get('imageAuthor'),
                     imageDescription=self.request.get('imageDescription'),
                     sourcesURLs=sourcesURLs,
                     sourcesNames=sourcesNames            
                 )
             else:
                 raise WhysaurusException('Point with URL %s not found' % parentPointURL)
         except WhysaurusException as e:
             jsonOutput = {
                 'result': False,
                 'errMessage': str(e)
             }
         else:
             ReportEvent.queueEventRecord(user.key.urlsafe(), newLinkPoint.key.urlsafe(), newPoint.key.urlsafe(), "Create Point")           
             newLinkPointHTML = self.template_render('linkPoint.html', {
                 'point': newLinkPoint,
                 'linkType': linkType
             })
             jsonOutput = {
                 'result': True,
                 'version': newPoint.version,
                 'author': newPoint.authorName,
                 'dateEdited': newPoint.PSTdateEdited.strftime('%b. %d, %Y, %I:%M %p'),
                 'numLinkPoints': newPoint.linkCount(linkType),
                 'newLinkPoint': newLinkPointHTML,
                 'authorURL': self.current_user.url
             }
         self.response.headers["Content-Type"] = 'application/json; charset=utf-8'      
         self.response.out.write(json.dumps(jsonOutput))
     else:
         self.response.out.write('Need to be logged in')
Пример #27
0
 def cleanDeadBacklinks(self, pointURL):        
     point, pointRoot = Point.getCurrentByUrl(pointURL)
     if pointRoot:
         rootsRemoved = pointRoot.removeDeadBacklinks()
         message = 'Removed %d dead roots from %s' % (rootsRemoved, point.title)
     else:
         message = 'Could not find point'
     template_values = {
         'message': message,            
         'user': self.current_user,
         'currentArea':self.session.get('currentArea')
     }
     self.response.out.write(self.template_render('message.html', template_values))        
Пример #28
0
    def getPointComments(self):
        resultJSON = json.dumps({'result': False})

        newURL = None
        url = self.request.get('url')
        point, pointRoot = Point.getCurrentByUrl(url)
        if point is None:
            # Try to find a redirector
            newURL = RedirectURL.getByFromURL(url)
            if newURL:
                point, pointRoot = Point.getCurrentByUrl(url)
        if pointRoot:
            template_values = {
                'user': self.current_user,
                'pointRoot': pointRoot,
                'comments': pointRoot.getComments()
            }
            html = self.template_render('pointComments.html', template_values)
            resultJSON = json.dumps({'result': True, 'html': html})
        self.response.headers[
            "Content-Type"] = 'application/json; charset=utf-8'
        self.response.out.write(resultJSON)
 def post(self):
     resultJSON = json.dumps({'result': False})
     if self.request.get('mainPointURL'):
         mainPoint, pointRoot = Point.getCurrentByUrl(self.request.get('mainPointURL'))
         if self.request.get('supportingPointURL'):
             supportingPointURL = self.request.get('supportingPointURL')
             newVersion = mainPoint.unlink(self.request.get('supportingPointURL'), 
                                           self.request.get('linkType'), 
                                           self.current_user)
             if newVersion:
                 resultJSON = json.dumps({'result': True, 'pointURL': supportingPointURL})
     self.response.headers.add_header('content-type', 'application/json', charset='utf-8')
     self.response.out.write(resultJSON)
Пример #30
0
 def addMissingBacklinks(self, pointURL):
     point, pointRoot = Point.getCurrentByUrl(pointURL)
     if point:
         rootsAdded = point.addMissingBacklinks()
         message = 'Added %d missing roots to links of %s' % (rootsAdded, point.title)
     else:
         message = 'Could not find point'
     template_values = {
         'message': message,            
         'user': self.current_user,
         'currentArea':self.session.get('currentArea')
     }
     self.response.out.write(self.template_render('message.html', template_values))                    
Пример #31
0
 def cleanDeadBacklinks(self, pointURL):        
     point, pointRoot = Point.getCurrentByUrl(pointURL)
     if pointRoot:
         rootsRemoved = pointRoot.removeDeadBacklinks()
         message = 'Removed %d dead roots from %s' % (rootsRemoved, point.title)
     else:
         message = 'Could not find point'
     template_values = {
         'message': message,            
         'user': self.current_user,
         'currentArea':self.session.get('currentArea')
     }
     self.response.out.write(self.template_render('message.html', template_values))        
Пример #32
0
 def addMissingBacklinks(self, pointURL):
     point, pointRoot = Point.getCurrentByUrl(pointURL)
     if point:
         rootsAdded = point.addMissingBacklinks()
         message = 'Added %d missing roots to links of %s' % (rootsAdded, point.title)
     else:
         message = 'Could not find point'
     template_values = {
         'message': message,            
         'user': self.current_user,
         'currentArea':self.session.get('currentArea')
     }
     self.response.out.write(self.template_render('message.html', template_values))                    
 def addMissingBacklinks(self, pointURL):
     point, pointRoot = Point.getCurrentByUrl(pointURL)
     if point:
         rootsAdded = point.addMissingBacklinks()
         message = 'Added %d missing roots to links of %s' % (rootsAdded, point.title)
     else:
         message = 'Could not find point'
     template_values = {
         'message': message,            
         'user': self.current_user,
         'currentArea':self.session.get('currentArea')
     }
     path = os.path.join(os.path.dirname(__file__), '../templates/message.html')
     self.response.out.write(template.render(path, template_values))      
Пример #34
0
 def cleanEmptyLinks(self, pointURL):
     point, pointRoot = Point.getCurrentByUrl(pointURL)
     if pointRoot:
         linksRemoved, versionCount = pointRoot.cleanEmptyLinks()
         message = 'Removed %d dead links from structured link arrays in %d versions of %s' % \
             (linksRemoved, versionCount, point.title)
     else:
         message = 'Could not find point'
     template_values = {
         'message': message,            
         'user': self.current_user,
         'currentArea':self.session.get('currentArea')
     }
     self.response.out.write(self.template_render('message.html', template_values))        
Пример #35
0
 def post(self):
     resultJSON = json.dumps({'result': False})
     point, pointRoot = Point.getCurrentByUrl(self.request.get('pointURL'))
     user = self.current_user
     newRibbonValue = self.request.get('ribbon') == 'true'
     if point and user:
         if user.setRibbon(point, newRibbonValue):
             resultJSON = json.dumps({
                 'result': True,
                 'ribbonTotal': point.ribbonTotal
             })
     self.response.headers[
         "Content-Type"] = 'application/json; charset=utf-8'
     self.response.out.write(resultJSON)
Пример #36
0
 def cleanEmptyLinks(self, pointURL):
     point, pointRoot = Point.getCurrentByUrl(pointURL)
     if pointRoot:
         linksRemoved, versionCount = pointRoot.cleanEmptyLinks()
         message = 'Removed %d dead links from structured link arrays in %d versions of %s' % \
             (linksRemoved, versionCount, point.title)
     else:
         message = 'Could not find point'
     template_values = {
         'message': message,            
         'user': self.current_user,
         'currentArea':self.session.get('currentArea')
     }
     self.response.out.write(self.template_render('message.html', template_values))        
 def reconcileVersionArrays(self, pointURL):
     point, pointRoot = Point.getCurrentByUrl(pointURL)
     if pointRoot:
         pointsRemoved = pointRoot.reconcileVersionArrays()
         message = 'Removed %d points from version root arrays in %s' % (pointsRemoved, point.title)
     else:
         message = 'Could not find point'
     template_values = {
         'message': message,            
         'user': self.current_user,
         'currentArea':self.session.get('currentArea')
     }
     path = os.path.join(os.path.dirname(__file__), '../templates/message.html')
     self.response.out.write(template.render(path, template_values)) 
 def cleanDeadBacklinks(self, pointURL):        
     point, pointRoot = Point.getCurrentByUrl(pointURL)
     if pointRoot:
         rootsRemoved = pointRoot.removeDeadBacklinks()
         message = 'Removed %d dead roots from %s' % (rootsRemoved, point.title)
     else:
         message = 'Could not find point'
     template_values = {
         'message': message,            
         'user': self.current_user,
         'currentArea':self.session.get('currentArea')
     }
     path = os.path.join(os.path.dirname(__file__), '../templates/message.html')
     self.response.out.write(template.render(path, template_values))                                                 
Пример #39
0
    def getPointComments(self):       
        resultJSON = json.dumps({'result': False})

        newURL = None
        url = self.request.get('url')
        point, pointRoot = Point.getCurrentByUrl(url)
        if point is None:
            # Try to find a redirector
            newURL = RedirectURL.getByFromURL(url)
            if newURL:
                point, pointRoot = Point.getCurrentByUrl(url)   
        if pointRoot:
            template_values = {
                'user': self.current_user,                
                'pointRoot': pointRoot,
                'comments':pointRoot.getComments()
            }        
            html = self.template_render('pointComments.html', template_values)
            resultJSON = json.dumps({
                'result': True,
                'html': html
            }) 
        self.response.headers["Content-Type"] = 'application/json; charset=utf-8'
        self.response.out.write(resultJSON) 
Пример #40
0
    def makeFeatured(self):
        result = {"result": False}
        try:
            if self.current_user and self.current_user.isAdmin:
                point, pointRoot = Point.getCurrentByUrl(self.request.get("urlToEdit"))
                if not pointRoot:
                    result["error"] = "Not able to find point by URL"
                if FeaturedPoint.setFeatured(pointRoot.key):
                    result = {"result": True}
            else:
                result = {"result": False, "error": "Permission denied!"}
        except Exception as e:
            result = {"result": False, "error": str(e)}

        resultJSON = json.dumps(result)
        self.response.headers["Content-Type"] = "application/json; charset=utf-8"
        self.response.out.write(resultJSON)
Пример #41
0
 def refreshTopStatus(self):
     result = {'result': False}
     try:
         if self.current_user and self.current_user.isAdmin:    
             point, pointRoot = Point.getCurrentByUrl(self.request.get('urlToEdit'))
             if not pointRoot:
                 result['error'] = 'Not able to find point by URL'
             pointRoot.setTop()
             result = {'result': True}
         else:
             result = {'result': False, 'error': 'Permission denied!'}
     except Exception as e:
         result = {'result': False, 'error': str(e)}  
          
     resultJSON = json.dumps(result)    
     self.response.headers["Content-Type"] = 'application/json; charset=utf-8'
     self.response.out.write(resultJSON)
Пример #42
0
 def updateCachedValues(self, pointURL):
     point, pointRoot = Point.getCurrentByUrl(pointURL)
     if pointRoot:
         eValue = point.cachedPointValue
         point.updateCachedValues(doPutOnUpdate=True, recurse=False)
         pValue = point.cachedPointValue
         if (eValue == pValue):
             message = 'Updated Cached Value - No Change (%d): %s' % (pValue, point.title)
         else:
             message = 'Updated Cached Values (%d -> %d): %s' % (eValue, pValue, point.title)
     else:
         message = 'Could not find point'
     template_values = {
         'message': message,
         'user': self.current_user,
         'currentArea': self.session.get('currentArea')
     }
     self.response.out.write(self.template_render('message.html', template_values))
Пример #43
0
    def changeLowQualityAdmin(self):
        result = {'result': False}
        try:
            if self.current_user and self.current_user.isAdmin:
                point, pointRoot = Point.getCurrentByUrl(self.request.get('urlToEdit'))
                if not point:
                    result['error'] = 'Not able to find point by URL'
                pick = True if self.request.get('lowQuality') == 'true' else False
                if point.updateLowQualityAdmin(pick):
                    result = {'result': True}
            else:
                result = {'result': False, 'error': 'Permission denied!'}
        except Exception as e:
            result = {'result': False, 'error': str(e)}

        resultJSON = json.dumps(result)
        self.response.headers["Content-Type"] = 'application/json; charset=utf-8'
        self.response.out.write(resultJSON)
Пример #44
0
    def changeEditorsPick(self):
        result = {"result": False}
        try:
            if self.current_user and self.current_user.isAdmin:
                point, pointRoot = Point.getCurrentByUrl(self.request.get("urlToEdit"))
                if not pointRoot:
                    result["error"] = "Not able to find point by URL"
                pick = True if self.request.get("editorsPick") == "true" else False
                if pointRoot.updateEditorsPick(pick, int(self.request.get("editorsPickSort"))):
                    result = {"result": True}
            else:
                result = {"result": False, "error": "Permission denied!"}
        except Exception as e:
            result = {"result": False, "error": str(e)}

        resultJSON = json.dumps(result)
        self.response.headers["Content-Type"] = "application/json; charset=utf-8"
        self.response.out.write(resultJSON)
Пример #45
0
    def refreshTopStatus(self):
        result = {'result': False}
        try:
            if self.current_user and self.current_user.isAdmin:
                point, pointRoot = Point.getCurrentByUrl(
                    self.request.get('urlToEdit'))
                if not pointRoot:
                    result['error'] = 'Not able to find point by URL'
                pointRoot.setTop()
                result = {'result': True}
            else:
                result = {'result': False, 'error': 'Permission denied!'}
        except Exception as e:
            result = {'result': False, 'error': str(e)}

        resultJSON = json.dumps(result)
        self.response.headers[
            "Content-Type"] = 'application/json; charset=utf-8'
        self.response.out.write(resultJSON)
Пример #46
0
    def post(self):
        resultJSON = json.dumps({'result': False, 'error': 'Point Not Found'})
        user = self.current_user
        if not user:
            resultJSON = json.dumps({'result': False, 'error': 'Need to be logged in'})
        elif not user.isAdmin:
            resultJSON = json.dumps({'result': False, 'error': 'Must be admin'})
        else:
            urlToDelete = self.request.get('urlToDelete')
            point, pointRoot = Point.getCurrentByUrl(urlToDelete)

            if pointRoot:
                result, error = pointRoot.delete(user)
                if result:
                    resultJSON = json.dumps({'result': True, 'deletedURL': urlToDelete})
                else:
                    resultJSON = json.dumps({'result': False, 'error': error})
        self.response.headers["Content-Type"] = 'application/json; charset=utf-8'
        self.response.out.write(resultJSON)
    def post(self):
        user = self.current_user
        # GET RECENTLY VIEWED
        if user:
            oldPoint, oldPointRoot = Point.getCurrentByUrl(self.request.get('parentPointURL'))
            recentlyViewedPoints = user.getRecentlyViewed(
                excludeList=[oldPoint.key.parent()] + oldPoint.supportingPointsRoots
            )
        else:
            recentlyViewedPoints = []

        templateValues = {
            'points': recentlyViewedPoints,
            'parentPoint': oldPoint,
            'user': user,
            'thresholds': constants.SCORETHRESHOLDS
        }
        path = os.path.join(constants.ROOT, 'templates/selectSupportingPoint.html')
        self.response.out.write(template.render(path, templateValues))
Пример #48
0
 def changeEditorsPick(self):
     result = {'result': False}
     try:
         if self.current_user and self.current_user.admin:
             point, pointRoot = Point.getCurrentByUrl(self.request.get('urlToEdit'))
             if pointRoot is None:
                 result['error'] = 'Not able to find point by URL'
             else:
                 pick = True if self.request.get('editorsPick') == 'true' else False
                 if pointRoot.updateEditorsPick(pick, 
                                                int(self.request.get('editorsPickSort'))):
                     result = {'result': True}
         else:
             result = {'result': False, 'error': 'Permission denied!'}
     except Exception as e:
         result = {'result': False, 'error': str(e)}
 
     resultJSON = json.dumps(result)    
     self.response.headers.add_header('content-type', 'application/json', charset='utf-8')
     self.response.out.write(resultJSON)
Пример #49
0
 def updateCachedValues(self, pointURL):
     point, pointRoot = Point.getCurrentByUrl(pointURL)
     if pointRoot:
         eValue = point.cachedPointValue
         point.updateCachedValues(doPutOnUpdate=True, recurse=False)
         pValue = point.cachedPointValue
         if (eValue == pValue):
             message = 'Updated Cached Value - No Change (%d): %s' % (
                 pValue, point.title)
         else:
             message = 'Updated Cached Values (%d -> %d): %s' % (
                 eValue, pValue, point.title)
     else:
         message = 'Could not find point'
     template_values = {
         'message': message,
         'user': self.current_user,
         'currentArea': self.session.get('currentArea')
     }
     self.response.out.write(
         self.template_render('message.html', template_values))
Пример #50
0
    def changeLowQualityAdmin(self):
        result = {'result': False}
        try:
            if self.current_user and self.current_user.isAdmin:
                point, pointRoot = Point.getCurrentByUrl(
                    self.request.get('urlToEdit'))
                if not point:
                    result['error'] = 'Not able to find point by URL'
                pick = True if self.request.get(
                    'lowQuality') == 'true' else False
                if point.updateLowQualityAdmin(pick):
                    result = {'result': True}
            else:
                result = {'result': False, 'error': 'Permission denied!'}
        except Exception as e:
            result = {'result': False, 'error': str(e)}

        resultJSON = json.dumps(result)
        self.response.headers[
            "Content-Type"] = 'application/json; charset=utf-8'
        self.response.out.write(resultJSON)
Пример #51
0
    def mutate(self, info, point_data):
        oldPoint, oldPointRoot = PointModel.getCurrentByUrl(
            point_data.parentURL)
        newPoint, newLinkPoint = PointModel.addSupportingPoint(
            oldPointRoot=oldPointRoot,
            title=point_data.title,
            content=point_data.content,
            summaryText=point_data.summaryText,
            user=info.context.current_user,
            linkType=point_data.linkType,
            imageURL=point_data.imageURL,
            imageAuthor=point_data.imageAuthor,
            imageDescription=point_data.imageDescription,
            sourcesURLs=point_data.sourceURLs,
            sourcesNames=point_data.sourceNames)

        # these two are in service of the SubPointConnection logic - we should find a way to DRY this up
        newLinkPoint.parent = newPoint
        newLinkPoint.link_type = point_data.linkType

        return AddEvidence(point=newLinkPoint, parent=newPoint)
Пример #52
0
 def mutate(self, info, url):
     point, pointRoot = PointModel.getCurrentByUrl(url)
     return ExpandPoint(point=point)
Пример #53
0
    def post(self):
        user = self.current_user
        if user:

            resultJSON = json.dumps({'result': False})
            oldPoint, oldPointRoot = Point.getCurrentByUrl(
                self.request.get('urlToEdit'))
            sourcesURLs=json.loads(self.request.get('sourcesURLs')) \
                if self.request.get('sourcesURLs') else None
            sourcesNames=json.loads(self.request.get('sourcesNames')) \
                if self.request.get('sourcesNames') else None
            sourcesToRemove=json.loads(self.request.get('sourcesToRemove')) \
                if self.request.get('sourcesToRemove') else None
            if oldPoint == None:
                resultJSON = json.dumps({
                    'result':
                    False,
                    'error':
                    'Unable to edit point. Please refresh the page and try again.'
                })
            elif user.isLimited:
                resultJSON = json.dumps({
                    'result':
                    False,
                    'error':
                    'This account cannot edit points.'
                })
            else:
                sources = Source.constructFromArrays(sourcesURLs, sourcesNames,
                                                     oldPoint.key)
                newVersion = oldPoint.update(
                    newTitle=self.request.get('title'),
                    newContent=self.request.get('content'),
                    newSummaryText=self.request.get('plainText'),
                    user=self.current_user,
                    imageURL=self.request.get('imageURL'),
                    imageAuthor=self.request.get('imageAuthor'),
                    imageDescription=self.request.get('imageDescription'),
                    sourcesToAdd=sources,
                    sourceKeysToRemove=sourcesToRemove)
                if newVersion:
                    sources = newVersion.getSources()
                    sourcesHTML = self.template_render('sources.html',
                                                       {'sources': sources})

                    resultJSON = json.dumps({
                        'result':
                        True,
                        'version':
                        newVersion.version,
                        'author':
                        newVersion.authorName,
                        'authorURL':
                        self.current_user.url,
                        'dateEdited':
                        newVersion.PSTdateEdited.strftime(
                            '%b. %d, %Y, %I:%M %p'),
                        'pointURL':
                        newVersion.url,
                        'imageURL':
                        newVersion.imageURL,
                        'imageAuthor':
                        newVersion.imageAuthor,
                        'imageDescription':
                        newVersion.imageDescription,
                        'sourcesHTML':
                        sourcesHTML
                    })
                    ReportEvent.queueEventRecord(user.key.urlsafe(),
                                                 newVersion.key.urlsafe(),
                                                 None, "Edit Point")
                else:
                    # This is the only way newVersion will fail
                    resultJSON = json.dumps({
                        'result':
                        False,
                        'error':
                        'You appear not to be logged in.'
                    })

        self.response.headers[
            "Content-Type"] = 'application/json; charset=utf-8'
        self.response.out.write(resultJSON)
Пример #54
0
 def resolve_point(self, info, **args):
     point, pointRoot = PointModel.getCurrentByUrl(args['url'])
     return point