Пример #1
0
 def post(self, trailId = None):
     
     if(trailId is None):
         try:
             uploadedFiles = self.get_uploads('file')  # 'file' is file upload field in the form
             blobInfo = uploadedFiles[0]
             blobReader = blobInfo.open()
             
             parser = KmlParser()
             trailInfo = parser.parseKml(blobReader)
             logging.debug(trailInfo)
             blobInfo.delete()
             
             #parse tags, if any. It is assumed that they are separated by commas.
             tags = self.request.get('tags').split(',')
                 
             #store entry
             entry = Trail(title = self.request.get('title'),
                             militaryMap = self.request.get('militaryMap'),
                             nearestCity = self.request.get('nearestCity'),
                             timeDurationHours = self.request.get('timeDurationHours'),
                             extension = trailInfo['extension'],
                             slope = trailInfo['slope'],
                             startPoint = trailInfo['startPoint'],
                             points = simplejson.dumps(trailInfo['points']))
             entry.put()
             self.redirect('/trails')
         except:
             logging.exception("Unexpected creating trail: %s", sys.exc_info()[0])
             self.error(500)
     
     else:
         self._updateTrail(trailId)
Пример #2
0
 def _updateTrail(self, trailId):
     try:
         trail = Key("Trail", long(trailId)).get()
         
         if(trail is not None):
             '''
                 Try to update the trail. Returns the updated trail as a JSON object.
                 First the properties that are not related to the file upload are updated.
             '''
             trail.title = self.request.get('title')
             trail.militaryMap= self.request.get('militaryMap')
             trail.timeDurationHours= self.request.get('timeDurationHours')
             trail.nearestCity= self.request.get('nearestCity')
             trail.tags= self.request.get('tags').split(',')
             
             '''
                 Check if there is a newly uploaded file that superseeds the old data.
             '''
             uploadedFiles = self.get_uploads('file')  # 'file' is file upload field in the form
             if(len(uploadedFiles) > 0):
                 blobInfo = uploadedFiles[0]
                 blobReader = blobInfo.open()
             
                 parser = KmlParser()
                 trailInfo = parser.parseKml(blobReader)
                 
                 trail.extension = trailInfo['extension'] 
                 trail.slope = trailInfo['slope']
                 trail.points = simplejson.dumps(trailInfo['points'])
                 trail.startPoint = trailInfo['startPoint']
                 
                 blobInfo.delete()
             
             #Save the updated trail.
             trail.save()
             
             #log action
             usr = users.get_current_user()
             if(usr is not None):
                 logEntry = ActivityLog(user=usr, action="Update - Trail")
                 logEntry.put()
                        
             self.response.clear()
             self.response.set_status(200)
         else:
             self.error(404)
     
     except:
         logging.exception("An exception occurred when updating the trail")
         self.error(500)