Exemplo n.º 1
0
def upload_document(request, wiki):
    w = get_object_or_404(Wiki, slug=wiki)

    if request.method != 'POST':
        raise Http404

    format = request.POST.pop('format', [None])[0]

    form = UploadDocumentForm(request.POST, request.FILES)

    if form.is_valid():
        path = form.cleaned_data['path'].replace('\\', '/')
        path = os.path.join(*path.split('/'))

        doc = request.FILES['doc']

        # Add the file to the repository, save() returns the new file path.
        git_path = os.path.join('__media__', path, doc.name)
        doc_path = w.repo.save(git_path, doc)

        w.repo.commit(request.user, ugettext(u'Upload document: {0}').format(path))

        if format == "json":
            data = {
                'url': doc_path,
            }

            return HttpResponse(json.dumps(data))

    return redirect(reverse('filemanager-index', args=[wiki, '']))
Exemplo n.º 2
0
def upload_document(request, wiki):
    w = get_object_or_404(Wiki, slug=wiki)

    if request.method != 'POST':
        raise Http404

    form = UploadDocumentForm(request.POST, request.FILES)

    if form.is_valid():
        path = form.cleaned_data['path'].replace('\\', '/')
        path = os.path.join(*path.split('/'))

        doc = request.FILES['doc']

        os.environ['GIT_AUTHOR_NAME'] = u'{0} {1}'.format(request.user.first_name, request.user.last_name).encode('utf-8')
        os.environ['GIT_AUTHOR_EMAIL'] = request.user.email
        os.environ['USERNAME'] = str(request.user.username)

        w.repo.put_uploaded_file(os.path.join('__media__', path, doc.name), doc)

        del(os.environ['GIT_AUTHOR_NAME'])
        del(os.environ['GIT_AUTHOR_EMAIL'])
        del(os.environ['USERNAME'])

    return wiki, ''
Exemplo n.º 3
0
def index(request, wiki, path):
    w = get_object_or_404(Wiki, slug=wiki)

    filelist = []

    # Get the folder path inside git repository
    if path:
        gitfolder = os.path.join('__media__', path)
    else:
        gitfolder = '__media__'

    # Check if the directory exists
    if w.repo.exists(gitfolder):
        # Get file list
        files = w.repo.get_folder_tree(gitfolder)

        # Append files to the list for the view
        for f in files:
            filelist.append({
                'url': urljoin(path, f['name']),
                'name': f['name'],
                'mimetype': f['type']
            })

    return {'wiki': {
        'files': filelist,
        'obj': w,
        'breadcrumbs': breadcrumbify(path),
        'forms': {
            'upload': UploadDocumentForm({})
        }
    }}