コード例 #1
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)