Ejemplo n.º 1
0
def doeditsimfile(request, simfile_id):

    #Open up the file in an editor:
    sim_file = SimFile.get_tracked_sims(id = simfile_id)

    cwd = os.getcwd()
    os.chdir( os.path.split(sim_file.full_filename)[0])
    data_dict = {'full_filename':sim_file.full_filename}
    cmds = MReOrgConfig.get_ns().get('drop_into_editor_cmds',['xterm &'])
    for cxt_data in cmds:
        t = string.Template(cxt_data).substitute(**data_dict)
        os.system(t)
    os.chdir(cwd)


    # Return to the previous page:
    referer = request.META.get('HTTP_REFERER', None)
    if referer is None:
        return HttpResponseRedirect('/')

    try:
        redirect_to = urlsplit(referer, 'http', False)[2]
        return HttpResponseRedirect(redirect_to)
    except IndexError:
        return HttpResponseRedirect('/')
Ejemplo n.º 2
0
def get_image_file(request, filename):

    im_dir = MReOrgConfig.get_image_store_dir()

    expected_filename = os.path.join(im_dir, filename)

    if os.path.exists(expected_filename):

        fsock = open(expected_filename, 'r')
        file_path = expected_filename
        file_name = os.path.basename(file_path)
        mime_type_guess = mimetypes.guess_type(file_name)
        if mime_type_guess is not None:
            response = HttpResponse(fsock, mimetype=mime_type_guess[0])
        response['Content-Disposition'] = 'attachment; filename=' \
            + file_name
        return response
    else:
        return HttpResponseNotFound('<h1>Image not found</h1>')
    assert False