def process_request(self, request): r = Req(request=repr(request)) r.save() request._debug_req = r return None
def request_post(): """ Content-Type: application/json """ data = request.form print data if 'case_id' not in data: # A new case try: device_id = data['device_id'] longitude = data['longitude'] latitude = data['latitude'] except KeyError as e: # TODO: Handle missing param print sys.exc_info() return jsonify({"status": 400}) # Create a new case case = Case(resolved=0) case_id = None try: db.session.add(case) db.session.commit() # Save the case id case_id = case.case_id except: print sys.exc_info() else: # Add a new request to an existing case try: case_id = data['case_id'] device_id = data['device_id'] longitude = data['longitude'] latitude = data['latitude'] except KeyError as e: # TODO: Handle missing param print sys.exc_info() return jsonify({"status": 400}) # Add request into db req = Req(case_id=case_id, device_id=device_id, longitude=longitude, latitude=latitude) db.session.add(req) db.session.commit() # Send useful information to the front end map_msg = { "case_id": r['case_id'], "latitude": r['latitude'], "longitude": r['longitude'] } # Send message to client socketio.emit('map message', map_msg) return jsonify({'status': 'success'})