def creat_project(request): cur_dir = Directory("./Projects/") creator_id = request.session['user_id'] project_name = request.POST['name'] if (project_name == ''): return render(request, 'login/initial.html', locals()) type = request.POST['type'] new_pro = models.Project.objects.create(project_name=project_name, creator_id=creator_id, type=type) proname = str(creator_id) + '_' + project_name cur_dir.create_folder(proname) return render(request, 'login/initial.html', locals())
def index(request, project_id): # print("come index") user_pro = models.Project.objects.get(project_id=project_id) request.session["cur_type"] = user_pro.type cur_pro_name = user_pro.project_name real_pro_name = str(user_pro.creator_id) + '_' + cur_pro_name request.session['cur_project'] = project_id cur_dir = Directory('./Projects/' + real_pro_name + '/') request.session["cur_base"] = './Projects/' + real_pro_name + '/' # cur_dir.create_folder('test1') all_url = [(0, "root")] files_list = cur_dir.get_files_and_folders() return render(request, 'login/index.html', {'file_names': files_list, "url": all_url})
def __init__(self, compiler, project_name, main_document): try: assert compiler in self.__compiler_list except AssertionError: print('Compiler is not support!') self.compiler = compiler self.project_name = project_name self.main_document = main_document self.__project_path = self.project_name self.__latex_path = self.__project_path + '/' self.__output_path = self.__project_path + '{}.pdf'.format( main_document) self.__directory = Directory(self.__project_path)
def creat_fold(request): try: if_exist = models.Project.objects.get(creator_id= request.session["user_id"] , project_id= request.session["cur_project"]) cur_url = request.POST["position"] print(cur_url) cur_url = cur_url.strip('root/') file_name = request.POST['name'] if (file_name == ''): return HttpResponse(json.dumps({"is_ok": True})) print(file_name) now_pro = models.Project.objects.get(project_id=request.session["cur_project"]) base_url = request.session['cur_base'] + cur_url + "/" cur_dir = Directory(base_url) print(base_url) cur_dir.create_folder(file_name) print('creat_fold succeed') return HttpResponse(json.dumps({"is_ok": True})) except models.Project.DoesNotExist: if_exist = models.Authorize.objects.get(user_id=request.session["user_id"], project_id=request.session["cur_project"]) if (if_exist.can_write == 0): return HttpResponse(json.dumps({"is_ok": False})) cur_url = request.POST["position"] print(cur_url) cur_url = cur_url.strip('root/') file_name = request.POST['name'] if (file_name == ''): return HttpResponse(json.dumps({"is_ok": True})) print(file_name) now_pro = models.Project.objects.get(project_id=request.session["cur_project"]) base_url = request.session['cur_base'] + cur_url + "/" cur_dir = Directory(base_url) print(base_url) cur_dir.create_folder(file_name) print('creat_fold succeed') return HttpResponse(json.dumps({"is_ok": True}))
def delete(request): # ./Project/11713021_test/ cur_base = request.session['cur_base'] # root/test1/test2/ dir_path = request.POST.get("position") dir_path = dir_path.replace('root/', '') print(dir_path) ff_name = dir_path + request.POST.get("ff_name") post_fix = splitext(ff_name)[-1] no_file_dir = cur_base + dir_path.strip(ff_name) print(no_file_dir) diro = Directory(no_file_dir) if isfile(no_file_dir + ff_name): diro.delete_file(ff_name) else: diro.delete_folder(ff_name) return HttpResponse("sfsdf")
def open_cur_pro_fold(request): dir_path = request.POST['url_list'] dir_list = dir_path.split('/') print(dir_list) dir_list.pop(0) dir_list.pop(0) if len(dir_list) != 0: dir_list[-1] = dir_list[-1].split(' ')[-1] print(dir_list) # dir_path = dir_path[7:] cur_base = request.session['cur_base'] list2path = cur_base for i in dir_list: list2path += i + '/' list2path = list2path[:-1] print(list2path) if not isfile(list2path): return_url_list = [(0, 'root')] i = 1 for dl in dir_list: return_url_list.append((i, dl)) i += 1 diro = Directory(list2path + "/") return_ff_list = diro.get_files_and_folders() # return render(request, 'login/index.html', {'is_file': False, 'url': return_url_list, 'file_names': return_ff_list, 'content': None}) # return render(request, 'login/index.html', {'file_names': files_list, "url": all_url}) return HttpResponse( json.dumps({'is_file': False, 'url': return_url_list, 'file_names': return_ff_list, 'content': None})) else: request.session["cur_file"] = list2path with codecs.open(list2path, "r", encoding='utf-8') as f: file = f.read() print(file) request.session["cur_edit_file"] = list2path return HttpResponse(json.dumps({"is_file": True, 'content': file}))
def upload(request): ''' :param request: dir_path example: test/file.zip or test1/test2/file.tex; bit_stream; :return: nothing ''' try: if_exist = models.Project.objects.get(creator_id= request.session["user_id"] , project_id= request.session["cur_project"]) cur_base = request.session['cur_base'] dir_path = request.POST.get("position") dir_path = dir_path.replace('root/', '') print(dir_path) bit_stream = request.FILES.get('upload_file') file_name = dir_path + request.POST.get("file_name") print("upload file name:" + file_name) # file_name = dir_path.split('/')[-1] post_fix = splitext(file_name)[-1] no_file_dir = cur_base + dir_path.strip(file_name) print(no_file_dir) diro = Directory(no_file_dir) # print(post_fix) if post_fix == '.zip': zip_path = './Temp/zips/' with open(zip_path + file_name, 'wb') as zip_file: for chunk in bit_stream.chunks(): zip_file.write(chunk) diro.unzip(file_name, no_file_dir) else: print((no_file_dir + file_name)) with open((no_file_dir + file_name), 'wb') as common_file: for chunk in bit_stream.chunks(): common_file.write(chunk) print('success') return HttpResponse(json.dumps({"is_ok":True})) except: if_exist = models.Authorize.objects.get(user_id= request.session["user_id"] , project_id=request.session["cur_project"]) if(if_exist.can_write == 0): return HttpResponse(json.dumps({"is_ok": False})) cur_base = request.session['cur_base'] dir_path = request.POST.get("position") dir_path = dir_path.replace('root/', '') print(dir_path) bit_stream = request.FILES.get('upload_file') file_name = dir_path + request.POST.get("file_name") print("upload file name:" + file_name) # file_name = dir_path.split('/')[-1] post_fix = splitext(file_name)[-1] no_file_dir = cur_base + dir_path.strip(file_name) print(no_file_dir) diro = Directory(no_file_dir) # print(post_fix) if post_fix == '.zip': zip_path = './Temp/zips/' with open(zip_path + file_name, 'wb') as zip_file: for chunk in bit_stream.chunks(): zip_file.write(chunk) diro.unzip(file_name, no_file_dir) else: print((no_file_dir + file_name)) with open((no_file_dir + file_name), 'wb') as common_file: for chunk in bit_stream.chunks(): common_file.write(chunk) print('success') return HttpResponse(json.dumps({"is_ok": True}))
def __init__(self,project_name, main_document): self.project_name= project_name self.main_document= main_document self.__directory = Directory(self.__project_path)