def get_ajax(self, request, *args, **kwargs): session = self.request.user.current_session.uuid try: docs_ids_to_judge = CALFunctions.get_documents(str(session), 5) return self.render_json_response(docs_ids_to_judge) except TimeoutError: error_dict = { u"message": u"Timeout error. Please check status of servers." } return self.render_timeout_request_response(error_dict) except CALError as e: # TODO: add proper http response for CAL errors return JsonResponse({"message": "Ops! CALError."}, status=404)
def get_ajax(self, request, *args, **kwargs): session = self.request.user.current_session seed_query = self.request.user.current_session.topic.seed_query try: docids_to_judge, top_terms = CALFunctions.get_documents( str(session.uuid), 10) if not docids_to_judge: return self.render_json_response([]) ret = {} next_patch_ids = [] for docid_score_pair in docids_to_judge: doc_id, doc_score = docid_score_pair.rsplit(':', 1) ret[doc_id] = doc_score next_patch_ids.append(doc_id) doc_ids_hack = [] for doc_id in next_patch_ids: doc = {'doc_id': doc_id} if '.' in doc_id: doc['doc_id'], doc['para_id'] = doc_id.split('.') doc_ids_hack.append(doc) if 'doc' in self.request.user.current_session.strategy: documents = DocEngine.get_documents(next_patch_ids, seed_query, top_terms) else: documents = DocEngine.get_documents_with_snippet( doc_ids_hack, seed_query, top_terms) return self.render_json_response(documents) except TimeoutError: error_dict = { u"message": u"Timeout error. Please check status of servers." } return self.render_timeout_request_response(error_dict) except CALServerSessionNotFoundError: message = "Ops! Session is not found in CAL. " if "scal" not in self.request.user.current_session.strategy: seed_judgments = Judgment.objects.filter( user=self.request.user, session=session).filter(relevance__isnull=False) strategy = self.request.user.current_session.strategy CALFunctions.restore_session(session.uuid, seed_query, seed_judgments, strategy) message += "Restoring.. Please try in few minutes." return JsonResponse({"message": message}, status=404) except CALError as e: return JsonResponse({"message": "Ops! CALError."}, status=404)
def get_ajax(self, request, *args, **kwargs): session = self.request.user.current_session.uuid seed_query = self.request.user.current_session.topic.seed_query try: docids_to_judge, top_terms = CALFunctions.get_documents( str(session), 10) if not docids_to_judge: return self.render_json_response([]) ret = {} next_patch_ids = [] for docid_score_pair in docids_to_judge: doc_id, doc_score = docid_score_pair.split(':') ret[doc_id] = doc_score next_patch_ids.append(doc_id) doc_ids_hack = [] for doc_id in next_patch_ids: doc = {'doc_id': doc_id} if '.' in doc_id: doc['doc_id'], doc['para_id'] = doc_id.split('.') doc_ids_hack.append(doc) if 'doc' in self.request.user.current_session.strategy: documents = DocEngine.get_documents(next_patch_ids, seed_query, top_terms) else: documents = DocEngine.get_documents_with_snippet( doc_ids_hack, seed_query, top_terms) return self.render_json_response(documents) except TimeoutError: error_dict = { u"message": u"Timeout error. Please check status of servers." } return self.render_timeout_request_response(error_dict) except CALError as e: return JsonResponse({"message": "Ops! CALError."}, status=404)