def post(self): if self.logged_in: user = self.current_user id = int(self.request.POST['id']) found_attack = Attack.get_by_id(id, parent=user.key) if found_attack: found_attack.key.delete() self.response.out.write({'message': "Attack deleted."}) self.response.status = 200 else: self.response.out.write({'message': "Attack not found."}) self.response.status = 404 else: template_values = { 'status': '401 - Unauthenticated', 'title': 'What a headache!', 'message': "You need to be logged in to delete attacks." } self.response.status = 404 path = os.path.join( os.path.join(os.path.dirname(__file__), 'html'), '../templates/error.html') self.response.out.write(template.render(path, template_values))
def post(self): if self.logged_in: user = self.current_user id = int(self.request.POST['id']) started = datetime.datetime.strptime(self.request.POST['started'], "%Y-%m-%d %H:%M") if 'duration' in self.request.POST: duration = int(self.request.POST['duration']) else: ended = datetime.datetime.strptime(self.request.POST['ended'], "%Y-%m-%d %H:%M") duration_delta = ended - started duration = int(duration_delta.total_seconds()) found_attack = Attack.get_by_id(id, parent=user.key) if found_attack: found_attack.start_time = started found_attack.duration = duration found_attack.comment = self.request.POST['comment'] found_attack.start_text = create_start_text(started) found_attack.duration_text = create_duration_text(duration) found_attack.put() self.response.out.write({'message': "Attack updated."}) self.response.status = 200 else: self.response.out.write({'message': "Attack not found."}) self.response.status = 404 else: template_values = { 'status': '401 - Unauthenticated', 'title': 'What a headache!', 'message': "You need to be logged in to update attacks." } self.response.status = 404 path = os.path.join( os.path.join(os.path.dirname(__file__), 'html'), '../templates/error.html') self.response.out.write(template.render(path, template_values))