def all_search(request): try: keyword = request.GET.get('keyword') search_flag = request.GET.get('search_flag') max_count = int(request.GET.get('max_count')) page = int(request.GET.get('page')) myuser = request.myuser if not keyword: return JsonResponse(code[40013]) if search_flag == 'note': my_filter = Q() my_filter = my_filter | Q( Q(note_name__icontains=keyword) | Q(content__icontains=keyword)) note_obj = Note.objects.filter( Q(my_filter & ~Q(note_premission=0)) | my_filter & Q(user_id=myuser.id)) if myuser.user_permission == 1: list_data, total_page = handle_note_search_info( note_obj, myuser, keyword, max_count, page) else: list_data, total_page = handle_note_search_info( note_obj, myuser, keyword, max_count, page) elif search_flag == 'file': file_obj = File.objects.filter(file_name__icontains=keyword) list_data, total_page = handle_file_search_info( file_obj, myuser, max_count, page) elif search_flag == 'host': host_obj = Host.objects.filter( Q(name__icontains=keyword) | Q(ip__icontains=keyword)) list_data, total_page = handle_host_search_info( host_obj, myuser, max_count, page) elif search_flag == 'knowledge': note_obj = Note.objects.filter( Q(note_premission=2) & Q(note_name__icontains=keyword)) list_data, total_page = handle_knowledge_search_info( note_obj, max_count, page, keyword) elif search_flag == 'mind': mind_obj = MindNode.objects.filter( Q(name__icontains=keyword) | Q(note__icontains=keyword)) page_info_list = get_page_info_list(mind_obj, max_count, page) total_page = get_total_page(mind_obj, max_count) list_data = handle_mind_search_info(page_info_list) elif search_flag == 'loop': loop_obj = TaskVulnerability.objects.filter( name__icontains=keyword) page_info_list = get_page_info_list(loop_obj, max_count, page) total_page = get_total_page(loop_obj, max_count) list_data = handle_loop_search_info(page_info_list) else: return JsonResponse(code[60002]) res_data = code[200] res_data['data'] = list_data res_data['total'] = total_page return JsonResponse(res_data) except Exception as e: print(e)
def note_search(cls, keyword, page, max_count, flag): flag_res = False try: if flag == 'content': note = Note.objects.filter(content__icontains=keyword) else: flag_res = True note = Note.objects.filter(note_name__icontains=keyword) total_page = get_total_page(note, max_count) current_page_info_list = get_page_info_list(note, max_count, page) note_list = [] for info in current_page_info_list: if not flag_res: content = handle_search_content(keyword, html2text.html2text(info.content)) else: content = html2text.html2text(info.content)[:50] note_dic = { 'note_name': info.note_name, 'note_id': info.id, 'content': content, 'note_premission': info.note_premission, 'classify': info.classify, 'label': info.label.label_name, 'file_dir': Tool().find_pid(info.file_dir_id, info.note_name, 'note') } note_list.append(note_dic) return note_list, total_page except Exception as e: print(e) return [], None
def task_dir_get_all_file(cls, task_id, max_count, page): try: file_info = File.objects.filter(task_id=task_id) total = get_total_page(file_info, max_count) page_info_list = get_page_info_list(file_info, max_count, page) info_lists = File().handle_queryset_info(page_info_list) return info_lists, total except Exception as e: return [], None
def dir_id_query_note(cls, dir_id, max_count, page): """目录id 查询目录下所有笔记 """ try: note = Note.objects.filter(file_dir=dir_id).order_by('-update_time') total_page = get_total_page(note, max_count) page_info_list = get_page_info_list(note, max_count, page) info_list = Note().handle_queryset_info(page_info_list) return info_list, total_page except Exception: return [], None
def query_engin_info(cls, page, max_count, search_word): """查询 搜索engine""" try: if search_word: key_info = SearchEngine.objects.filter( account__icontains=search_word) total_page = get_total_page(key_info, max_page=max_count) page_info_list = get_page_info_list(key_info, max_count, page) data = SearchEngine().user_obj_return_key_info(page_info_list) return data, total_page else: key_info = SearchEngine.objects.all() total_page = get_total_page(key_info, max_page=max_count) page_info_list = get_page_info_list(key_info, max_count, page) data = SearchEngine().user_obj_return_key_info(page_info_list) return data, total_page except Exception as e: print(e) raise e
def task_dir_get_all_note(cls, task_id, max_count, page): """根据 任务id获取任务下所有笔记""" try: note_info = Note.objects.filter(task_id=task_id).order_by('-update_time') total_page = get_total_page(note_info, max_count) page_info_list = get_page_info_list(note_info, max_count, page) info_list = Note().handle_queryset_info(page_info_list) return info_list, total_page except Exception as e: print(e) return [], None
def query_user_info(cls, page, max_count, search_word): """ 查询用户基本信息 """ data_dic = {} redis_obj = Redis('user') redis_key = 'user_info' try: if search_word: redis_filed = 'user_dict_' + page + '_' + search_word + '_' + max_count print(redis_filed) data, flag = redis_obj.is_not_hit_hget_cache( redis_key, redis_filed) if flag: print('用户搜索命中缓存') return data user_info = UserInfo.objects.filter( name__icontains=search_word) total_page = get_total_page(user_info, max_page=max_count) page_info_list = get_page_info_list(user_info, max_count, page) data = UserInfo().user_obj_return_info(page_info_list) else: redis_filed = 'user_dict_' + page + '_' + max_count print(redis_filed) data, flag = redis_obj.is_not_hit_hget_cache( redis_key, redis_filed) if flag: print('用户信息命中缓存') return data user_info = UserInfo.objects.all() total_page = get_total_page(user_info, max_page=max_count) page_info_list = get_page_info_list(user_info, max_count, page) data = UserInfo().user_obj_return_info(page_info_list) data_dic['data'] = data data_dic['total_page'] = total_page print(redis_key, redis_filed) redis_obj.dic_type_write_cache(redis_key, redis_filed, data_dic) return data_dic except Exception as e: raise e
def dir_id_query_file(cls, dir_id, max_count, page): """ 查询文件 :param dir_id: :return: """ try: file_info = File.objects.filter(file_dir=dir_id) total = get_total_page(file_info, max_count) page_info_list = get_page_info_list(file_info, max_count, page) info_lists = File().handle_queryset_info(page_info_list) return info_lists, total except Exception: return [], None
def file_search(cls, search, page, max_count): file = File.objects.filter(file_name__icontains=search) total = get_total_page(file, max_count) page_info_list = get_page_info_list(file, max_count, page) info_list = [] for info in page_info_list: file_path = Tool().find_pid(info.file_dir_id, info.file_name, 'file') info_dic = { 'file_name': info.file_name, 'file_id': info.id, 'create_time': info.create_time.strftime('%Y-%m-%d %H:%M:%S'), 'create_user': info.user.name, 'box_check': info.box_check, 'file_dir': file_path } info_list.append(info_dic) return info_list, total
def know_note_info(cls, task_id, page, max_count): """知识库中 对应任务中所有笔记信息""" data_list = [] note = Note.objects.filter(task_id=task_id, note_premission=2).order_by('-update_time') total_count = get_total_page(note, max_count) page_info_list = get_page_info_list(note, max_count, page) for info in page_info_list: data_dic = { 'id': info.id, 'classify': info.classify, 'note_name': info.note_name, 'create_user': info.user.name, 'label': info.label.label_name, 'create_time': info.create_time.strftime('%Y-%m-%d %H:%M:%S') } data_list.append(data_dic) return data_list, total_count