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)
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])
def test_remove_header(self): fs = self.cluster.fs path = "/tmp/test_remove_header.txt" data_header = "destination\trank" data_body = """thailand\t10 costarica\t? curacao\t?""" data = data_header + '\n' + data_body f = fs.open(path, "w") f.write("hello") f.close() encoding = i18n.get_site_encoding() do_overwrite_save(fs, path, data.encode(encoding)) assert_not_equal(data_body, fs.open(path).read()) remove_header(fs, path) assert_equals(data_body, fs.open(path).read())