コード例 #1
0
ファイル: views.py プロジェクト: ixiaoshayu/hue
def save_file(request):
    """
    The POST endpoint to save a file in the file editor.

    Does the save and then redirects back to the edit page.
    """
    form = EditorForm(request.POST)
    is_valid = form.is_valid()
    path = form.cleaned_data.get('path')

    if request.POST.get('save') == "Save As":
        if not is_valid:
            return edit(request, path, form=form)
        else:
            return render("saveas.mako", request, {'form': form})

    if not path:
        raise PopupException(_("No path specified"))
    if not is_valid:
        return edit(request, path, form=form)

    if request.fs.exists(path):
        do_overwrite_save(request.fs, path,
                           form.cleaned_data['contents'],
                           form.cleaned_data['encoding'])
    else:
        do_newfile_save(request.fs, path,
                         form.cleaned_data['contents'],
                         form.cleaned_data['encoding'])

    messages.info(request, _('Saved %(path)s.') % {'path': os.path.basename(path)})
    request.path = reverse("filebrowser.views.edit", kwargs=dict(path=path))
    return edit(request, path, form)
コード例 #2
0
ファイル: views.py プロジェクト: perestu/hue
def save_file(request):
    """
    The POST endpoint to save a file in the file editor.

    Does the save and then redirects back to the edit page.
    """
    form = EditorForm(request.POST)
    is_valid = form.is_valid()
    path = form.cleaned_data.get('path')

    if request.POST.get('save') == "Save As":
        if not is_valid:
            return edit(request, path, form=form)
        else:
            return render("saveas.mako", request, {'form': form})

    if not path:
        raise PopupException(_("No path specified"))
    if not is_valid:
        return edit(request, path, form=form)

    encoding = form.cleaned_data['encoding']
    data = form.cleaned_data['contents'].encode(encoding)

    try:
        if request.fs.exists(path):
            do_overwrite_save(request.fs, path, data)
        else:
            request.fs.create(path, overwrite=False, data=data)
    except WebHdfsException, e:
        raise PopupException(_("The file could not be saved"), detail=e.message.splitlines()[0])
コード例 #3
0
ファイル: views.py プロジェクト: mobilipia/hue
def save_file(request):
    """
    The POST endpoint to save a file in the file editor.

    Does the save and then redirects back to the edit page.
    """
    form = EditorForm(request.POST)
    is_valid = form.is_valid()
    path = form.cleaned_data.get('path')

    if request.POST.get('save') == "Save As":
        if not is_valid:
            return edit(request, path, form=form)
        else:
            data = dict(form=form)
            return render("saveas.mako", request, data)

    if not path:
        raise PopupException("No path specified")
    if not is_valid:
        return edit(request, path, form=form)

    if request.fs.exists(path):
        _do_overwrite_save(request.fs, path,
                           form.cleaned_data['contents'],
                           form.cleaned_data['encoding'])
    else:
        _do_newfile_save(request.fs, path,
                         form.cleaned_data['contents'],
                         form.cleaned_data['encoding'])

    messages.info(request, _('Saved %(path)s.') % {'path': os.path.basename(path)})
    """ Changing path to reflect the request path of the JFrame that will actually be returned."""
    request.path = urlresolvers.reverse("filebrowser.views.edit", kwargs=dict(path=path))
    return edit(request, path, form)
コード例 #4
0
def save_file(request):
    """
    The POST endpoint to save a file in the file editor.

    Does the save and then redirects back to the edit page.
    """
    form = EditorForm(request.POST)
    is_valid = form.is_valid()
    path = form.cleaned_data.get('path')

    if request.POST.get('save') == "Save As":
        if not is_valid:
            return edit(request, path, form=form)
        else:
            data = dict(form=form)
            return render("saveas.mako", request, data)

    if not path:
        raise PopupException("No path specified")
    if not is_valid:
        return edit(request, path, form=form)

    if request.fs.exists(path):
        _do_overwrite_save(request.fs, path, form.cleaned_data['contents'],
                           form.cleaned_data['encoding'])
    else:
        _do_newfile_save(request.fs, path, form.cleaned_data['contents'],
                         form.cleaned_data['encoding'])

    messages.info(request,
                  _('Saved %(path)s.') % {'path': os.path.basename(path)})
    """ Changing path to reflect the request path of the JFrame that will actually be returned."""
    request.path = urlresolvers.reverse("filebrowser.views.edit",
                                        kwargs=dict(path=path))
    return edit(request, path, form)
コード例 #5
0
ファイル: views.py プロジェクト: ixiaoshayu/hue
    if not form:
        encoding = request.REQUEST.get('encoding') or i18n.get_site_encoding()
        if stats:
            f = request.fs.open(path)
            try:
                try:
                    current_contents = unicode(f.read(), encoding)
                except UnicodeDecodeError:
                    raise PopupException(_("File is not encoded in %(encoding)s; cannot be edited: %(path)s.") % {'encoding': encoding, 'path': path})
            finally:
                f.close()
        else:
            current_contents = u""

        form = EditorForm(dict(path=path, contents=current_contents, encoding=encoding))

    data = dict(
        exists=(stats is not None),
        stats=stats,
        form=form,
        path=path,
        filename=os.path.basename(path),
        dirname=os.path.dirname(path),
        breadcrumbs = parse_breadcrumbs(path))
    return render("edit.mako", request, data)


def save_file(request):
    """
    The POST endpoint to save a file in the file editor.