示例#1
0
  def get(self, pointURL):
    # check if dev environment for Disqus
    devInt = 1 if constants.DEV else 0

    point, pointRoot = Point.getCurrentByUrl(pointURL)
    if point:
      supportingPoints = point.getSupportingPoints()
      user = self.current_user
      if not user or not user.userVotes or not point.key.parent() in user.userVotes: 
        voteValue = 0
      else:
        voteValue = user.userVotes[point.key.parent()].value

      addedToRecentlyViewed = False      
      if user:
        addedToRecentlyViewed = user.updateRecentlyViewed(point.key.parent())

      # 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:
        pointRoot.addViewCount()
      logging.info('Getting point for user %s', str(user))
      template_values = {
      	'point': point,
      	'pointRoot': pointRoot,
      	'numPoints': len(point.supportingPoints),
      	'supportingPoints': supportingPoints,
      	'user': user,
      	'devInt': devInt, # For Disqus
      	'voteValue': voteValue,
        'thresholds' : constants.SCORETHRESHOLDS
      }
      path = os.path.join(os.path.dirname(__file__), 'templates/point.html')
      self.response.out.write(template.render(path, template_values))
    else:
      self.response.out.write('Could not find point: ' + pointURL)
示例#2
0
 def get(self):
   searchResults = Point.search(self.request.get('searchTerms'))
   template_values = {
     'user': self.current_user,
     'searchResults' : searchResults,
     'searchString': self.request.get('searchTerms'),
     'thresholds' : constants.SCORETHRESHOLDS
   }
   path = os.path.join(os.path.dirname(__file__), 'templates/searchResults.html')
   self.response.out.write(template.render(path, template_values))
示例#3
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:
     logging.info('ADDING VOTE')
     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)
示例#4
0
 def post(self):
   resultJSON = json.dumps({'result':False})
   searchResults = Point.search(self.request.get('searchTerms'), self.request.get('exclude'))
   if searchResults:
     resultJSON = json.dumps( {
       'result': True,
       'searchResults' : searchResults,
       'searchString': self.request.get('searchTerms')
     })
   self.response.headers.add_header('content-type', 'application/json', charset='utf-8')
   self.response.out.write(resultJSON)   
示例#5
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
   
   if user:      
     try:
       newPoint = oldPoint.update(
         newSupportingPoint=supportingPointRoot,
         user=user
         )
     except WhysaurusException as e:
       resultJSON = json.dumps({'result':False, 'error': str(e)})
     else:   
       resultJSON = json.dumps({'result':True})
   else:
     resultJSON = json.dumps({'result':'ACCESS DENIED!'})
   self.response.headers.add_header('content-type', 'application/json', charset='utf-8')
   self.response.out.write(resultJSON)   
示例#6
0
 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.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)
示例#7
0
  def get(self):
    pointData = Point.getFullHistory(self.request.get('pointUrl'))
    
    template_values = {
      'latestPoint' : pointData[0]["point"] if pointData else None,
      'numPoints': len(pointData) if pointData else 0,
      'pointData': pointData,
      'user' : self.current_user
    }

    path = os.path.join(os.path.dirname(__file__), 'templates/pointHistory.html')
    self.response.out.write(template.render(path, template_values ))
示例#8
0
 def post(self):
   jsonOutput = {'result':False}
   oldPoint, oldPointRoot = Point.getCurrentByUrl(self.request.get('pointUrl'))
   user = self.current_user
   
   if user:
     supportingPoint, supportingPointRoot = Point.create(
       title=self.request.get('title'), 
       content=self.request.get('content'),
       summaryText=self.request.get('plainText'),
       user=user,        
       pointSupported=oldPoint.key.parent(),
       imageURL=self.request.get('imageURL'),
       imageAuthor=self.request.get('imageAuthor'),
       imageDescription=self.request.get('imageDescription'))     
     try: 
       newPoint = oldPoint.update(
         newSupportingPoint=supportingPointRoot,
         user=user
         )
     except WhysaurusException as e:
       jsonOutput = {
         'result':False,
         'err':str(e)
       }
     else: 
       jsonOutput = {
         'result':True,
         'version':newPoint.version,
         'author':newPoint.authorName,
         'dateEdited':newPoint.dateEdited.strftime("%Y-%m-%d %H:%M:%S %p"),
       }
     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')
示例#9
0
 def post(self):
   user = self.current_user
   resultJSON = json.dumps({'result':False, 'error':'Not authorized'})
   if user:
     newPoint, newPointRoot = Point.create(
       title=self.request.get('title'),
       content=self.request.get('content'), 
       summaryText=self.request.get('plainText'),
       user=user,
       imageURL=self.request.get('imageURL'),
       imageAuthor=self.request.get('imageAuthor'),
       imageDescription=self.request.get('imageDescription'))
     if newPoint:
       resultJSON = json.dumps({'result':True, 'pointURL':newPoint.url })
     else:
       resultJSON = json.dumps({'result':False, 'error':'Failed to create point.' })
   self.response.headers.add_header('content-type', 'application/json', charset='utf-8')
   self.response.out.write(resultJSON)
示例#10
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.admin:
      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.add_header('content-type', 'application/json', charset='utf-8')
    self.response.out.write(resultJSON)
示例#11
0
  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.supportingPoints 
                                                     )
    else:
      recentlyViewedPoints = []

    templateValues = {
      'points': recentlyViewedPoints,
      'parentPoint': oldPoint,
			'user' : user,
      'thresholds' : constants.SCORETHRESHOLDS
    }
    path = os.path.join(os.path.dirname(__file__), 'templates/selectSupportingPoint.html')
    self.response.out.write(template.render(path, templateValues ))
示例#12
0
 def post(self): 
   resultJSON = json.dumps({'result':False})
   oldPoint, oldPointRoot = Point.getCurrentByUrl(self.request.get('urlToEdit'))
   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') 
     )
   if newVersion:
     resultJSON = json.dumps({'result':True, 
       'version':newVersion.version,
       'author':newVersion.authorName,
       'dateEdited': str(newVersion.dateEdited),
       'imageURL': newVersion.imageURL,
       'imageAuthor': newVersion.imageAuthor,
       'imageDescription': newVersion.imageDescription 
       })
   self.response.headers.add_header('content-type', 'application/json', charset='utf-8')
   self.response.out.write(resultJSON)