def tree_view(request, repo_name, branch=REPO_BRANCH, path=None, commit_sha=None): repo = get_repo(repo_name) commit, tree = get_commit_tree(repo, commit_sha) if path: if path[-1:] == "/": path = path[:-1] tree = tree[path] if request.method == "POST": form = FileUploadForm(request.POST, request.FILES) if form.is_valid(): file_path = os.path.join(repo.working_dir, path, request.FILES["file_source"].name) handle_uploaded_file(file_path, request.FILES["file_source"]) msg = "file %s uploaded" % file_path result_msg = mk_commit(repo, msg, file_path) messages.success(request, result_msg) else: form = FileUploadForm() context = dict( GITTER_MEDIA_URL=GITTER_MEDIA_URL, repo_name=repo_name, branch_name=branch, commit=commit, upload_form=form, tree=tree.list_traverse(depth=1), breadcrumbs=None, # make_crumbs(path), dir_path=path.split("/"), ) return TemplateResponse(request, "commitlog/view_tree.html", context)
def view(request, repo_name, branch=REPO_BRANCH, path=None, commit_sha=None ): repo = get_repo( repo_name ) commit, tree = get_commit_tree(repo, commit_sha) dir_path = path.split("/") if commit_sha: template_name = 'commitlog/view_commit_tree.html' else: template_name = 'commitlog/view_tree.html' if path: if path[-1:] == "/": path = path[:-1] try: tree = tree[path] except AttributeError: tree = tree[dir_path[:-1]] if request.method == 'POST': form = FileUploadForm(request.POST, request.FILES) if form.is_valid(): file_path = os.path.join( repo.working_dir, path, request.FILES["file_source"].name) handle_uploaded_file(file_path, request.FILES['file_source']) msg = "file %s uploaded" % file_path result_msg = mk_commit(repo, msg, file_path ) messages.success(request, result_msg ) else: form = FileUploadForm( initial={ "dir_path": path } ) context = dict( GITTER_MEDIA_URL = GITTER_MEDIA_URL, repo_name = repo_name, branch_name = branch, commit = commit, upload_form = form, tree = tree.list_traverse(depth = 1), breadcrumbs = make_crumbs(path), dir_path = dir_path, ) return mix_response( request, template_name, context)
def new(request, repo_name, branch=REPO_BRANCH, path=None ): result_msg = file_source = "" form_class = TextFileEditForm file_path = path #!!! FIX security #TODO check if file exist allready file_meta = dict( type = "python", ) if request.method == 'POST': form = FileUploadForm( request.POST, request.FILES ) if form.is_valid(): repo = Repo(REPOS[repo_name]) file_source = form.cleaned_data["file_source"] write_file(file_path, file_source ) msg = form.cleaned_data["message"] result_msg = mk_commit(repo, msg, file_path ) messages.success(request, result_msg ) dir_path = "/".join( path.split("/")[:-1] ) return redirect('commitlog-tree-view', repo_name, branch, dir_path ) else: result_msg = MSG_COMMIT_ERROR else: form = form_class( initial={"message":"%s added" % path} ) context = dict( GITTER_MEDIA_URL = GITTER_MEDIA_URL, form= form, breadcrumbs = make_crumbs(path), result_msg = result_msg, file_meta = file_meta, repo_name = repo_name, branch_name = branch, path = path, ) return mix_response( request, 'commitlog/new_file.html', context)
def upload(request, repo_name, branch=REPO_BRANCH ): result_msg = file_source = path = "" if request.method == 'POST': form = FileUploadForm( request.POST, request.FILES ) if form.is_valid(): dir_path = form.cleaned_data["dir_path"] #!!! FIX security #TODO check if file exist allready repo = Repo(REPOS[repo_name]) file_source = form.cleaned_data["file_source"] path = os.path.join( dir_path, file_source["name"] ) write_file(file_path, file_source ) msg = form.cleaned_data["message"] result_msg = mk_commit(repo, msg, path ) messages.success(request, result_msg ) return redirect('commitlog-tree-view', repo_name, branch, dir_path ) else: result_msg = MSG_COMMIT_ERROR else: form = FileUploadForm( initial={"message":"%s added" % path} ) context = dict( GITTER_MEDIA_URL = GITTER_MEDIA_URL, form= form, breadcrumbs = make_crumbs(path), result_msg = result_msg, repo_name = repo_name, branch_name = branch, path = path, ) return mix_response( request, 'commitlog/new_file.html', context)