Пример #1
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)
Пример #2
0
	def post(self, request, *args, **kwargs):
		if request.method == 'POST':
			try:
				question_id = kwargs.get("question_id")
			except Exception, e:
				logging.error(str(e))
				return HttpResponse(status=500)

			question = str(request.POST["question"])
			answers = filter(None, request.POST.getlist('answer'))
			category = str(request.POST["categories"])
			type_answers = str(request.POST["type-answers"])

			_doc_question = {
				"content": question,
				"type": type_answers,
				"category": category,
			}

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

			if doc_question["type"] != "03" and answers:
				for answer in answers:
					_doc_answer = {
						"content": str(answer),
						"table": "answer",
						"question_id": doc_question["_id"]
					}
					doc_answer = couch_server.save_doc(_doc_answer)
					doc_question["answer_id"].append(doc_answer["_id"])
			elif doc_question["type"] == "03":
				del (doc_question["answer_id"])[:]

			couch_server.save_doc(doc_question)

			messages.add_message(
				request,
				messages.SUCCESS,
				"SUCCESS: Question and answers have been edited successfully!"
			)
Пример #3
0
	def post(self, request, *args, **kwargs):
		if request.method == 'POST':

			couch_server = ConnectCouchdb()
			question = str(request.POST["question"])
			answers = filter(None, request.POST.getlist('answer'))
			category = str(request.POST["categories"])
			type_answers = str(request.POST["type-answers"])

			_doc_question = {
				"table": "question",
				"content": question,
				"type": type_answers,
				"category": category,
				"answer_id": []
			}
			doc_question = couch_server.save_doc(_doc_question)

			if answers:
				for answer in answers:
					_doc_answer = {
						"content": str(answer),
						"table": "answer",
						"question_id": doc_question["_id"]
					}
					doc_answer = couch_server.save_doc(_doc_answer)
					doc_question["answer_id"].append(doc_answer["_id"])

			couch_server.save_doc(doc_question)

			messages.add_message(
				request,
				messages.SUCCESS,
				"SUCCESS: Question and answers have been created successfully!"
			)
		return HttpResponseRedirect('/edit_answer_question/%s' % doc_question["_id"])