Exemple #1
0
	def post(self):
		# check whether the data is valid
		args = self.reqparse.parse_args() # exclude args not in the parser
		#args = request.get_json(force=True) # allow all args
		mongo.db.posts.insert(args)
		# if inserted successfully, return last inserted document
		cursor = mongo.db.posts.find().sort([('_id', -1)]).limit(1)
		socketio.emit('new post', json_util.dumps(cursor[0]), room=cursor[0]['roomName'])
		return cursor[0]
Exemple #2
0
def output_json(obj, code, headers=None):
	"""
	This is needed because we need to use a custom JSON converter
	that knows how to translate MongoDB types to JSON.
	"""
	resp = make_response(json_util.dumps(obj), code)
	# not needed any more. CORS will take care of these headers
	# resp.headers['Access-Control-Allow-Headers'] = 'Content-Type'
	# resp.headers['Access-Control-Allow-Methods'] = 'GET, POST, OPTIONS'
	# resp.headers['Access-Control-Allow-Origin'] = '*'
	resp.headers.extend(headers or {})
	return resp