예제 #1
0
def remove_answer_question(request):
	if request.method == 'POST':
		try:
			question_id = request.POST["questionId"]
		except Exception, e:
			logging.error(str(e))
			return HttpResponse(status=500)

		couch_server = ConnectCouchdb()
		doc_question = couch_server.get_doc(question_id)

		if doc_question:
			doc_answers = doc_question["answer_id"]
			couch_server.delete_doc(question_id)

			if doc_answers:
				for answer in doc_answers:
					couch_server.delete_doc(answer)

		messages.add_message(
			request,
			messages.SUCCESS,
			"SUCCESS: Question and answers have been deleted successfully!"
		)
		return HttpResponse(status=200)
예제 #2
0
def remove_answer(request):
	if request.method == 'POST':
		try:
			answer_id = request.POST["answerId"]
			question_id = request.POST["questionId"]
		except Exception, e:
			logging.error(str(e))
			return HttpResponse(status=500)

		couch_server = ConnectCouchdb()
		doc_answer = couch_server.get_doc(answer_id)
		doc_question = couch_server.get_doc(question_id)

		couch_server.delete_doc(answer_id)
		doc_question["answer_id"].remove(answer_id)
		couch_server.save_doc(doc_question)

		return HttpResponse(status=200)