def post(self): if self.logged_in: user = self.current_user 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()) new_attack = attack.Attack(parent=user.key) new_attack.start_time = started new_attack.duration = duration new_attack.comment = self.request.POST['comment'] new_attack.start_text = create_start_text(started) new_attack.duration_text = create_duration_text(duration) new_attack.put() self.response.out.write({'message': "One attack created"}) self.response.status = 200 else: self.redirect('/')
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))
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))