Ejemplo n.º 1
0
def know_note_details(request):
    if request.method == "GET":
        note_id = request.GET.get('note_id')
        data_dic = Note().query_note_info(note_id)
        res_data = code[200]
        res_data['data'] = data_dic.get('data', '')
        return JsonResponse(res_data)
    else:
        return JsonResponse(code[60001])
Ejemplo n.º 2
0
 def get(self, request):
     note_id = request.GET.get('note_id')
     try:
         data_dic = Note().query_note_info(note_id)
         res_data = code[200]
         res_data['data'] = data_dic.get('data', '')
     except Exception:
         return JsonResponse(code[40005])
     return JsonResponse(res_data)
Ejemplo n.º 3
0
def note_file_search(request):
    """ 笔记 文件搜索 """
    if request.method == 'GET':
        try:
            search = request.GET.get('search')
            keyword = request.GET.get('keyword')
            if not search:
                return JsonResponse(code[40013])
            page = request.GET.get('page')
            max_count = request.GET.get('max_count')
            if keyword == 'note':
                flag = request.GET.get('flag')
                data, total_page = Note().note_search(search, page, max_count,
                                                      flag)
            elif keyword == 'file':
                data, total_page = File().file_search(search, page, max_count)
            else:
                return JsonResponse(code[60002])
            res_data = code[200]
            res_data['data'] = data
            res_data['total'] = total_page
            return JsonResponse(res_data)
        except Exception as e:
            err_info = code[60003]
            err_info['info'] = str(e)
            return JsonResponse(err_info)
    else:
        return JsonResponse(code[60001])
Ejemplo n.º 4
0
def uploade_notes(request):
    """批量文件上传"""
    if request.method == 'POST':
        try:
            task_id = None
            user = request.myuser
            data = {
                'p_dir_id': request.POST.get('p_dir_id'),
                'label': request.POST.get('label'),
                'classify': request.POST.get('classify'),
                'note_premission': request.POST.get('note_premission')
            }
            files = request.FILES.getlist('myfiles')
            for f in files:
                data['content'] = f.read().decode('utf-8')
                data['note_name'] = f.name
                flag, task_id = Note().add_note(data, user)
                if not flag:
                    return JsonResponse(code[30003])
            task_progress(6, task_id)
            print('导入笔记进度完成')
            return JsonResponse(code[200])
        except Exception as e:
            print(e)
            return JsonResponse(code[30005])
    else:
        return JsonResponse(code[60001])
Ejemplo n.º 5
0
 def post(self, request):
     user = request.myuser
     data = judge_data_complate(request.body)
     if not data:
         return JsonResponse(code[60004])
     try:
         result = Note().modify_note(data, user)
         if not result:
             return JsonResponse(code[40004])
     except Exception as e:
         print(e)
         return JsonResponse(code[40005])
     return JsonResponse(code[200])
Ejemplo n.º 6
0
 def post(self, request):
     data = judge_data_complate(request.body)
     user = request.myuser
     if not data:
         return JsonResponse(code[60004])
     try:
         flag, task_id = Note().add_note(data, user)
         if not flag:
             return JsonResponse(code[40002])
         task_progress(6, task_id)
     except Exception:
         return JsonResponse(code[40001])
     return JsonResponse(code[200])
Ejemplo n.º 7
0
 def get(self, request):
     task_id = request.GET.get('task_id')
     is_primary = int(request.GET.get('is_primary'))
     dir_id = request.GET.get('dir_id')
     page = request.GET.get('page')
     max_count = request.GET.get('max_count')
     print(f'目录, is_primary, 任务id{dir_id, is_primary, task_id}')
     try:
         result = Note().query_file_dir(task_id, page, max_count,
                                        is_primary, dir_id)
         res_data = code[200]
         res_data['data'] = result
         return JsonResponse(res_data)
     except Exception:
         return JsonResponse(code[20008])
Ejemplo n.º 8
0
def knowledge_primary_page(request):
    get_task = int(request.GET.get('get_task'))
    search_word = request.GET.get('search_word')
    if get_task:
        result = Task().get_all_task()
        res_data = code[200]
        res_data['data'] = result
        return JsonResponse(res_data)

    elif not get_task and not search_word:
        task_id = request.GET.get('task_id')
        page = request.GET.get('page')
        max_count = request.GET.get('max_count')
        # 获取当前任务下笔记
        result, total = Note().know_note_info(task_id, page, max_count)
        res_data = code[200]
        res_data['data'] = result
        res_data['total'] = total
        return JsonResponse(res_data)

    elif search_word:
        # 搜索
        page = request.GET.get('page')
        max_count = request.GET.get('max_count')
        try:
            data_list, total_count = Task().search_task_all_note(
                page, max_count, search_word)
            res_data = code[200]
            res_data['data'] = data_list
            res_data['total'] = total_count
        except Exception as e:
            err_info = code[60003]
            err_info['info'] = str(e)
            return JsonResponse(err_info)
        return JsonResponse(res_data)
    else:
        return JsonResponse(code[60001])