def deleteMilestone(milestone):
    
    if milestone.image != None:
        image = Image.get(milestone.image)
        if image != None:
            Image.delete(image)
            
    query = db.Query(MilestoneAttachment)
    query.filter('milestone_id = ',str(milestone.key()))
    for attachment in query.run():
        deleteAttachment(attachment)
    
    if milestone != None:
        Milestone.delete(milestone)
 def get(self,milestone_id):
     self.response.headers['Content-Type'] = 'application/json'
     
     milestone = Milestone.get(milestone_id)
     
     if milestone == None:
         self.response.write({'milestone' : None})
         return
     
     milestoneInfo = dict(milestone.__dict__['_entity'])
     milestoneInfo['milestone_id'] = milestone_id
     
     query = db.Query(MilestoneAttachment)
     query.filter('milestone_id = ',milestone_id)
     query.order('time')
     
     attachments = []
     for attachment in query.run():
         attachmentInfo = dict(attachment.__dict__['_entity'])
         attachmentInfo['attachment_id'] = str(attachment.key())
         attachments.append(attachmentInfo)
         
     milestoneInfo['attachments'] = attachments
     
     self.response.write(json.dumps({'milestone' : milestoneInfo}))
 def get(self,milestone_id):
     self.response.headers['Content-Type'] = 'application/json'
     
     milestone = Milestone.get(milestone_id)
     if milestone == None:
         self.response.write({'status' : 0})
         return
     
     deleteMilestone(milestone)
     
     self.response.write(json.dumps({'status' : 1}))
 def post(self):
     self.response.headers['Content-Type'] = 'application/json'
     
     newMilestone = Milestone(journey_id = self.request.get('journey_id'))
     
     newMilestone.latitude = float(self.request.get('latitude'))
     newMilestone.longitude = float(self.request.get('longitude'))
     newMilestone.location = self.request.get('location')
     newMilestone.time = getTimeEpoch()
     
     newMilestone.put()
     
     self.response.write(json.dumps({'milestone_id' : str(newMilestone.key())}))