# print form_data["question_set"][0] form_id = mongo.db.forms.insert(form_data) return mongo.db.forms.find_one({"_id": form_id}) # the method could be used to modify get new and delete item form the list class Form(restful.Resource): def get(self, form_id): # return mongo.db.forms.find_one_or_404({"": }) return mongo.db.forms.find_one_or_404({"_id": form_id}) def delete(self, form_id): mongo.db.forms.find_one_or_404({"_id": form_id}) mongo.db.forms.remove({"_id": form_id}) return '', 204 def put(self, form_id): target_id = {'_id': form_id} update_content = {'$set': request.get_json()} mongo.db.forms.update_one(target_id, update_content, upsert=False) return mongo.db.forms.find_one_or_404({"_id": form_id}) class Root(restful.Resource): def get(self): return { 'status': 'OK' } api.add_resource(Root, '/') api.add_resource(FormList, '/forms/') api.add_resource(Form, '/forms/<ObjectId:form_id>')
result_data = request.get_json() result_user = result_data['user'] result_time = result_data['time'] result_title = result_data['title'] result_content = result_data['content'] data = json.dumps(result_data) result_id = mongo.db.results.insert(result_data) return mongo.db.results.find_one({"_id": result_id}) # the method could be used to modify get new and delete item result the list class Result(restful.Resource): def get(self, result_id): # return mongo.db.users.find_one_or_404({"": }) return mongo.db.results.find_one_or_404({"_id": result_id}) def delete(self, result_id): mongo.db.results.find_one_or_404({"_id": result_id}) mongo.db.results.remove({"_id": result_id}) return '', 204 def put(self, result_id): target_id = {'_id': result_id} update_content = {'$set': request.get_json()} mongo.db.results.update_one(target_id, update_content, upsert=False) return mongo.db.results.find_one_or_404({"_id": result_id}) api.add_resource(ResultList, '/results/') api.add_resource(Result, '/results/<ObjectId:result_id>')
email = user_data['email'] gender = user_data['gender'] job = user_data['job'] mobile_os = user_data['mobile_os'] mobile_name = user_data['mobile_name'] pc_os = user_data['pc_os'] data = json.dumps(user_data) user_id = mongo.db.users.insert(user_data) return mongo.db.users.find_one({"_id": user_id}) # the method could be used to modify get new and delete item user the list class User(restful.Resource): def get(self, user_id): # return mongo.db.users.find_one_or_404({"": }) return mongo.db.users.find_one_or_404({"_id": user_id}) def delete(self, user_id): mongo.db.users.find_one_or_404({"_id": user_id}) mongo.db.users.remove({"_id": user_id}) return '', 204 def put(self, user_id): target_id = {'_id': user_id} update_content = {'$set': request.get_json()} mongo.db.users.update_one(target_id, update_content, upsert=False) return mongo.db.users.find_one_or_404({"_id": user_id}) api.add_resource(UserList, '/users/') api.add_resource(User, '/users/<ObjectId:user_id>')
# post a experiment to the web def post(self): experiment_data = request.get_json() experiment_form = experiment_data['form'] experiment_users = experiment_data['users'] data = json.dumps(experiment_data) experiment_id = mongo.db.experiments.insert(experiment_data) return mongo.db.experiments.find_one({"_id": experiment_id}) # the method could be used to modify get new and delete item experiment the list class Experiment(restful.Resource): def get(self, experiment_id): # return mongo.db.users.find_one_or_404({"": }) return mongo.db.experiments.find_one_or_404({"_id": experiment_id}) def delete(self, experiment_id): mongo.db.experiments.find_one_or_404({"_id": experiment_id}) mongo.db.experiments.remove({"_id": experiment_id}) return '', 204 def put(self, experiment_id): target_id = {'_id': experiment_id} update_content = {'$set': request.get_json()} mongo.db.experiments.update_one(target_id, update_content, upsert=False) return mongo.db.experiments.find_one_or_404({"_id": experiment_id}) api.add_resource(ExperimentList, '/experiments/') api.add_resource(Experiment, '/experiments/<ObjectId:experiment_id>')
def post(self): result_data = request.get_json() result_user = result_data['user'] result_time = result_data['time'] result_title = result_data['title'] result_content = result_data['content'] data = json.dumps(result_data) result_id = mongo.db.results.insert(result_data) return mongo.db.results.find_one({"_id": result_id}) # the method could be used to modify get new and delete item result the list class Result(restful.Resource): def get(self, result_id): # return mongo.db.users.find_one_or_404({"": }) return mongo.db.results.find_one_or_404({"_id": result_id}) def delete(self, result_id): mongo.db.results.find_one_or_404({"_id": result_id}) mongo.db.results.remove({"_id": result_id}) return '', 204 def put(self, result_id): target_id = {'_id': result_id} update_content = {'$set': request.get_json()} mongo.db.results.update_one(target_id, update_content, upsert=False) return mongo.db.results.find_one_or_404({"_id": result_id}) api.add_resource(ResultList, '/results/') api.add_resource(Result, '/results/<ObjectId:result_id>')